diff --git a/lib/pronto/rubocop.rb b/lib/pronto/rubocop.rb index e903722..5e1ec31 100644 --- a/lib/pronto/rubocop.rb +++ b/lib/pronto/rubocop.rb @@ -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) diff --git a/spec/pronto/rubocop_spec.rb b/spec/pronto/rubocop_spec.rb index 71a56cb..3e2034d 100644 --- a/spec/pronto/rubocop_spec.rb +++ b/spec/pronto/rubocop_spec.rb @@ -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) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4262804..54fb2b8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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