-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Cleanup lint codebase #13110
Cleanup lint codebase #13110
Conversation
Test files have some calls that don't necessarily get checked since they have a very low probability to fail, and in a testing environment it's acceptable to not have bulletproof code. Therefore, we add a rule to not run that check on any file that ends with `_test.go` (Go test convention), so the linter isn't as noisy as it used to be.
Some of the variables we create are flagged by our linters as ineffective assignments, which makes sense as those are generally fed by code below, so we don't need to use the declaration/assignation syntax (:=) but instead can fall back to using var with a type to get the zero value of the declared entity.
The logOutput function had a bunch of nested checks in the code for the function, as well as one ineffasign pointed out by golangci-lint. This commit changes how special cases are processed, and changes a bit how log redirection to a file is handled. Prior to this commit, only when PACKER_LOG and PACKER_LOG_FILE are set does Packer redirect logs to the specified path, which is a bit superfluous as setting PACKER_LOG_FILE should be enough on its own to redirect logs and enable verbose logs. Now, when neither is set, no logOutput is set, if PACKER_LOG_FILE is set (regardless of PACKER_LOG), we redirect to the specified file, and finally if PACKER_LOG is set, we redirect to stderr.
In a couple places in the codebase we didn't check the errors from functions we execute. In some cases this is harmless (or at least ignorable), but others may need to log what went wrong, so for all the reported occurrences we either ignore explicitly or handle the error with a log.
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.
Nice work!
Should, and can, this be back ported to the 1.11.x branch? |
I don't see a reason why this couldn't! I'll add the backport label |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
This PR is a collection of fixups for linters run by golangci-lint.
With this, we should be able to run
golangci-lint
on the whole codebase as all smells are eliminated.