-
Notifications
You must be signed in to change notification settings - Fork 13
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
Fix linting errors #3189
Conversation
MDrakos
commented
Mar 21, 2024
•
edited by github-actions
bot
Loading
edited by github-actions
bot
DX-2358 Fix the hundreds of linter warnings/errors in the repo. |
There was a problem hiding this 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).
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this 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.
@@ -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) |
There was a problem hiding this comment.
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/uniqid/uniqid.go
Outdated
@@ -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()) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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"), |
There was a problem hiding this comment.
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.
We overlooked two lint errors: https://github.com/ActiveState/cli/blob/DX-2358/internal/subshell/subshell_win_test.go#L59 Error return value of https://github.com/ActiveState/cli/blob/DX-2358/internal/subshell/subshell_win_test.go#L89 Error return value of |
Thank you for catching this. Meant to run the linter again on Windows myself but I'm glad you did. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!