-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Improve experience of running linters with auto-fix capabilities on save events in editor #4639
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
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello, in v1.57.0, we introduced the flag Then you can use The When typecheck errors occur, most linters (107 linters on 117) cannot perform the analysis because they need type information. Another element, golangci-lint is made to handle packages, I recommend avoiding the usage on file because side effects can appear (e.g. typecheck) |
Hello, If there is no interest in file-level formatting or modifying/disabling the typechecking process then I think the applicability of golangci-lint for this use case will always be a little lacking. In my particular case, using gci directly is probably the best solution. Thanks for considering the issue! (and the advice on the flags) |
Just a precision, typecheck is not a linter or specific golangci-lint process: https://golangci-lint.run/welcome/faq/#why-do-you-have-typecheck-errors So it's not really because "no interest modifying/disabling the typechecking process" but because I highly recommend using golangci-lint on a package instead of a file. |
Do you have a minimal reproducible example? Because
|
For example, with the following file:
Running
Running gci via
|
thank you if you use this sample: package gciexample
func () {
} The behavior will be different: an error will be reported by gci detects syntax errors only, and golangci-lint detects syntax errors and type checking error. Related to #2914 Side note: I know that the name |
@HartBlanc with PR #4653, if you run only a "fast" linter like |
This sounds like a significant improvement! Thanks @ldez! |
Your feature request related to a problem? Please describe
A repo I work in uses golangci-lint with the
gci
linter (among other linters).golangci-lint is run automatically before raising each PR, and the auto-fixes from gci are applied at this point.
As a developer in this repo, I find that these changes introduce a little friction as I need to amend the suggested changes to my latest commit before raising my PR. The change which introduces the import and the change which sorts the imports may then be in different commits which introduces a little unnecessary noise in my changes (or additional effort to reorganise the commits).
I would prefer to have the autofix applied automatically by my editor (neovim) after each save to ensure that imports are sorted as early as possible.
I can configure my editor to run gci when saving a file relatively easily. However, I would like to ensure that when gci runs on save in my editor it uses the same config that golangci-lint will use without needing to manually ensure that the two stay in sync.
I have attempted the following approaches:
Limitations:
goclangci-lint run --fix --fast --enable-only=gci $FILENAME
flags).Limitations:
Describe the solution you'd like
run --autofix-linters
flag or something similar)Describe alternatives you've considered
Additional context
I'm happy to contribute a PR if any of the proposed solutions are acceptable
The text was updated successfully, but these errors were encountered: