mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.73k stars 276 forks source link

Can 'revive' only check for uncommitted code? #886

Closed shiw-yang closed 12 months ago

shiw-yang commented 12 months ago

Is your feature request related to a problem? Please describe. I currently have a project with a backlog of code that hasn't undergone code analysis. We are looking to integrate 'revive' for pre-commit checks. At this point, we're interested in examining only the code that hasn't been committed yet.

Describe the solution you'd like I would like the ability to control 'revive' so that it only checks un-committed code , either through a 'revive.toml' or args parameters. Describe alternatives you've considered none

Additional context none

denisvmedia commented 12 months ago

This would mean revive will have to be aware of git. Which I'd personally avoid. It could be technically possible using files to check passed to revive, but AFAIK there is no way for revive to check only certain files. But this could be a solution.

chavacava commented 12 months ago

Hi @shiw-yang, thanks for submitting your question. The subject was already discussed before: #42 and #109

denisvmedia commented 12 months ago

BTW, it should be possible if running revive through golangci-lint as it has these flags.

  -n, --new                            Show only new issues: if there are unstaged changes or untracked files, only those changes are analyzed, else only changes in HEAD~ are analyzed.
                                       It's a super-useful option for integration of golangci-lint into existing large codebase.
                                       It's not practical to fix all existing issues at the moment of integration: much better to not allow issues in new code.
                                       For CI setups, prefer --new-from-rev=HEAD~, as --new can skip linting the current patch if any scripts generate unstaged files before golangci-lint runs.
      --new-from-rev REV               Show only new issues created after git revision REV
      --new-from-patch PATH            Show only new issues created in git patch with file path PATH

Though I never tried it myself.