Skip to content

Commit

Permalink
Merge pull request #6436 from deivid-rodriguez/fix_interrupted_exit_s…
Browse files Browse the repository at this point in the history
…tatus

Fix exit status when rubocop is interrupted
  • Loading branch information
koic committed Nov 1, 2018
2 parents 18eaa7a + 75df7f2 commit c5a8470
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [#5934](https://github.com/rubocop-hq/rubocop/issues/5934): Handle the combination of `--auto-gen-config` and `--config FILE` correctly. ([@jonas054][])
* [#5970](https://github.com/rubocop-hq/rubocop/issues/5970): Make running `--auto-gen-config` in a subdirectory work. ([@jonas054][])
* [#6412](https://github.com/rubocop-hq/rubocop/issues/6412): Fix an `unknown keywords` error when using `Psych.safe_load` with Ruby 2.6.0-preview2. ([@koic][])
* [#6436](https://github.com/rubocop-hq/rubocop/pull/6436): Fix exit status code to be 130 when rubocop is interrupted. ([@deivid-rodriguez][])

## 0.60.0 (2018-10-26)

Expand Down
11 changes: 7 additions & 4 deletions lib/rubocop/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class CLI
SKIPPED_PHASE_1 = 'Phase 1 of 2: run Metrics/LineLength cop (skipped ' \
'because the default Metrics/LineLength:Max is ' \
'overridden)'.freeze
STATUS_SUCCESS = 0
STATUS_OFFENSES = 1
STATUS_ERROR = 2
STATUS_SUCCESS = 0
STATUS_OFFENSES = 1
STATUS_ERROR = 2
STATUS_INTERRUPTED = 128 + Signal.list['INT']

class Finished < RuntimeError; end

Expand Down Expand Up @@ -163,7 +164,9 @@ def execute_runner(paths)

all_pass_or_excluded = all_passed || @options[:auto_gen_config]

if all_pass_or_excluded && !runner.aborting? && runner.errors.empty?
if runner.aborting?
STATUS_INTERRUPTED
elsif all_pass_or_excluded && runner.errors.empty?
STATUS_SUCCESS
else
STATUS_OFFENSES
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
subject(:cli) { described_class.new }

context 'when interrupted' do
it 'returns 1' do
it 'returns 130' do
allow_any_instance_of(RuboCop::Runner)
.to receive(:aborting?).and_return(true)
create_empty_file('example.rb')
expect(cli.run(['example.rb'])).to eq(1)
expect(cli.run(['example.rb'])).to eq(130)
end
end

Expand Down

0 comments on commit c5a8470

Please sign in to comment.