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
An error occurred while Gemspec/OrderedDependencies cop was inspecting ops-ticket.gemspec #7576
Comments
@sai-singh If possible can you share the gemspec file (or parts of it)? If not are you sure the gemspec format is correct? I was able to reproduce this issue by removing the dependency name. eg: s.add_runtime_dependency # no gem name But this is invalid gemspec & bundle command will throw error as expected. |
frozen_string_literal: truerequire_relative 'lib/xyz/version' Gem::Specification.new do |s| |
Fixes rubocop#7576. This PR fixes the following error for `Gemspec/OrderedDependencies` when using a local variable in an argument of dependent gem. ```console % cat example.gemspec Gem::Specification.new do |s| %w[foo bar].each { |dep| s.add_dependency dep } s.add_dependency 'baz' end % rubocop --only Gemspec/OrderedDependencies example.gemspec -d (nsip) An error occurred while Gemspec/OrderedDependencies cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/7576/example.gemspec. undefined method `str_type?' for nil:NilClass ``` Since it is difficult to trace variables and list gem names, this PR will skip them. And `add_dependency`, `add_runtime_dependency`, and `add_development_dependency` accept a symbol. e.g. `add_dependency(:foo)` The original implementation raises the same error if a symbol is passed as an argument. This PR also solves that problem. The issue for `add_dependency` and` abc` to accept symbols will open as separate a PR.
Fixes #7576. This PR fixes the following error for `Gemspec/OrderedDependencies` when using a local variable in an argument of dependent gem. ```console % cat example.gemspec Gem::Specification.new do |s| %w[foo bar].each { |dep| s.add_dependency dep } s.add_dependency 'baz' end % rubocop --only Gemspec/OrderedDependencies example.gemspec -d (nsip) An error occurred while Gemspec/OrderedDependencies cop was inspecting /Users/koic/src/github.com/koic/rubocop-issues/7576/example.gemspec. undefined method `str_type?' for nil:NilClass ``` Since it is difficult to trace variables and list gem names, this PR will skip them. And `add_dependency`, `add_runtime_dependency`, and `add_development_dependency` accept a symbol. e.g. `add_dependency(:foo)` The original implementation raises the same error if a symbol is passed as an argument. This PR also solves that problem. The issue for `add_dependency` and` abc` to accept symbols will open as separate a PR.
Expected behavior
21 files inspected, no offenses detected
I expect Rubocop not to fail and just report offense.
1 error occurred:
An error occurred while Gemspec/OrderedDependencies cop was inspecting
ops-ticket.gemspec
Actual behavior
Rubocop fails with the following backtrace:
undefined method
str_type?' for nil:NilClass /lib/rubocop/cop/mixin/ordered_gem_node.rb:46:in
find_gem_name'/.rvm/gems/ruby-2.5.7/gems/rubocop-0.76.0/lib/rubocop/cop/mixin/ordered_gem_node.rb:48:in
find_gem_name' /.rvm/gems/ruby-2.5.7/gems/rubocop-0.76.0/lib/rubocop/cop/mixin/ordered_gem_node.rb:42:in
gem_name'/.rvm/gems/ruby-2.5.7/gems/rubocop-
/lib/rubocop/cop/gemspec/ordered_dependencies.rb:69:in
block in investigate' /.rvm/gems/ruby-2.5.7/gems/rubocop- /lib/rubocop/cop/gemspec/ordered_dependencies.rb:112:in
block in dependency_declarations'/lib/rubocop/ast/node.rb:562:in
block in visit_descendants' /lib/rubocop/ast/node.rb:193:in
block in each_child_node'/lib/rubocop/ast/node.rb:190:in
each' /lib/rubocop/ast/node.rb:190:in
each_child_node'/lib/rubocop/ast/node.rb:561:in
visit_descendants' /lib/rubocop/ast/node.rb:563:in
block in visit_descendants'/lib/rubocop/ast/node.rb:193:in
block in each_child_node' /lib/rubocop/ast/node.rb:190:in
each'/lib/rubocop/ast/node.rb:190:in
each_child_node' /lib/rubocop/ast/node.rb:561:in
visit_descendants'/lib/rubocop/ast/node.rb:563:in
block in visit_descendants' lib/rubocop/ast/node.rb:193:in
block in each_child_node'/lib/rubocop/ast/node.rb:190:in
each' /lib/rubocop/ast/node.rb:190:in
each_child_node'/lib/rubocop/ast/node.rb:561:in
visit_descendants' /lib/rubocop/ast/node.rb:268:in
each_node'/.rvm/gems/ruby-2.5.7/gems/rubocop-
/lib/rubocop/cop/gemspec/ordered_dependencies.rb:102:in
dependency_declarations' /.rvm/gems/ruby-2.5.7/gems/rubocop- /lib/rubocop/cop/gemspec/ordered_dependencies.rb:65:in
each'/.rvm/gems/ruby-2.5.7/gems/rubocop-
/lib/rubocop/cop/gemspec/ordered_dependencies.rb:65:in
each_cons' /.rvm/gems/ruby-2.5.7/gems/rubocop- /lib/rubocop/cop/gemspec/ordered_dependencies.rb:65:in
investigate'/.rvm/gems/ruby-2.5.7/gems/rubocop-
/lib/rubocop/cop/commissioner.rb:108:in
block (2 levels) in invoke_custom_processing' /.rvm/gems/ruby-2.5.7/gems/rubocop- /lib/rubocop/cop/commissioner.rb:136:in
with_cop_error_handling'/.rvm/gems/ruby-2.5.7/gems/rubocop-
/lib/rubocop/cop/commissioner.rb:107:in
block in invoke_custom_processing' /.rvm/gems/ruby-2.5.7/gems/rubocop- /lib/rubocop/cop/commissioner.rb:104:in
each'/Users/sidsingh/.rvm/gems/ruby-2.5.7/gems/rubocop-
/lib/rubocop/cop/commissioner.rb:104:in
invoke_custom_processing' /lib/rubocop/cop/commissioner.rb:42:in
investigate'/lib/rubocop/cop/team.rb:119:in
investigate' /lib/rubocop/cop/team.rb:107:in
offenses'/lib/rubocop/cop/team.rb:44:in
inspect_file' /lib/rubocop/runner.rb:290:in
inspect_file'/lib/rubocop/runner.rb:238:in
block in do_inspection_loop' /lib/rubocop/runner.rb:270:in
block in iterate_until_no_changes'/lib/rubocop/runner.rb:263:in
loop' /lib/rubocop/runner.rb:263:in
iterate_until_no_changes'/lib/rubocop/runner.rb:234:in
do_inspection_loop' /lib/rubocop/runner.rb:119:in
block in file_offenses'/lib/rubocop/runner.rb:137:in
file_offense_cache' /lib/rubocop/runner.rb:117:in
file_offenses'/lib/rubocop/runner.rb:108:in
process_file' /lib/rubocop/runner.rb:87:in
block in each_inspected_file'/lib/rubocop/runner.rb:86:in
each' /lib/rubocop/runner.rb:86:in
reduce'/lib/rubocop/runner.rb:86:in
each_inspected_file' /lib/rubocop/runner.rb:73:in
inspect_files'/lib/rubocop/runner.rb:39:in
run' /lib/rubocop/cli.rb:213:in
execute_runner'/lib/rubocop/cli.rb:80:in
execute_runners' /lib/rubocop/cli.rb:51:in
run'/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
Steps to reproduce the problem
still trying to reproduce.
RuboCop version
0.76.0 (using Parser 2.6.5.0, running on ruby 2.5.7 x86_64-darwin17)
The text was updated successfully, but these errors were encountered: