From e26f2bd01315edff809b24ac8f0d2129b1162d67 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Tue, 19 Apr 2016 16:14:04 -0400 Subject: [PATCH 1/2] scalastyle: capture messages with no line --- lib/overcommit/hook/pre_commit/scalastyle.rb | 4 +-- .../hook/pre_commit/scalastyle_spec.rb | 36 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/overcommit/hook/pre_commit/scalastyle.rb b/lib/overcommit/hook/pre_commit/scalastyle.rb index 6aa4017c..6034195a 100644 --- a/lib/overcommit/hook/pre_commit/scalastyle.rb +++ b/lib/overcommit/hook/pre_commit/scalastyle.rb @@ -6,8 +6,8 @@ class Scalastyle < Base MESSAGE_REGEX = / ^(?error|warning)\s file=(?(?:\w:)?.+)\s - message=.+\s - line=(?\d+) + message=.+\s* + (line=(?\d+))? /x def run diff --git a/spec/overcommit/hook/pre_commit/scalastyle_spec.rb b/spec/overcommit/hook/pre_commit/scalastyle_spec.rb index 375e36f9..a42dc4f3 100644 --- a/spec/overcommit/hook/pre_commit/scalastyle_spec.rb +++ b/spec/overcommit/hook/pre_commit/scalastyle_spec.rb @@ -41,7 +41,21 @@ OUT end - it { should warn } + it { should warn(/Use : Unit = for procedures/) } + end + + context 'and it reports a warning with no line' do + before do + result.stub(stderr: '', stdout: normalize_indent(<<-OUT)) + warning file=file1.scala message=File must end with newline character + Processed 1 file(s) + Found 0 errors + Found 1 warnings + Finished in 490 ms + OUT + end + + it { should warn(/File must end with newline character/) } end end @@ -64,7 +78,21 @@ OUT end - it { should fail_hook } + it { should fail_hook(/Use : Unit = for procedures/) } + end + + context 'and it reports an error with no line' do + before do + result.stub(stderr: '', stdout: normalize_indent(<<-OUT)) + error file=file1.scala message=File must end with newline character + Processed 1 file(s) + Found 1 errors + Found 0 warnings + Finished in 490 ms + OUT + end + + it { should fail_hook(/File must end with newline character/) } end context 'with a usage message' do @@ -83,7 +111,7 @@ OUT end - it { should fail_hook } + it { should fail_hook(/Usage/) } end context 'with a runtime error' do @@ -104,7 +132,7 @@ ERR end - it { should fail_hook } + it { should fail_hook(/Exception/) } end end end From 6fa0c7be9123464b3343a87b702cec2a3ea2cd57 Mon Sep 17 00:00:00 2001 From: Josh Hagins Date: Tue, 19 Apr 2016 16:19:41 -0400 Subject: [PATCH 2/2] Update change log with Scalastyle fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8f17c4f..d158eca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## master (unreleased) +* Fix `Scalastyle` pre-commit hook to capture messages with no line number * Fix `CoffeeLint` pre-commit hook detection of modified lines ## 0.33.0