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
Document pre-commit hook for staged files #4711
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4711 +/- ##
===========================================
+ Coverage 0 84.71% +84.71%
- Complexity 0 3423 +3423
===========================================
Files 0 490 +490
Lines 0 11255 +11255
Branches 0 2069 +2069
===========================================
+ Hits 0 9535 +9535
- Misses 0 675 +675
- Partials 0 1045 +1045
Continue to review full report at Codecov.
|
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.
Nice addition 👍
|
||
It is also possible to use [the CLI](cli.md) to create a hook that only runs on staged files. This has the advantage of speedier execution, by running on fewer files and avoiding the warm-up time of the gradle daemon. | ||
|
||
Please note, however, that a handful of checks will not work correctly with this approach. This is because they require full type resolution - see for example [ElseCaseInsteadOfExhaustiveWhen](https://detekt.dev/potential-bugs.html#elsecaseinsteadofexhaustivewhen). If you do adopt a partial hook, it is recommended that you still implement a full `detekt` check as part of your CI pipeline. |
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 would link to the Using Type Resolution page here rather than a specific rule
- Link to pre-commit.com - Link to general type resolution page
Thanks! The main problem of mixing cli and gradle is the baseline, I think. If you don't use it, all is fine, but when you run the cli, usually you run it just once for all the project but the baseline is usually per-project/module. And if you uses type solving you enve have two baselines: main and test. And hopefully you don't have multiple build variants on Android... It's a mess. But I agree that this fast loop is good so we can add it and iterate it later. This baseline-mess should be something to fix for 2.0 |
Happily we're not using the baseline stuff, so I haven't encountered these problems. There is a more minor issue with mixing gradle and CLI, though - I have to pipe a few arguments in our hook so the CLI properly mimics our gradle config ( Another option would be to try and get the file list to |
I like having a more comprehensive documentation regarding commit hooks. Thank you very much! |
Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
We ran into an issue using the hook so I've just pushed our updated version - the I've simplified it to not use a file at all 😄 |
Relates to: #1057, #1792, #2175, #2320, #3078
I just got finished implementing a "partial" detekt hook for my team, so I'm raising a PR to document it since it has been asked about many times in the past. Our use case is that we want a hook for "fast feedback" (i.e. not having to wait for a CI build to find out you've violated a check) - as such, we want it to run quickly and aren't too fussed if it occasionally misses things (because CI will still pick those cases up for us, by running a full check).
I've included a disclaimer that checks requiring types won't work properly, however I am yet to verify exactly what will happen in this scenario. Are the affected checks simply skipped when using the
--include
flag? That's what I'm hoping is the case... it would be more problematic if they fall over or might produce false positives etc!Anyhow, hopefully this can be of use to someone. Thanks for developing and maintaining this tool! 😄