Skip to content

Commit 0b1e50e

Browse files
authored
Document the case-sensitive KtLint hook name (#927)
The configuration in #787 uses `Ktlint`, while the built-in hook is named `KtLint`. With `required_executable: ktlint`, the misspelled name becomes an ad hoc hook. It receives Git's original hook arguments, so a pre-commit invocation runs Ktlint with no filenames and scans unmodified files too. Document the exact built-in name, give a minimal working configuration, and explain why the alternative spelling behaves differently. Strengthen the existing KtLint success example to require passing the applicable filenames to the executable. Fixes #787 through a configuration correction; no runtime change is necessary. Local reproduction with Ktlint 1.8.0 downloaded into `/tmp` and a disposable Git repository: - Commit an invalid `Bad.kt`, then stage only a valid `Good.kt` and Overcommit configuration. - With the report's `Ktlint` spelling, a real commit fails and reports the unchanged `Bad.kt`. - Change only the hook name to `KtLint`: the real commit succeeds and does not report `Bad.kt`. Validation: existing KtLint specs pass with the stronger argument assertion; RuboCop passes. Full CI is required before merging. Final verification: [run 42762226697](https://github.com/sds/overcommit/actions/runs/42762226697) passed all 38 checks, including Linux/Windows Ruby 3.3, 3.4, and 4.0, lint, CI, and all coverage statuses. All 20 completed jobs report zero annotations.
1 parent 6647ccc commit 0b1e50e

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,20 @@ information on this option and what exactly it controls.
396396
Currently, Overcommit supports the following hooks out of the box—simply
397397
enable them in your `.overcommit.yml`.
398398

399+
Hook names are case-sensitive. For example, use `KtLint` to enable the built-in
400+
Kotlin hook, which passes only the applicable modified files to `ktlint`:
401+
402+
```yaml
403+
PreCommit:
404+
KtLint:
405+
enabled: true
406+
```
407+
408+
Using `Ktlint` with a `required_executable: ktlint` setting instead defines an
409+
[ad hoc hook](#adding-existing-git-hooks). Ad hoc hooks receive Git's original
410+
hook arguments, so this runs `ktlint` without filenames and lets it check its
411+
default file patterns, including unmodified files.
412+
399413
**Note**: Hooks with a `*` are enabled by default.
400414

401415
**Warning**: This list represents the list of hooks available on the `master`

‎spec/overcommit/hook/pre_commit/kt_lint_spec.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
before do
1616
result = double('result')
1717
result.stub(:success?).and_return(true)
18-
subject.stub(:execute).and_return(result)
18+
subject.should_receive(:execute).
19+
with(['ktlint'], args: %w[file1.kt file2.kt]).and_return(result)
1920
end
2021

2122
it { should pass }

0 commit comments

Comments
 (0)