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

Fix for syntax error discarding #35

Open
wants to merge 4 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
17 changes: 13 additions & 4 deletions lib/pronto/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,24 @@ def valid_patch?(patch)
ruby_file?(path)
end

def inspect(patch)
def offences(patch)
processed_source = processed_source_for(patch)
offences = @inspector.send(:inspect_file, processed_source).first

offences.sort.reject(&:disabled?).map do |offence|
@inspector.send(:inspect_file, processed_source).first
end

def inspect(patch)
offences(patch).sort.reject(&:disabled?).map do |offence|
patch.added_lines
.select { |line| line.new_lineno == offence.line }
.map { |line| new_message(offence, line) }
end
end.concat(
offences(patch).sort.reject(&:disabled?).select do |offence|
offence.cop_name == "Lint/Syntax"
end.map do |offence|
new_message(offence, patch.added_lines.last)
end
)
end

def new_message(offence, line)
Expand Down
59 changes: 59 additions & 0 deletions spec/pronto/rubocop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,65 @@ module Pronto
end
end

describe '#inspect' do
subject { rubocop.inspect(patches) }

let(:item_patch) { nil }
let(:item_line) { double(new_lineno: 1) }
let(:item_offense) { double(disabled?: false, cop_name: "Lint/Syntax", message: "message-text", status: :uncorrected, line: 9) }
let(:item_line_patch) { nil }
let(:item_delta_value) { nil }
let(:item_severity) { double(name: :error) }

before do
allow(rubocop).to receive(:patch).and_return(patch)
allow(rubocop).to receive(:offences).and_return(array_of_offences)
allow(rubocop).to receive(:patches).and_return(patch)

allow(item_patch).to receive(:added_lines).and_return(array_of_lines)

allow(item_line).to receive(:patch).and_return(line_patch)
allow(item_line).to receive(:commit_sha).and_return("123456789abcdefgh")

allow(line_patch).to receive(:delta).and_return(delta_value)

allow(item_delta_value).to receive(:new_file).and_return(file)

allow(item_offense).to receive(:severity).and_return(severity)

allow(item_severity).to receive(:name).and_return(:error)
end

context 'return offences' do
let(:patch) { item_patch }
let(:line_patch) { item_line_patch }
let(:delta_value) { item_delta_value }
let(:array_of_offences) { [item_offense] }
let(:array_of_lines) { [item_line] }
let(:file) { { :path => "file.rb" } }
let(:severity) { item_severity }

it 'syntax error offense' do
should == [[], Message.new("file.rb", patch.added_lines.last, :error, "message-text", nil, nil)]
end
end

context 'does not return offences' do
let(:item_offense) { double(disabled?: false, cop_name: "Asd", message: "message-text", status: :uncorrected, line: 1) }
let(:patch) { item_patch }
let(:line_patch) { item_line_patch }
let(:delta_value) { item_delta_value }
let(:array_of_offences) { [item_offense] }
let(:array_of_lines) { [item_line] }
let(:file) { { :path => "file.rb" } }
let(:severity) { item_severity }

it 'syntax error offense' do
should == [[Message.new("file.rb", patch.added_lines.last, :error, "message-text", nil, nil)]]
end
end
end

describe '#level' do
subject { rubocop.level(severity) }

Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

RSpec.configure do |config|
config.expect_with(:rspec) { |c| c.syntax = :should }
config.mock_with(:rspec) { |c| c.syntax = :should }
end