Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure commit sha is always passed to Message #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/pronto/eslint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ 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?

# Use the line specific commit sha for non-fatal errors so that it can be better
# attributed to the specific commit.
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,13 +36,13 @@ 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 = offence['message']
message = "#{offence['ruleId']}: #{message}" if offence['ruleId']

Message.new(path, line, level, message, nil, self.class)
Message.new(path, line, level, 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 == "curly: Expected { after 'if' condition." }
its(:'first.commit_sha') { should == "3a6237c5feacca9a37c36bec5110a1eeb9da703b" }
end
end
end
Expand Down