From 75df7f2360c5d749d1aa88a32ad3be8f78c4a3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 31 Oct 2018 14:26:08 -0300 Subject: [PATCH] Fix exit status when rubocop is interrupted --- CHANGELOG.md | 1 + lib/rubocop/cli.rb | 11 +++++++---- spec/rubocop/cli_spec.rb | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 130acc4fdf84..16ed029e6c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/rubocop/cli.rb b/lib/rubocop/cli.rb index 30ff1a06641e..30330737c9fe 100644 --- a/lib/rubocop/cli.rb +++ b/lib/rubocop/cli.rb @@ -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 @@ -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 diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index 8811cca4b0ea..83322e5ac9de 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -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