Repository navigation
Replies: 1 comment 1 reply
|
I haven’t thought this through carefully yet, but my initial impression is that it would be difficult to implement. I’ll take a closer look later. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Add an option (e.g.
--delta-only/--check-delta) to builtin pattern hooks (deny-patternandrequire-pattern) so that patterns are evaluated only against newly added or modified lines in the Git diff, rather than scanning the full file content from disk.Motivation
In large codebases and monorepos, teams frequently introduce rules to ban deprecated APIs, imports, or patterns in new code (ratcheted migrations).
Currently,
deny-patternscans the entire file from disk whenever a file is staged or selected:deny-patternfails the commit.repo: localdiff-parsing scripts.Having native
--delta-onlysupport inrepo: builtinwould allow zero-setup, blazingly fast ratcheting checks directly withinprek.Proposed Configuration
Proposed Behavior
--delta-onlyis enabled:prek run): Inspects staged diff hunks (e.g.git diff --cached -U0) and evaluates patterns only on added lines (+lines in diff hunks).prek run --from-ref <REF> [--to-ref <REF>]): Inspects diff hunks across the specified revision range (e.g.git diff -U0 <FROM_REF>...<TO_REF>).<file>:<line>: <matched_text>for matches found within added lines and exits with code 1. Pre-existing matches on untouched lines are ignored.--delta-onlyis omitted: Default behavior is preserved (scans full file from disk).-m/--multiline), or should operate on contiguous added hunk blocks.References
crates/prek/src/hooks/builtin_hooks/pattern.rsrustgrepbuiltin for one-off hooks #2355 (Initialrustgrep/deny-patternbuiltin request)All reactions