Skip to content

Commit

Permalink
[Fix #2194] Allow any options with --auto-gen-config
Browse files Browse the repository at this point in the history
  • Loading branch information
agrimm authored and bbatsov committed Nov 7, 2015
1 parent d351c8a commit c6a63a3
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 @@ -71,6 +71,10 @@
* [#2344](https://github.com/bbatsov/rubocop/pull/2344): When autocorrecting, `Style/ParallelAssignment` reorders assignment statements, if necessary, to avoid breaking code. ([@alexdowad][])
* `Style/MultilineOperationAlignment` does not try to align the receiver and selector of a method call if both are on the LHS of an assignment. ([@alexdowad][])

### 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 @@ -71,7 +71,6 @@ def add_configuration_options(opts, args)
option(opts, '-c', '--config FILE')

option(opts, '--auto-gen-config') do
@validator.validate_auto_gen_config_option(args)
@options[:formatters] = [[DEFAULT_FORMATTER],
[Formatter::DisabledConfigFormatter,
ConfigLoader::AUTO_GENERATED_FILE]]
Expand Down Expand Up @@ -193,14 +192,6 @@ def validate_compatibility
fail ArgumentError, "Incompatible cli options: #{incompat.inspect}"
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 @@ -978,21 +978,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 @@ -232,6 +232,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 c6a63a3

Please sign in to comment.