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

Cleanup lint codebase #13110

Merged
merged 6 commits into from
Jul 18, 2024
Merged

Cleanup lint codebase #13110

merged 6 commits into from
Jul 18, 2024

Conversation

lbajolet-hashicorp
Copy link
Contributor

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.

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.
@lbajolet-hashicorp lbajolet-hashicorp added the tech-debt Issues and pull requests related to addressing technical debt or improving the codebase label Jul 18, 2024
@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner July 18, 2024 13:45
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

Nice work!

@nywilken
Copy link
Contributor

nywilken commented Jul 18, 2024

Should, and can, this be back ported to the 1.11.x branch?

@lbajolet-hashicorp
Copy link
Contributor Author

I don't see a reason why this couldn't! I'll add the backport label

@lbajolet-hashicorp lbajolet-hashicorp added the backport/1.11.x Backport PR changes to `release/1.11.x` label Jul 18, 2024
@lbajolet-hashicorp lbajolet-hashicorp merged commit 3e3b136 into main Jul 18, 2024
13 checks passed
@lbajolet-hashicorp lbajolet-hashicorp deleted the cleanup_lint_codebase branch July 18, 2024 18:38
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/1.11.x Backport PR changes to `release/1.11.x` tech-debt Issues and pull requests related to addressing technical debt or improving the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants