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 fail on empty files #4

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
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
danger-shiphawk-plugin (1.0.7)
danger-shiphawk-plugin (1.0.9)
danger
rubocop

Expand Down
11 changes: 7 additions & 4 deletions lib/danger_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ def offenses
end

def detect_offenses
rubocop_output = json_parse(rubocop)
files_string = files_to_lint

all_offenses = rubocop_output.files.flat_map do |file|
return [] if files_string.empty?
rubocop_output = call_rubocop(files_string)

all_offenses = json_parse(rubocop_output).files.flat_map do |file|
offenses = file.offenses
next [] if offenses.empty?

Expand All @@ -61,14 +64,14 @@ def detect_offenses
all_offenses.sort_by(&:serenity)
end

def rubocop
def call_rubocop(files_string)
command = ['bundle', 'exec']
command += ['rubocop']
command += ['--force-exclusion']
command += ['--format', 'json']
command += ['--config', @config.shellescape] if @config

`#{command.join(' ')} #{files_to_lint}`
`#{command.join(' ')} #{files_string}`
end

def files_to_lint
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Danger
module ShipHawkPlugin
VERSION = '1.0.8'
VERSION = '1.0.9'
end
end
17 changes: 13 additions & 4 deletions spec/danger_shiphawk_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
context 'rubocop launch' do
it 'with format only' do
expect_any_instance_of(described_class).to receive(:`)
.with('bundle exec rubocop --format json .').and_return(rubocop_response_blank)
.with('bundle exec rubocop --force-exclusion --format json .').and_return(rubocop_response_blank)

@shiphawk_plugin.checkup
end

it 'with config-file' do
expect_any_instance_of(described_class).to receive(:`)
.with('bundle exec rubocop --format json --config hello.txt .').and_return(rubocop_response_blank)
.with('bundle exec rubocop --force-exclusion --format json --config hello.txt .').and_return(rubocop_response_blank)

@shiphawk_plugin.checkup(config: 'hello.txt')
end
Expand All @@ -67,7 +67,16 @@
expect(@shiphawk_plugin.git).to receive(:added_files).and_return(['log/temp.rb'])

expect_any_instance_of(described_class).to receive(:`)
.with('bundle exec rubocop --format json temp.rb log/temp.rb').and_return(rubocop_response_blank)
.with('bundle exec rubocop --force-exclusion --format json temp.rb log/temp.rb').and_return(rubocop_response_blank)

@shiphawk_plugin.checkup(files: 'diff')
end

it 'has no diff' do
expect(@shiphawk_plugin.git).to receive(:modified_files).and_return([])
expect(@shiphawk_plugin.git).to receive(:added_files).and_return([])

expect_any_instance_of(described_class).to_not receive(:`)

@shiphawk_plugin.checkup(files: 'diff')
end
Expand All @@ -76,7 +85,7 @@
context 'offenses' do
before do
expect_any_instance_of(described_class).to receive(:`)
.with('bundle exec rubocop --format json .').and_return(rubocop_response_with_errors)
.with('bundle exec rubocop --force-exclusion --format json .').and_return(rubocop_response_with_errors)
end

it 'check errors messages' do
Expand Down