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

Fix linting errors #3189

Merged
merged 34 commits into from
Mar 28, 2024
Merged

Fix linting errors #3189

merged 34 commits into from
Mar 28, 2024

Conversation

MDrakos
Copy link
Member

@MDrakos MDrakos commented Mar 21, 2024

TaskDX-2358 Fix the hundreds of linter warnings/errors in the repo.

@MDrakos MDrakos changed the base branch from master to version/0-44-0-RC1 March 21, 2024 17:18
@MDrakos MDrakos marked this pull request as ready for review March 25, 2024 23:04
Copy link
Contributor

@mitchell-as mitchell-as 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 some great work! Don't be discouraged with the number of change requests because there are bound to be some in 266 changed files :)

There are a handful of minor things to address, but I think the main thing I'd like to bring up is that I would personally prefer avoiding //nolint: at all costs. Writing code to pander to a linter is not ideal unless we absolutely cannot avoid it. For example instead of tagging a function as //nolint:unused because it's only used on Linux, create a _linux.go file and move that tagged function into it (and then untag it).

cmd/state-svc/autostart/autostart.go Outdated Show resolved Hide resolved
cmd/state-svc/autostart/autostart.go Outdated Show resolved Hide resolved
@@ -76,7 +76,8 @@ func (m *Messages) Check(command string, flags []string) ([]*graph.MessageInfo,
}
allMessages := cacheValue.([]*graph.MessageInfo)

conditionParams := &(*m.baseParams) // copy
// copy the base params
conditionParams := &(*m.baseParams) //nolint:staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better solution would be to use conditionParams := m.baseParams // copy and then change *conditionParams to conditionParams on line 89, and change conditionParams to &conditionParams on line 92.

Copy link
Member Author

@MDrakos MDrakos Mar 27, 2024

Choose a reason for hiding this comment

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

m.baseparams is a pointer to a struct, so conditionParams := m.basParams will just be a copy of the pointer. I believe dereferencing here is what we want so I've updated it to conditionParams := *m.baseParams. Either way, the current code on master is not creating a copy of the struct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you are correct. I made a typo; I missed the '*' dereference. You did what I had in mind.

cmd/state/autoupdate.go Show resolved Hide resolved
internal/analytics/client/sync/client.go Show resolved Hide resolved
test/integration/checkout_int_test.go Outdated Show resolved Hide resolved
test/integration/performance_expansion_int_test.go Outdated Show resolved Hide resolved
test/integration/run_int_test.go Show resolved Hide resolved
excludes.txt Outdated Show resolved Hide resolved
internal/subshell/subshell_test.go Outdated Show resolved Hide resolved
@MDrakos
Copy link
Member Author

MDrakos commented Mar 27, 2024

I've cross-referenced the integration test failures here with our latest nightly failures and it seem to line up, aside from timeouts on Windows.

Thanks for the great review. When dealing with all of these linting errors I started applying quick/lazy fixes as there were just so many of them. A second set of eyes really helped. Hopefully we can be more diligent and stay on top of these in the future.

Copy link
Contributor

@mitchell-as mitchell-as left a comment

Choose a reason for hiding this comment

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

Almost there! Just a few more things to address.

internal/logging/rotate.go Outdated Show resolved Hide resolved
pkg/platform/model/vcs.go Show resolved Hide resolved
internal/fileutils/fileutils_win.go Outdated Show resolved Hide resolved
internal/keypairs/local_load_test.go Outdated Show resolved Hide resolved
@@ -230,7 +227,9 @@ func NewHiddenShimCommand(name string, prime primer, flags []*Flag, args []*Argu
}

cmd.cobra.SetHelpFunc(func(_ *cobra.Command, args []string) {
cmd.execute(cmd, args)
if err := cmd.execute(cmd, args); err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see. GitHub didn't give me that context. Since this is an established pattern, we can keep it. I consider this double-checked!

internal/svcctl/svcctl.go Outdated Show resolved Hide resolved
@@ -190,7 +189,9 @@ func writeFile(filePath string, data []byte) error {
if err := os.Chmod(filePath, 0644); err != nil {
return fmt.Errorf("os.Chmod %s failed: %w", filePath, err)
}
defer os.Chmod(filePath, stat.Mode().Perm())
defer func() {
rerr = os.Chmod(filePath, stat.Mode().Perm())
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, this may end up overwriting an existing error, so perhaps use

if rerr != nil {
  rerr = os.Chmod(...)
}

@@ -76,7 +76,8 @@ func (m *Messages) Check(command string, flags []string) ([]*graph.MessageInfo,
}
allMessages := cacheValue.([]*graph.MessageInfo)

conditionParams := &(*m.baseParams) // copy
// copy the base params
conditionParams := &(*m.baseParams) //nolint:staticcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, you are correct. I made a typo; I missed the '*' dereference. You did what I had in mind.

uintptr(0),
uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)))
if err != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

That works. Our integration tests should probably catch it since they fail if there are any errors in the logs.

@@ -108,6 +107,7 @@ runtime = solve(
],
requirements = [
Req(name = "language/perl"),
Req(name = "language/perl/JSON"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for double-checking. You can leave it as-is.

@mitchell-as
Copy link
Contributor

We overlooked two lint errors:

https://github.com/ActiveState/cli/blob/DX-2358/internal/subshell/subshell_win_test.go#L59

Error return value of pjfile.Persist is not checked (errcheck)

https://github.com/ActiveState/cli/blob/DX-2358/internal/subshell/subshell_win_test.go#L89

Error return value of pjfile.Persist is not checked (errcheck)

@MDrakos
Copy link
Member Author

MDrakos commented Mar 28, 2024

We overlooked two lint errors:

https://github.com/ActiveState/cli/blob/DX-2358/internal/subshell/subshell_win_test.go#L59

Error return value of pjfile.Persist is not checked (errcheck)

https://github.com/ActiveState/cli/blob/DX-2358/internal/subshell/subshell_win_test.go#L89

Error return value of pjfile.Persist is not checked (errcheck)

Thank you for catching this. Meant to run the linter again on Windows myself but I'm glad you did.

Copy link
Contributor

@mitchell-as mitchell-as left a comment

Choose a reason for hiding this comment

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

Yay!

@MDrakos MDrakos merged commit af8a8b9 into version/0-44-0-RC1 Mar 28, 2024
4 of 7 checks passed
@MDrakos MDrakos deleted the DX-2358 branch March 28, 2024 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants