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 #7576] Fix an error for Gemspec/OrderedDependencies #7585

Merged

Conversation

koic
Copy link
Member

@koic koic commented Dec 23, 2019

Fixes #7576.

This PR fixes the following error for Gemspec/OrderedDependencies when using a local variable in an argument of dependent gem.

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


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.

@koic koic force-pushed the fix_an_error_for_gemspec_ordered_dependencies branch 2 times, most recently from 2095196 to 6f3ec08 Compare December 25, 2019 14:09
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.
@koic koic force-pushed the fix_an_error_for_gemspec_ordered_dependencies branch from 6f3ec08 to 50d51fc Compare December 27, 2019 17:00
@bbatsov bbatsov merged commit af2d567 into rubocop:master Dec 28, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 28, 2019

Good fix! I think we should probably add some cop that discourages this practice, though, as gemspecs are much more readable when written in a purely declarative fashion.

@koic koic deleted the fix_an_error_for_gemspec_ordered_dependencies branch December 28, 2019 14:12
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.

An error occurred while Gemspec/OrderedDependencies cop was inspecting ops-ticket.gemspec
2 participants