Skip to content

Commit

Permalink
[Fix rubocop#2194] Allow any options with --auto-gen-config
Browse files Browse the repository at this point in the history
  • Loading branch information
agrimm committed Oct 11, 2015
1 parent 871586e commit cd1f6e8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
* [#2295](https://github.com/bbatsov/rubocop/issues/2295): Fix Performance/Detect autocorrect to handle rogue newlines. ([@palkan][])
* [#2294](https://github.com/bbatsov/rubocop/issues/2294): Do not register an offense in `Performance/StringReplacement` for regex with options. ([@rrosenblum][])

### Changes

* [#2194](https://github.com/bbatsov/rubocop/issues/2194): Allow any options with `--auto-gen-config`. ([@agrimm][])

## 0.34.2 (21/09/2015)

### Bug Fixes
Expand Down
9 changes: 0 additions & 9 deletions lib/rubocop/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def add_configuration_options(opts, args)
option(opts, '-c', '--config FILE')

option(opts, '--auto-gen-config') do
validate_auto_gen_config_option(args)
@options[:formatters] = [[DEFAULT_FORMATTER],
[Formatter::DisabledConfigFormatter,
ConfigLoader::AUTO_GENERATED_FILE]]
Expand Down Expand Up @@ -173,14 +172,6 @@ def long_opt_symbol(args)
long_opt[2..-1].sub(/ .*/, '').tr('-', '_').to_sym
end

def validate_auto_gen_config_option(args)
return if args.empty?
return if args.size <= 2 && args.first == '--exclude-limit'

warn '--auto-gen-config can only be combined with --exclude-limit.'
exit(1)
end

def validate_exclude_limit_option(args)
if @options[:exclude_limit] !~ /^\d+$/
# Emulate OptionParser's behavior to make failures consistent regardless
Expand Down
15 changes: 0 additions & 15 deletions spec/rubocop/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -980,21 +980,6 @@ def abs(path)
''].join("\n"))
end

it 'exits with error if file arguments are given' do
create_file('example1.rb', ['# encoding: utf-8',
'x= 0 ',
'#' * 85,
'y ',
'puts x'])
expect { cli.run(['--auto-gen-config', 'example1.rb']) }
.to exit_with_code(1)
expect($stderr.string)
.to eq(['--auto-gen-config can only be combined with ' \
'--exclude-limit.',
''].join("\n"))
expect($stdout.string).to eq('')
end

it 'can generate a todo list' do
create_file('example1.rb', ['# encoding: utf-8',
'$x= 0 ',
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ def abs(path)
end
end

describe '--auto-gen-config' do
it 'accepts other options' do
expect { options.parse %w(--auto-gen-config --rails) }
.not_to raise_error
end
end

describe '-s/--stdin' do
before do
$stdin = StringIO.new
Expand Down

0 comments on commit cd1f6e8

Please sign in to comment.