Skip to content

Commit

Permalink
Fix bug with --auto-gen-config and a file that does not exist (#3239)
Browse files Browse the repository at this point in the history
  • Loading branch information
meganemura authored and bbatsov committed Jun 21, 2016
1 parent f77f3cd commit 2ad9b67
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* [#3056](https://github.com/bbatsov/rubocop/issues/3056): Fix `Style/StringLiterals` to register offenses on non-ascii strings. ([@deivid-rodriguez][])
* [#2986](https://github.com/bbatsov/rubocop/issues/2986): Fix `RedundantBlockCall` to not report calls that pass block arguments, or where the block has been overridden. ([@owst][])
* [#3223](https://github.com/bbatsov/rubocop/issues/3223): Return can take many arguments. ([@ptarjan][])
* [#3239](https://github.com/bbatsov/rubocop/pull/3239): Fix bug with --auto-gen-config and a file that does not exist. ([@meganemura][])

### Changes

Expand Down
8 changes: 6 additions & 2 deletions lib/rubocop/formatter/disabled_config_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class << self
attr_accessor :config_to_allow_offenses, :detected_styles
end

def initialize(output, options = {})
super
@cops_with_offenses ||= Hash.new(0)
@files_with_offenses ||= {}
end

def file_started(_file, _file_info)
@exclude_limit_option = @options[:exclude_limit]
@exclude_limit = (
Expand All @@ -34,8 +40,6 @@ def file_started(_file, _file_info)
end

def file_finished(file, offenses)
@cops_with_offenses ||= Hash.new(0)
@files_with_offenses ||= {}
offenses.each do |o|
@cops_with_offenses[o.cop_name] += 1
@files_with_offenses[o.cop_name] ||= []
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cli/cli_auto_gen_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,9 @@ def abs(path)
' Enabled: false',
''].join("\n"))
end

it 'can be called when there are no files to inspection' do
expect(cli.run(['--auto-gen-config'])).to eq(0)
end
end
end
8 changes: 8 additions & 0 deletions spec/rubocop/formatter/disabled_config_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ def o.path
''].flatten.join("\n"))
end

it 'creates a .rubocop_todo.yml even if RuboCop does not inspect ' \
'any files' do
formatter.finished([])
expect(output.string).to eq(format(described_class::HEADING,
'rubocop --auto-gen-config') +
"\n")
end

context 'when exclude_limit option is passed into constructor' do
let(:formatter) { described_class.new(output, exclude_limit: 5) }

Expand Down

0 comments on commit 2ad9b67

Please sign in to comment.