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

Add explicit error when a section is empty #1784

Merged
merged 1 commit into from
Apr 14, 2015

Conversation

bankair
Copy link
Contributor

@bankair bankair commented Apr 11, 2015

Raises a ValidationError "empty section #{name} found in #{loaded_path || self}" instead of 'undefined method `each_key' for nil:NilClass' when the configuration file contains an empty section.

closes issue #1782

@bankair bankair force-pushed the empty-config-causes-explicit-error branch from 5ed8f57 to 17cc2c1 Compare April 11, 2015 20:24
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 12, 2015

Looks good to me. @jonas054 what do you think?

return unless @hash.key?(name) && @hash[name].nil?
fail ValidationError,
"empty section #{name} found " \
"in #{loaded_path || self}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not immediately obvious (to me, at least) what loaded_path || self would return. Maybe extract it to a variable with a descriptive name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

That expression is used at least 2 other times in that file.

The way I see things, I could factorize it in a method called loaded_path_or_self, but I'm not sure it will add something to the code comprehension.

@bbatsov, what's your input on this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn’t see that the expression was used already. Surely re-using it should be ok for this PR.

@jonas054
Copy link
Collaborator

👍 Looks good! I agree that loaded_path || self is a bit weird. It's there to support specs that create a cop without configuration, but all specs still pass if you remove || self. Leave it for now.

@bankair
Copy link
Contributor Author

bankair commented Apr 13, 2015

Thanks for your feedbacks, guys.

@bankair bankair force-pushed the empty-config-causes-explicit-error branch from 11e69e2 to bbd4905 Compare April 13, 2015 18:48
it 'raises validation error' do
expect { configuration.validate }
.to raise_error(described_class::ValidationError,
%r{^empty section Metrics\/LineLength})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is / escaped?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake. Thanks for noticing.

@bankair bankair force-pushed the empty-config-causes-explicit-error branch from bbd4905 to b95689a Compare April 13, 2015 19:56
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 14, 2015

Please, rebase on top of the current master.

@bankair bankair force-pushed the empty-config-causes-explicit-error branch from b95689a to 827d0c8 Compare April 14, 2015 20:36
@bankair
Copy link
Contributor Author

bankair commented Apr 14, 2015

Done.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 14, 2015

👍

bbatsov added a commit that referenced this pull request Apr 14, 2015
@bbatsov bbatsov merged commit f6159fa into rubocop:master Apr 14, 2015
@kWhittington
Copy link

Should this fix have worked it's way into v0.32.0? I'm getting the undefined methodeach_key' for false:FalseClass` with this config:

# Please see the following for configuration options:
#   https://github.com/bbatsov/rubocop
#   https://github.com/nevir/rubocop-rspec
require: rubocop-rspec

AllCops:
  RunRailsCops: true

Documentation: false

When I remove the Documentation: false bit, rubocop works again:

# Please see the following for configuration options:
#   https://github.com/bbatsov/rubocop
#   https://github.com/nevir/rubocop-rspec
require: rubocop-rspec

AllCops:
  RunRailsCops: true

Do you think this error is related to the bug this P.R. is fixing?

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.

5 participants