Skip to content

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

Merged
merged 31 commits into from
May 4, 2025
Merged

Upgrade golangci-lint to v2 #8986

merged 31 commits into from
May 4, 2025

Conversation

nopcoder
Copy link
Contributor

@nopcoder nopcoder commented Apr 27, 2025

  • 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
@nopcoder nopcoder added area/testing Improvements or additions to tests infrastructure build, deploy and release processes labels Apr 27, 2025
@nopcoder nopcoder self-assigned this Apr 27, 2025
Copy link

E2E Test Results - DynamoDB Local - Local Block Adapter

13 passed, 1 skipped

Copy link

E2E Test Results - Quickstart

12 passed

@nopcoder nopcoder added the exclude-changelog PR description should not be included in next release changelog label Apr 27, 2025
@nopcoder nopcoder requested a review from a team April 27, 2025 08:49
@nopcoder nopcoder added the minor-change Used for PRs that don't require issue attached label Apr 27, 2025
Copy link
Contributor

@arielshaqed arielshaqed left a 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.

@@ -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 {
Copy link
Contributor

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...)

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@@ -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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@@ -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
Copy link
Contributor

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

@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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!

Copy link
Contributor Author

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

Copy link
Contributor

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
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor

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.
}

Copy link
Contributor Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

nopcoder and others added 18 commits May 3, 2025 19:54
* 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
N-o-Z and others added 2 commits May 3, 2025 19:54
- applyed the same linter configuration
- revert all `if` invert
- revert some of the defer anonymous func
Copy link

github-actions bot commented May 3, 2025

🎊 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

@nopcoder
Copy link
Contributor Author

nopcoder commented May 3, 2025

@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

@nopcoder nopcoder requested a review from arielshaqed May 4, 2025 07:39
Copy link
Contributor

@arielshaqed arielshaqed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THANKS!

@@ -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 {
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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 😢

@nopcoder nopcoder enabled auto-merge (squash) May 4, 2025 08:01
@nopcoder nopcoder merged commit ed66469 into master May 4, 2025
41 checks passed
@nopcoder nopcoder deleted the chore/golangci-lint branch May 4, 2025 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing Improvements or additions to tests exclude-changelog PR description should not be included in next release changelog infrastructure build, deploy and release processes minor-change Used for PRs that don't require issue attached
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants