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

Bump golangci-lint to v2.0.2 #5721

Merged

Conversation

juanluisvaladas
Copy link
Contributor

Description

Bump golangci-lint to v2.0.2 and fix all the new linter errors.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

How Has This Been Tested?

  • Manual test
  • Auto test added

Checklist

  • My code follows the style guidelines of this project
  • My commit messages are signed-off
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@juanluisvaladas juanluisvaladas requested review from a team as code owners April 3, 2025 14:02
@juanluisvaladas juanluisvaladas requested review from kke and makhov April 3, 2025 14:02
@juanluisvaladas juanluisvaladas marked this pull request as draft April 3, 2025 16:55
@juanluisvaladas juanluisvaladas marked this pull request as ready for review April 4, 2025 19:20
@twz123 twz123 disabled auto-merge April 7, 2025 07:12
twz123
twz123 previously approved these changes Apr 7, 2025
Copy link
Member

@twz123 twz123 left a comment

Choose a reason for hiding this comment

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

Would be cool if the comments in the linter config could be preserved, and if the dependency changes could be backed out.

I'm a bit on the fence about the ban on using embedded structs to name fields. I think it can sometimes help when reading code. WDYT?

go.mod Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why we need to change the dependencies here.

@@ -46,13 +46,13 @@ func (s *NetworkSuite) TestAddresses() {
s.Run("DNS_service_cidr_too_narrow", func() {
n := Network{ServiceCIDR: "192.168.178.0/31"}
dns, err := n.DNSAddress()
s.Zero(dns)
s.Empty(dns)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I kinda disagree here. When testing error conditions for functions that return (T, error), I want to assert that the returned T is the zero value of T, even if T happens to be a type that can be "empty". But, well, linters... 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not a big fan of it either to be honest...

@@ -36,7 +36,7 @@ func (s *services) Run() error {
var errs []error

for _, role := range []string{"controller", "worker"} {
if err := install.UninstallService(role); err != nil && !(errors.Is(err, fs.ErrNotExist) || isExitCode(err, 1)) {
if err := install.UninstallService(role); err != nil && (!errors.Is(err, fs.ErrNotExist) && !isExitCode(err, 1)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the parenthesis are no longer required now?

Suggested change
if err := install.UninstallService(role); err != nil && (!errors.Is(err, fs.ErrNotExist) && !isExitCode(err, 1)) {
if err := install.UninstallService(role); err != nil && !errors.Is(err, fs.ErrNotExist) && !isExitCode(err, 1) {

Comment on lines +101 to +104
t.Setenv(key, "")
os.Unsetenv(key)
Copy link
Member

Choose a reason for hiding this comment

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

I see what you did there, but I think it's a bit hard to grasp. Would you mind to add a comment as to why the t.Setenv call is there?

OTOH, I have seen this test pop up in linter runs more than once. It might be worthwhile to nuke the dependency on os.Environ in the function being tested and pass the environment as a string slice argument instead. This would allow the above code to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment, I'm not opposed to the idea of passing a string slice with the environ though.

Bump golangci-lint to v2.0.2 and fix all the new linter errors.

* Some if statements were rewritten according to the De Morgan's law.
* TestGetEnv environment variable cleanup was rewritten to avoid calling
  os.SetEnv
* --out-format=github-actions was deprecated for a while and was
removed in 2.0.0

Co-authored-by: Tom Wieczorek <[email protected]>
Signed-off-by: Juan-Luis de Sousa-Valadas Castaño <[email protected]>
@juanluisvaladas
Copy link
Contributor Author

I added all the suggestions and commented supervisor.TestGetEnv.

Copy link
Member

@twz123 twz123 left a comment

Choose a reason for hiding this comment

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

Can you maybe back out the go.mod/go.sum changes, as they don't seem to be related to the linter bump?

@juanluisvaladas
Copy link
Contributor Author

juanluisvaladas commented Apr 7, 2025

Can you maybe back out the go.mod/go.sum changes, as they don't seem to be related to the linter bump?

Unfortunately I can't, the original PR didn't have it, but for some reason without it the lint workflow fails. Since all the changes look like harmless bumps I didn't look further into it and just bumped them.

@juanluisvaladas juanluisvaladas merged commit 19e5b48 into k0sproject:main Apr 7, 2025
92 checks passed
@twz123
Copy link
Member

twz123 commented Apr 8, 2025

Unfortunately I can't, the original PR didn't have it, but for some reason without it the lint workflow fails. Since all the changes look like harmless bumps I didn't look further into it and just bumped them.

Weird! How would changing the linter affect this? But, then again, linters ... 🤷 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants