From 941e21d44dc3e7fc1e78ded63e326aec046840b3 Mon Sep 17 00:00:00 2001 From: Stephen Eckenrode Date: Tue, 4 Jun 2019 13:31:34 -0400 Subject: [PATCH 1/2] Correct extract line number output in Stylelint hook The MESSAGE_REGEX for stylelint does not appropriately extract line numbers >= 10. This can cause the hook to incorrectly report errors on modified lines as being for lines that are not modified. This commit changes the regex to correctly handle multiple digits in line numbers. --- lib/overcommit/hook/pre_commit/stylelint.rb | 2 +- spec/overcommit/hook/pre_commit/stylelint_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/overcommit/hook/pre_commit/stylelint.rb b/lib/overcommit/hook/pre_commit/stylelint.rb index a063233a..403c5e27 100644 --- a/lib/overcommit/hook/pre_commit/stylelint.rb +++ b/lib/overcommit/hook/pre_commit/stylelint.rb @@ -8,7 +8,7 @@ class Stylelint < Base # example of output: # index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation) - MESSAGE_REGEX = /^(?.+):\D*(?\d).*$/ + MESSAGE_REGEX = /^(?.+):\D*(?\d+).*$/ def run result = execute(command, args: applicable_files) diff --git a/spec/overcommit/hook/pre_commit/stylelint_spec.rb b/spec/overcommit/hook/pre_commit/stylelint_spec.rb index 3f619a25..d1925e14 100644 --- a/spec/overcommit/hook/pre_commit/stylelint_spec.rb +++ b/spec/overcommit/hook/pre_commit/stylelint_spec.rb @@ -39,6 +39,10 @@ end it { should fail_hook } + + it "extracts lines numbers correctly from output" do + expect(subject.run.map(&:line)).to eq([4, 10]) + end end end end From dcaabbd8d716b32244f77e518262db32b2cd0b4d Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Tue, 4 Jun 2019 14:05:34 -0400 Subject: [PATCH 2/2] Fix RuboCop warning --- spec/overcommit/hook/pre_commit/stylelint_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/overcommit/hook/pre_commit/stylelint_spec.rb b/spec/overcommit/hook/pre_commit/stylelint_spec.rb index d1925e14..d31ba948 100644 --- a/spec/overcommit/hook/pre_commit/stylelint_spec.rb +++ b/spec/overcommit/hook/pre_commit/stylelint_spec.rb @@ -40,7 +40,7 @@ it { should fail_hook } - it "extracts lines numbers correctly from output" do + it 'extracts lines numbers correctly from output' do expect(subject.run.map(&:line)).to eq([4, 10]) end end