Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error when running --only or --except options #7905

Merged

Conversation

koic
Copy link
Member

@koic koic commented Apr 24, 2020

This PR fixes an error when running rubocop --only or rubocop --except options without cop name argument.

Before

% rubocop --only
undefined method `empty?' for nil:NilClass
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.82.0/lib/rubocop/options.rb:87:in `block in add_cop_selection_csv_option'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.82.0/lib/rubocop/options.rb:206:in `block in option'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/2.7.0/optparse.rb:1589:in `block in parse_in_order'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/2.7.0/optparse.rb:1575:in `catch'

After

% rubocop --only
--only argument should be [COP1,COP2,...].

The same is true for rubocop --except.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

This PR fixes an error when running `rubocop --only` or
`rubocop --except` options without cop name argument.

## Before

```consle
% rubocop --only
undefined method `empty?' for nil:NilClass
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.82.0/lib/rubocop/options.rb:87:in
`block in add_cop_selection_csv_option'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.82.0/lib/rubocop/options.rb:206:in
`block in option'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/2.7.0/optparse.rb:1589:in
`block in parse_in_order'
/Users/koic/.rbenv/versions/2.7.1/lib/ruby/2.7.0/optparse.rb:1575:in `catch'
```

## After

```console
% rubocop --only
--only argument should be [COP1,COP2,...].
```

The same is true for `rubocop --except`.
@bbatsov bbatsov merged commit 9d51e4f into rubocop:master Apr 24, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 24, 2020

Nice catch!

@koic koic deleted the fix_error_when_using_only_or_except_options branch April 24, 2020 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants