overcommit icon indicating copy to clipboard operation
overcommit copied to clipboard

Precommit: Ktlint runs on unmodified files

Open hkhan-iengineering opened this issue 4 years ago • 1 comments

Ktlint throws errors from unmodified files when running pre-commit. Below is my Ktlint configuration: Ktlint: problem_on_unmodified_line: report enabled: true description: 'Analyze with Ktlint' required_executable: 'ktlint' install_command: 'brew install ktlint' include: '**/*.kt' flags: []

I searched the Ktlint repository for any flags specific to this issue but couldn't find one, any help?

hkhan-iengineering avatar May 10 '22 06:05 hkhan-iengineering

I reproduced this with Ktlint 1.8.0 in a disposable repository. The cause is the hook name: the built-in hook is KtLint, with a capital L, while the report uses Ktlint.

Use:

PreCommit:
  KtLint:
    enabled: true
    problem_on_unmodified_line: report

Ktlint plus required_executable: ktlint creates an ad hoc hook, which receives Git's original pre-commit arguments (no filenames). Ktlint then scans its default patterns and reports unchanged files. The built-in KtLint passes only applicable modified filenames.

I verified a real commit fails on an unchanged invalid Bad.kt with the reported spelling, then succeeds with the same files after changing only Ktlint to KtLint. #927 documents the correction and strengthens the built-in argument test; it will close this issue after CI passes and the PR is merged.

sds avatar Nov 10 '26 05:11 sds