-
Notifications
You must be signed in to change notification settings - Fork 373
Upgrade golangci-lint to v2 #8986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
nopcoder
commented
Apr 27, 2025
•
edited
Loading
edited
- Fixed some of the lint issues - plan to enable lint on tests and more linters after this PR.
- The github-actions output format was removed - will consider to use their action to run the lint
handle some of the lint errors next PR will enable more on test code
no longer supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really neat! But some of the new(?) linter features are not so good. Please see comments inlines. I did not go over the second half, if it's OK with you I would rather finish handling these comments and then have another round.
cmd/lakectl/cmd/import.go
Outdated
@@ -97,15 +97,17 @@ var importCmd = &cobra.Command{ | |||
case <-ticker.C: | |||
statusResp, err = client.ImportStatusWithResponse(ctx, toURI.Repository, toURI.Ref, &apigen.ImportStatusParams{Id: importID}) | |||
DieOnErrorOrUnexpectedStatusCode(statusResp, err, http.StatusOK) | |||
status := statusResp.JSON200 | |||
if status == nil { | |||
if statusResp.JSON200 == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this "fix". It seems longer, more reasonable, and easier to get wrong when code is notified. (TBF, if this flags a "can be nil" warning, any future breakage will flag it again...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix was related to missing nil check with status.IngestedObjects
. The line you marked is related to the change I made where we verify the statusResp.JSON200
nil before assign it to local variable where the old code assigned it first?
Let me know if moving the assignment first will make it clear or I missed anything and the issue with something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd just prefer the assignment first.
cmd/lakectl/cmd/local_init.go
Outdated
@@ -80,7 +80,7 @@ func localInit(ctx context.Context, dir string, remote *uri.URI, force, updateIg | |||
ignoreFile, err := git.Ignore(dir, []string{dir}, []string{filepath.Join(dir, local.IndexFileName)}, local.IgnoreMarker) | |||
if err == nil { | |||
fmt.Println("Location added to", ignoreFile) | |||
} else if !(errors.Is(err, giterror.ErrNotARepository) || errors.Is(err, giterror.ErrNoGit)) { | |||
} else if !errors.Is(err, giterror.ErrNotARepository) && !errors.Is(err, giterror.ErrNoGit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this better? Can we turn this longer off?
I definitely prefer the former (but not enough to require it). For instance, it is easier to refactor into a function isErrNotVersiomed. In general, negatives are confusing, best use as few of them as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the staticchecks linter try to apply de morgan's law on expressions that starts like !(...)
Will disable the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving the status assignment before the check
cmd/lakectl/cmd/root.go
Outdated
@@ -329,7 +329,7 @@ func getSyncArgs(args []string, requireRemote bool, considerGitRoot bool) (remot | |||
gitRoot, err := git.GetRepositoryPath(localPath) | |||
if err == nil { | |||
localPath = gitRoot | |||
} else if !(errors.Is(err, giterror.ErrNotARepository) || errors.Is(err, giterror.ErrNoGit)) { // allow support in environments with no git | |||
} else if !errors.Is(err, giterror.ErrNotARepository) && !errors.Is(err, giterror.ErrNoGit) { // allow support in environments with no git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, don't like this lint
esti/esti_utils.go
Outdated
@@ -668,7 +668,11 @@ func checkFileWasGarbageCollected(t *testing.T, presignedURLs map[string]string, | |||
if err != nil { | |||
t.Fatalf("%s, expected no error, got err=%s", "Http request to presigned url", err) | |||
} | |||
defer r.Body.Close() | |||
defer func() { | |||
if err := r.Body.Close(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is silly for a read, because Close cannot fail. But if it did, I would want to fail the test.
Can we nolint this here, with some content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert and check how we can exclude this one
@@ -1058,13 +1062,8 @@ func TestDeleteObjects(t *testing.T) { | |||
ctx, _, repo := setupTest(t) | |||
defer tearDownTest(repo) | |||
const numOfObjects = 10 | |||
identifiers := make([]types.ObjectIdentifier, 0, numOfObjects) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, actual code analysis for Go. Neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we really need to enable linters on test code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, PLEASE!
@@ -36,7 +36,7 @@ func TestTaskResultsIterator(t *testing.T) { | |||
}, | |||
{ | |||
name: "after out of range", | |||
runID: rand.Intn(100), | |||
runID: rand.Intn(100), //nolint:gosec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we disable gosec in tests? Preferably just the "pseudorandom numbers" thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted. will address it when enable linters on test code.
@@ -34,12 +34,12 @@ const ( | |||
) | |||
|
|||
type ActionStatsMockCollector struct { | |||
Hits map[string]int | |||
Hits map[string]uint64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? No, I thought the whole idea was to avoid unsigned arithmetic wherever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To quote some people who think they know Go:
When you need an integer value you should use int unless you have a specific reason to use a sized or unsigned integer type.
(My emphasis)
For counters and sizes signed integers are almost always better, they avoid making silly errors such as
var (
counter, max uint64
)
max = max.MaxUint64 - 3
// ...
// Check if we have room for 5 more
if counter + 5 < max {
// Gotcha! If counter == max-1 then counter + 5 == 1 and we're in here.
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the mock collector - I've updated the storage data type to match the interface CollectEvents(ev stats.Event, count uint64)
where we collect the counters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, so the interface is also bad. Anyway clearly out of scope for this PR 😢
@@ -317,7 +317,8 @@ func (c *Controller) UploadPart(w http.ResponseWriter, r *http.Request, body api | |||
|
|||
func (c *Controller) UploadPartCopy(w http.ResponseWriter, r *http.Request, | |||
body apigen.UploadPartCopyJSONRequestBody, dstRepository string, branch string, uploadID string, partNumber int, | |||
params apigen.UploadPartCopyParams) { | |||
params apigen.UploadPartCopyParams, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If different formatting is now required then gofmt should enforce it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this formatting is extra done because of my formatter - it is not required.
it is compatible with gofmt.
* initial alter impl * fix sql * execute statement * docs * param order * docs
Add details for new features, bug fixes, and improvements in v1.55.0. Highlights include repository/branch listing by prefix, enhanced pagination, security updates, and UI fixes.
* lakefsfs listStatus - Skip stat object on empty path * Add test for list status on root
* Enhance repository tree layout and link behavior Added inline styles to improve layout responsiveness and prevent overflow issues. Updated link paths to include references in the query parameters for better navigation. Minor adjustments ensure consistent component rendering and functionality. * Refactor repository layout and adjust CSS for flexibility Updated `RepoNav` to include reference handling for breadcrumbs, enabling better navigation with references. Adjusted global CSS and tree component to remove redundant `min-width` specification, ensuring consistent layout behavior.
* Install lakectl and lakefs binary wrappers * include Docker run option * refactor and fix linter * linter * better avoidance of recursive execution * ignore python build artifacts * execute module and explicit download * subcommands for lakefs and lakectl * docs fixes * seperate commands * support venv on windows * fix docs * remove shebangs * simplify quickstart flow
* Re-release the python HL SDK with minor version bump * fix spelling
- applyed the same linter configuration - revert all `if` invert - revert some of the defer anonymous func
🎊 PR Preview 38e77c9 has been successfully built and deployed to https://treeverse-lakeFS-preview-pr-8986.surge.sh 🕐 Build time: 0.01s 🤖 By surge-preview |
handle some of the lint errors next PR will enable more on test code
no longer supported
@arielshaqed thanks - I've revert the relevant changes, kept some comments and rewrote the configuration as yml without adding anything new, just disabled the "Apply De Morgan’s law" one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THANKS!
cmd/lakectl/cmd/import.go
Outdated
@@ -97,15 +97,17 @@ var importCmd = &cobra.Command{ | |||
case <-ticker.C: | |||
statusResp, err = client.ImportStatusWithResponse(ctx, toURI.Repository, toURI.Ref, &apigen.ImportStatusParams{Id: importID}) | |||
DieOnErrorOrUnexpectedStatusCode(statusResp, err, http.StatusOK) | |||
status := statusResp.JSON200 | |||
if status == nil { | |||
if statusResp.JSON200 == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd just prefer the assignment first.
@@ -1058,13 +1062,8 @@ func TestDeleteObjects(t *testing.T) { | |||
ctx, _, repo := setupTest(t) | |||
defer tearDownTest(repo) | |||
const numOfObjects = 10 | |||
identifiers := make([]types.ObjectIdentifier, 0, numOfObjects) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, PLEASE!
@@ -34,12 +34,12 @@ const ( | |||
) | |||
|
|||
type ActionStatsMockCollector struct { | |||
Hits map[string]int | |||
Hits map[string]uint64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch, so the interface is also bad. Anyway clearly out of scope for this PR 😢