-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
pre-commit hook runs on all files instead of just changed files in the repo #1245
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. |
were you able to fix this? I believe I'm having the same issue, although our repo/modules setup is a bit more complicated |
I've had a quick look and I'm pretty sure golangci-lint doesn't support that at the moment. When interfacing with pre-commit, it would be best if golangci-lint took a list of filenames like I've looked at the code a little am I'm pretty lost, if anybody is familiar with the codebase I'd love to hear if you think that's possible. If not, then the only way I can see is if we added another switch that maybe runs only on staged changes? |
Just to add a bit of information to this issue, in the I don't know if |
Not sure if make sense for |
We are facing the same scenario as this issue described, and it could be quite hard for us to accept and modify all the errors given by golangci-lint at once. But in order to improve code quality, it is really essential to integrate it. Any thoughts? |
The issue here is that you have issues:
new: true Remember that this flag has different meaning based on context. Also from the docs:
This also means that (after chaning the From your repository (if I amend the latest commit with the proper config): $ golangci-lint run --print-issued-lines=false
service/should_be_lint.go:7:1: commentFormatting: put a space between `//` and comment text (gocritic)
main.go:14:1: commentFormatting: put a space between `//` and comment text (gocritic)
$ echo $?
1 $ echo "package main" > main2.go
$ golangci-lint run --print-issued-lines=false
$ echo $?
0 $ git add . && git commit -m"New rev"
$ golangci-lint run --print-issued-lines=false
$ echo $?
0 $ echo "\nvar x = 1" >> main2.go
$ git commit -am"Add failing code"
$ golangci-lint run --print-issued-lines=false
main2.go:3:5: `x` is unused (deadcode)
$ echo $?
1 You might also be interested in using |
Fixes golangci#1245 by passing filenames from pre-commit to `golangci-lint run` and when used with `--new-from-rev HEAD` allows for partial commit support.
I want to run the tool only on the changed files since I am integrating it to an existing repo which is huge. Fixing all the errors at once is not practical.
I am using the
run: new
config in the.golangci.yml
but it still runs on all the files not just the changed files.I have created this small repo to mock the issue: https://github.com/heisfullstacked/golintci-test
If I uncomment the comment in the file
service/should_be_lint.go
and try to commit, I am expecting the pre-commit to only show errors in that file.Instead I see errors from both
main.go
andservice/should_be_lint.go
Additional Information
Version of golangci-lint
Config file
Go environment
Verbose output of running
The text was updated successfully, but these errors were encountered: