diff --git a/lib/overcommit/hook/pre_commit/jsxcs.rb b/lib/overcommit/hook/pre_commit/jsxcs.rb index e07f9cb6..7a196b22 100644 --- a/lib/overcommit/hook/pre_commit/jsxcs.rb +++ b/lib/overcommit/hook/pre_commit/jsxcs.rb @@ -7,22 +7,14 @@ def run return :pass if result.success? if result.status == 1 + # No configuration found return :warn, result.stderr.chomp end - # Keep lines from the output for files that we actually modified - error_lines, warning_lines = result.stdout.split("\n").partition do |output_line| - if match = output_line.match(/^([^:]+):[^\d]+(\d+)/) - file = match[1] - line = match[2] - end - modified_lines(file).include?(line.to_i) - end - - return :fail, error_lines.join("\n") unless error_lines.empty? - - [:warn, "Modified files have lints (on lines you didn't modify)\n" << - warning_lines.join("\n")] + extract_messages( + result.stdout.split("\n"), + /^(?[^:]+):[^\d]+(?\d+)/, + ) end end end diff --git a/spec/overcommit/hook/pre_commit/jsxcs_spec.rb b/spec/overcommit/hook/pre_commit/jsxcs_spec.rb index db7b4858..735a4c29 100644 --- a/spec/overcommit/hook/pre_commit/jsxcs_spec.rb +++ b/spec/overcommit/hook/pre_commit/jsxcs_spec.rb @@ -29,25 +29,13 @@ subject.stub(:execute).and_return(result) end - context 'and it reports lines that were not modified by the commit' do + context 'and it reports an error' do before do result.stub(:stdout).and_return([ 'file1.js.jsx: line 1, col 4, Missing space after `if` keyword' ].join("\n")) - subject.stub(:modified_lines).and_return([2, 3]) - end - - it { should warn } - end - - context 'and it reports lines that were modified by the commit' do - before do - result.stub(:stdout).and_return([ - 'file1.js.jsx: line 1, col 4, Missing space after `if` keyword' - ].join("\n")) - - subject.stub(:modified_lines).and_return([1, 2]) + subject.stub(:modified_lines_in_file).and_return([1, 2]) end it { should fail_hook }