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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Upgrade golangci-lint to v2 #8986

wants to merge 3 commits into from

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

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

@@ -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

@@ -87,10 +87,12 @@ var setupCmd = &cobra.Command{
if err != nil {
fmt.Printf("Setup failed: %s\n", err)
os.Exit(1)
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh? Isn't os.Exit a noreturn func, like panic and a very few others?

@@ -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?

@@ -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!

@@ -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?

@@ -99,7 +99,7 @@ func writeFuseSymlink(c *GSClient) lua.Function {
}

w := obj.NewWriter(c.ctx)
w.ObjectAttrs.Metadata = map[string]string{
w.Metadata = map[string]string{
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh???

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

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

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.

2 participants