Skip to content

Commit 06d5d75

Browse files
committed
Fix TrailingWhitespace to use extract_messages
Previously, if `problem_on_unmodified_line` was set to something other than `report`, this hook would still report an error for lines the user didn't modify. Correct this by changing the hook to use `extract_messages` so line information is included.
1 parent 60917a8 commit 06d5d75

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
[Scalariform](https://mdr.github.io/scalariform/)
1212
* Add `SlimLint` pre-commit hook that analyzes Slim templates with
1313
[Slim-Lint](https://github.com/sds/slim-lint)
14+
* Enhance `TrailingWhitespace` pre-commit hook to including line information in
15+
errors, making it work as expected when `problem_on_unmodified_line` is set
16+
to something other than `report`
1417

1518
## 0.24.0
1619

lib/overcommit/hook/pre_commit/trailing_whitespace.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module Overcommit::Hook::PreCommit
33
class TrailingWhitespace < Base
44
def run
55
result = execute(command + applicable_files)
6-
unless result.stdout.empty?
7-
return :fail, "Trailing whitespace detected:\n#{result.stdout}"
8-
end
96

10-
:pass
7+
extract_messages(
8+
result.stdout.split("\n"),
9+
/^(?<file>[^:]+):(?<line>\d+)/,
10+
)
1111
end
1212
end
1313
end

0 commit comments

Comments
 (0)