-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Make it more clear that golangci-lint run --fix will lint *and* format
#6174
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
Closed
MadLittleMods
wants to merge
1
commit into
golangci:main
from
MadLittleMods:madlittlemods/more-clear-run-lint-format
+3
−3
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
hmm, formatting only happens when using the
--fixoption (golangci-lint run --fix)Note
This command executes enabled linters, and the formatters defined in
formatters,but it does not format the code.
To only format code, use
golangci-lint fmt.To apply both linter fixes and formatting, use
golangci-lint run --fix.--
docs/content/docs/configuration/cli.md#L16-L18There 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 note has been added because some users were confused.
rundoesn't format the code, even with--fix, it only applies suggested fixes.I know this can be seen as a semantic nitpick, but this is important, especially when users are not native English speakers, to have clear concepts.
Sometimes it's better not to be exhaustive when you are explaining a topic, because the details can create more confusion.
Documenting always involves finding a balance between exhaustiveness and ease of understanding.
There is no silver bullet even inside documentation 😄
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.
@ldez The information is available in the docs 👍
Definitely could be chalked up to a case of "read the manual" type of thing so I understand push back on this.
I still feel like there is a blindspot here as a consumer who did reference the docs site to pick a set of
lintersandformattersand tried to navigate the CLI surface (golangci-lint --help). I did not reference the specific CLI docs page to notice the blue note explaining the nuance here.To explain my journey:
.golangci.yml(defaultlintersand a fewformatters)$ golangci-lint --help Smart, fast linters runner. Usage: golangci-lint [flags] golangci-lint [command] Available Commands: [...] fmt Format Go source files. [...] run Lint the code. [...]golangci-lint fmt ./...(to "Format Go source files") andgolangci-lint run ./...("Lint the code.")lintersrules aren't being auto-fixed as indicated on the docs sitegolangci-lint fmt ./...(to "Format Go source files") andgolangci-lint run ./... --fix("Lint the code." and auto-fix the rules it can)golangci/golangci-lint-actionSomething to update
At the very-least we can update the
--fix Fix found issues (if it's supported by the linter)help string to point out that it also runs the formatters. But I would not have dove that deep into the CLI help to find those specifics (golangci-lint run --help).It would be nice if we could make this more clear from the top-level help or something. Any good ideas?
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 can be improved.
I think this will create more confusion because this is not straightforward to explain.
And so, a detail will take up more space than the main subject.
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.
#6175
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.
👍 It's better than nothing but would not have prevented my journey
Thanks for talking this through @ldez 🙂
Uh oh!
There was an error while loading. Please reload this page.
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'm only catching this comment now but even more confused on the distinction 😅
Could I get a clear breakdown of how I can write an exhaustive lint script?
Based on that comment, I guess I need to keep both
golangci-lint fmt ./...andgolangci-lint run ./... --fixin my lint script.And then for CI, is
golangci/golangci-lint-actionactually sufficient? Ideally, I would want it to catch any formatting/autofix difference (to call out someone who forget to run the lint script)Uh oh!
There was an error while loading. Please reload this page.
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.
The formatters are "converted" into linters when using the
runcommand.This is context; the formatters will produce suggested fixes.
golangci-lint run --fixwill be the equivalent of runninggolangci-lint fmt.But we cannot say that the
runcommand is formatting the code.Uh oh!
There was an error while loading. Please reload this page.
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.
In summary:
The
runcommand will run linters (from the configuration file and the flags) and all explicitly defined formatters (from the configuration file only), and the flag--fixwill apply suggested fixes from linters (if they produce suggested fixes) and suggested fixes from formatters (they always produce suggested fixes).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.
Ahh, perfect! Understandable 🙇