Skip to content

Commit

Permalink
Switch Jsxcs hook to use extract_messages
Browse files Browse the repository at this point in the history
Change-Id: I707995644849c93f1b87a793896f7c71dd7dea98
Reviewed-on: http://gerrit.causes.com/44908
Tested-by: jenkins <[email protected]>
Reviewed-by: Shane da Silva <[email protected]>
  • Loading branch information
sds committed Nov 30, 2014
1 parent c8b19c2 commit 647b1bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
18 changes: 5 additions & 13 deletions lib/overcommit/hook/pre_commit/jsxcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
/^(?<file>[^:]+):[^\d]+(?<line>\d+)/,
)
end
end
end
16 changes: 2 additions & 14 deletions spec/overcommit/hook/pre_commit/jsxcs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 647b1bf

Please sign in to comment.