Skip to content

Commit

Permalink
Ensure commit sha is always passed to Message
Browse files Browse the repository at this point in the history
  • Loading branch information
tobischo committed May 10, 2021
1 parent 46848c9 commit 9a66ccc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/pronto/eslint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ def run

@patches.select { |patch| patch.additions > 0 }
.select { |patch| js_file?(patch.new_file_full_path) }
.map { |patch| inspect(patch) }
.map { |patch| inspect(patch, @patches.commit) }
.flatten.compact
end

def inspect(patch)
def inspect(patch, commit_sha)
offences = Eslintrb.lint(patch.new_file_full_path, options).compact

fatals = offences.select { |offence| offence['fatal'] }
.map { |offence| new_message(offence, nil) }
.map { |offence| new_message(offence, nil, commit_sha) }

return fatals if fatals && !fatals.empty?

offences.map do |offence|
patch.added_lines.select { |line| line.new_lineno == offence['line'] }
.map { |line| new_message(offence, line) }
.map { |line| new_message(offence, line, line.commit_sha) }
end
end

Expand All @@ -34,11 +34,11 @@ def options
end
end

def new_message(offence, line)
def new_message(offence, line, commit_sha)
path = line ? line.patch.delta.new_file[:path] : '.eslintrc'
level = line ? :warning : :fatal

Message.new(path, line, level, offence['message'], nil, self.class)
Message.new(path, line, level, offence['message'], commit_sha, self.class)
end

def js_file?(path)
Expand Down
3 changes: 3 additions & 0 deletions spec/pronto/eslint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module Pronto
subject.each do |element|
element.msg.should ==
'Parsing error: ecmaVersion must be 3, 5, 6, or 7.'
element.commit_sha.should ==
'931004157205727e6a47586feaed0473c6ddbd66'
end
end
end
Expand All @@ -40,6 +42,7 @@ module Pronto

its(:count) { should == 9 }
its(:'first.msg') { should == "Expected { after 'if' condition." }
its(:'first.commit_sha') { should == "3a6237c5feacca9a37c36bec5110a1eeb9da703b" }
end
end
end
Expand Down

0 comments on commit 9a66ccc

Please sign in to comment.