-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Cop Gemspec/OrderedDependencies
breaks when parsing a frozen gem name.
#6086
Labels
Comments
8 tasks
Thanks for the feedback. I confirmed this reproduction and I opened a PR #6087. |
koic
added a commit
to koic/rubocop
that referenced
this issue
Jul 9, 2018
Fixes rubocop#6086. This PR fixes an error for `Gemspec/OrderedDependencies` when using method call to gem names in gemspec. The following is reproduction steps. ```console % cat /tmp/foo.gemspec Gem::Specification.new do |spec| spec.add_development_dependency 'rspec'.freeze spec.add_development_dependency 'rubocop'.freeze end % rubocop foo.gemspec --only Gemspec/OrderedDependencies -d For /private/tmp: configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/config/default.yml Inheriting configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/config/enabled.yml Inheriting configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/config/disabled.yml Inspecting 1 file Scanning /private/tmp/foo.gemspec An error occurred while Gemspec/OrderedDependencies cop was inspecting /private/tmp/foo.gemspec. undefined method `downcase' for nil:NilClass (snip) /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/exe/rubocop:12:in `<top (required)>' /Users/koic/.rbenv/versions/2.5.1/bin/rubocop:23:in `load' /Users/koic/.rbenv/versions/2.5.1/bin/rubocop:23:in `<main>' . 1 file inspected, no offenses detected 1 error occurred: An error occurred while Gemspec/OrderedDependencies cop was inspecting /private/tmp/foo.gemspec. Errors are usually caused by RuboCop bugs. Please, report your problems to RuboCop's issue tracker. https://github.com/rubocop-hq/rubocop/issues Mention the following information in the issue report: 0.58.0 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-darwin17) Finished in 0.43951499997638166 seconds ``` This PR considers the case to be called in the method chain for the gem name as follows. ```ruby spec.add_development_dependency 'foo'.bar.baz ``` In this case, the gem name will be resolved searching recursively.
bbatsov
pushed a commit
that referenced
this issue
Jul 9, 2018
Fixes #6086. This PR fixes an error for `Gemspec/OrderedDependencies` when using method call to gem names in gemspec. The following is reproduction steps. ```console % cat /tmp/foo.gemspec Gem::Specification.new do |spec| spec.add_development_dependency 'rspec'.freeze spec.add_development_dependency 'rubocop'.freeze end % rubocop foo.gemspec --only Gemspec/OrderedDependencies -d For /private/tmp: configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/config/default.yml Inheriting configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/config/enabled.yml Inheriting configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/config/disabled.yml Inspecting 1 file Scanning /private/tmp/foo.gemspec An error occurred while Gemspec/OrderedDependencies cop was inspecting /private/tmp/foo.gemspec. undefined method `downcase' for nil:NilClass (snip) /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.58.0/exe/rubocop:12:in `<top (required)>' /Users/koic/.rbenv/versions/2.5.1/bin/rubocop:23:in `load' /Users/koic/.rbenv/versions/2.5.1/bin/rubocop:23:in `<main>' . 1 file inspected, no offenses detected 1 error occurred: An error occurred while Gemspec/OrderedDependencies cop was inspecting /private/tmp/foo.gemspec. Errors are usually caused by RuboCop bugs. Please, report your problems to RuboCop's issue tracker. https://github.com/rubocop-hq/rubocop/issues Mention the following information in the issue report: 0.58.0 (using Parser 2.5.1.0, running on ruby 2.5.1 x86_64-darwin17) Finished in 0.43951499997638166 seconds ``` This PR considers the case to be called in the method chain for the gem name as follows. ```ruby spec.add_development_dependency 'foo'.bar.baz ``` In this case, the gem name will be resolved searching recursively.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
Gemspec/OrderedDependencies
parses frozen gem names correctly.Actual behavior
The cop chokes when trying to call
downcase
after parsing a frozen gem name. The problem seems to come from this line of code sincestr_content
returnsnil
for a gem name that is explicitly frozen.Stack trace of the error:
Steps to reproduce the problem
Attempt to run Rubocop with a gemspec file like the following:
RuboCop version
The text was updated successfully, but these errors were encountered: