Skip to content
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

[MM-49410] Added golangci-lint support #820

Merged
merged 18 commits into from
Jan 19, 2023
Merged

[MM-49410] Added golangci-lint support #820

merged 18 commits into from
Jan 19, 2023

Conversation

fmartingr
Copy link
Contributor

Summary

Added golangci-lint support

Ticket Link

https://mattermost.atlassian.net/browse/MM-49410

Release Note

none

@mm-cloud-bot mm-cloud-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Jan 2, 2023
@fmartingr
Copy link
Contributor Author

PR fixes everything at this point except for shadowing. Enabling shadowing outputs a lot more errors around (most of them err in tests, but there are other outside the test suite). Yesterday I told you that we should discuss if disabling it on tests, but after a bit of thought I'd rather enable or disable it globally to avoid confusion. And I'd say it has more value enabled rather than disabled. What are your thoughts @mirshahriar @gabrieljackson ? Also if we could get @agnivade to chip in as well, since its sample configuration file has shadowing enabled, would love your opinion here.

@mirshahriar
Copy link
Contributor

mirshahriar commented Jan 4, 2023

Do we need to skip internal/mocks in make lint?

@fmartingr
Copy link
Contributor Author

fmartingr commented Jan 4, 2023

Do we need to skip internal/mocks in make lint?

That's why I'd like to discuss. Missread.

yeah, since mocks code is autogenerated, there's no point in linting it, since we're not going to fix the lint errors each time we run make mocks.

@agnivade
Copy link
Member

agnivade commented Jan 4, 2023

From my experience, shadowing is one of those issues which are a pain to fix, but sometimes a bug eventually falls through. So it's not very urgent, but I'd suggest to fix them. What we usually do in server is to rename err to err2 .

This was a real bug that we fixed caused due to shadowing: https://github.com/mattermost/enterprise/pull/594/files. It might look simple now but sometimes it's easy to miss.

@fmartingr
Copy link
Contributor Author

Screenshot 2023-01-05 at 12 16 15

Screenshot 2023-01-05 at 12 25 47

@gabrieljackson
Copy link
Contributor

I am okay with us setting the shadow check to disabled initially so we can get this running in CI/CD. We can then do some follow-up changes to correct shadowing issues and enable enforcement with shadow-checking.

@fmartingr
Copy link
Contributor Author

I am okay with us setting the shadow check to disabled initially so we can get this running in CI/CD. We can then do some follow-up changes to correct shadowing issues and enable enforcement with shadow-checking.

I'm already taking care of all the shadowing issues, I wanted to have it done by today but other things came up. I will have it ready by monday.

@fmartingr fmartingr marked this pull request as ready for review January 9, 2023 12:28
@fmartingr
Copy link
Contributor Author

Screenshot 2023-01-09 at 13 27 06

@fmartingr fmartingr requested review from mirshahriar and gabrieljackson and removed request for gabrieljackson January 9, 2023 12:46
@fmartingr fmartingr self-assigned this Jan 9, 2023
@fmartingr fmartingr added the 2: Dev Review Requires review by a developer label Jan 9, 2023
# Conflicts:
#	internal/tools/terraform/plan.go
@mirshahriar
Copy link
Contributor

I agree with turning on the shadow check. But I'm not a fan of using err2, err3 when err would suffice. If we need to introduce a new error variable to remove shadowing, I am in favour of naming it after the relevant error.

Like

  _, err2 := exec.LookPath(extraTool)
  if err2 != nil {
	  return errors.Errorf("failed to find %s on the PATH", extraTool)
  }

Instead of using err2, we can use execErr

_, execErr := exec.LookPath(extraTool)
if execErr != nil {
	return errors.Errorf("failed to find %s on the PATH", extraTool)
}

Though both are the same.

@fmartingr
Copy link
Contributor Author

I agree with turning on the shadow check. But I'm not a fan of using err2, err3 when err would suffice. If we need to introduce a new error variable to remove shadowing, I am in favour of naming it after the relevant error.

I agree with that, and I think I tried to use a similar naming outside of tests (so logic makes sense) but I may have missed some since most changes were mechanical after the first dozen or so. If you have spotted some tell me and I'll change it.

Copy link
Contributor

@gabrieljackson gabrieljackson left a comment

Choose a reason for hiding this comment

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

LGTM! There are a few err2 type names outside of tests that I don't love, but this is totally fine. We can just change them later if they bug us.

@@ -953,44 +953,6 @@ func (s *InstallationSupervisor) waitForUpdateStable(installation *model.Install
return model.InstallationStateStable
}

// Unused stub function
Copy link
Contributor

Choose a reason for hiding this comment

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

C'mon linter! It says right there it's unused. Why do you just leave it alone!? 😂

@fmartingr fmartingr requested review from Mshahidtaj and mirshahriar and removed request for mirshahriar and Mshahidtaj January 19, 2023 14:12
Copy link
Contributor

@mirshahriar mirshahriar left a comment

Choose a reason for hiding this comment

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

LGTM. But I would love to see the changes in err2, err3 naming in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a developer release-note-none Denotes a PR that doesn't merit a release note.
Projects
None yet
5 participants