diff --git a/lib/overcommit/hook/pre_commit/stylelint.rb b/lib/overcommit/hook/pre_commit/stylelint.rb index b129cbd2..aae26f08 100644 --- a/lib/overcommit/hook/pre_commit/stylelint.rb +++ b/lib/overcommit/hook/pre_commit/stylelint.rb @@ -12,7 +12,7 @@ class Stylelint < Base def run result = execute(command, args: applicable_files) - output = result.stdout.chomp + output = result.stdout + result.stderr.chomp return :pass if result.success? && output.empty? extract_messages( diff --git a/spec/overcommit/hook/pre_commit/stylelint_spec.rb b/spec/overcommit/hook/pre_commit/stylelint_spec.rb index d31ba948..68e83f65 100644 --- a/spec/overcommit/hook/pre_commit/stylelint_spec.rb +++ b/spec/overcommit/hook/pre_commit/stylelint_spec.rb @@ -15,6 +15,7 @@ before do result = double('result') result.stub(:success?).and_return(true) + result.stub(:stderr).and_return('') result.stub(:stdout).and_return('') subject.stub(:execute).and_return(result) end @@ -22,7 +23,7 @@ it { should pass } end - context 'when stylelint exits unsucessfully' do + context 'when stylelint exits unsucessfully with messages on stdout (stylelint < 16)' do let(:result) { double('result') } before do @@ -32,6 +33,7 @@ context 'and it reports an error' do before do result.stub(:success?).and_return(false) + result.stub(:stderr).and_return('') result.stub(:stdout).and_return([ 'index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)', 'form.css: line 10, col 6, error - Expected indentation of 4 spaces (indentation)', @@ -45,4 +47,29 @@ end end end + + context 'when stylelint exits unsucessfully with messages on stderr (stylelint >= 16)' do + let(:result) { double('result') } + + before do + subject.stub(:execute).and_return(result) + end + + context 'and it reports an error' do + before do + result.stub(:success?).and_return(false) + result.stub(:stdout).and_return('') + result.stub(:stderr).and_return([ + 'index.css: line 4, col 4, error - Expected indentation of 2 spaces (indentation)', + 'form.css: line 10, col 6, error - Expected indentation of 4 spaces (indentation)', + ].join("\n")) + 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