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

An error occurred while Gemspec/OrderedDependencies cop was inspecting ops-ticket.gemspec #7576

Closed
sai-singh opened this issue Dec 19, 2019 · 2 comments · Fixed by #7585
Closed
Labels

Comments

@sai-singh
Copy link

sai-singh commented Dec 19, 2019

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)

@tejasbubane
Copy link
Contributor

@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.

@sai-singh
Copy link
Author

@tejasbubane

frozen_string_literal: true

require_relative 'lib/xyz/version'

Gem::Specification.new do |s|
s.name = 'xyz'
s.version = xyz::VERSION
s.date = Time.now.strftime('%Y-%m-%d')
s.author = 'abc'
s.email = 'efg'
s.homepage = 'ijk'
s.summary = 'mno'
s.description = 'qrs'
s.require_paths = %w[lib bin]
s.bindir = 'bin'
s.files = git ls-files -z.split("\x0")
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
%w[typhoeus oauth highline json aq].each { |dep| s.add_dependency dep }
s.add_dependency 'zendesk_api', '1.14.0'
s.add_dependency 'hashie', '< 3.5'
end

@sai-singh sai-singh reopened this Dec 20, 2019
@koic koic added the bug label Dec 23, 2019
koic added a commit to koic/rubocop that referenced this issue Dec 27, 2019
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.
bbatsov pushed a commit that referenced this issue Dec 28, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants