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 Gemspec/DevelopmentDependencies not trigger when add_development_… #11872

Merged

Conversation

Bhacaz
Copy link
Contributor

@Bhacaz Bhacaz commented May 12, 2023

…dependency has more then one arguments

I was wondering why this cop was not triggered in my gemspec, to finally found that, the node matcher didn't match if an argument (or more) is passed.

# triggered 
spec.add_development_dependency 'foo'

# not triggered
spec.add_development_dependency 'foo', '>= 1.0'

There was a comment in the PR that introduce this cop which had no response and I didn't found any related issues about this behaviour.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@Bhacaz Bhacaz force-pushed the fix_development_dependencies_cop_with_arguments branch from c857f1c to 46a1573 Compare May 12, 2023 12:46
@Bhacaz Bhacaz marked this pull request as ready for review May 12, 2023 12:57
@@ -23,6 +23,28 @@
RUBY
end

it 'registers an offense when using `#add_development_dependency` in a gemspec with version' do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it 'registers an offense when using `#add_development_dependency` in a gemspec with version' do
it 'registers an offense when using `#add_development_dependency` in a gemspec with a single version argument' do

RUBY
end

it 'registers an offense when using `#add_development_dependency` in a gemspec with many arguments' do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it 'registers an offense when using `#add_development_dependency` in a gemspec with many arguments' do
it 'registers an offense when using `#add_development_dependency` in a gemspec with two version arguments' do

@@ -75,7 +75,7 @@ class DevelopmentDependencies < Base

# @!method add_development_dependency?(node)
def_node_matcher :add_development_dependency?, <<~PATTERN
(send _ :add_development_dependency (str #forbidden_gem? ...))
(send _ :add_development_dependency (str #forbidden_gem? ...) (...)*)
Copy link
Member

Choose a reason for hiding this comment

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

Is there ever a need for more than two arguments for the version? If not, wouldn't the following matcher suffice?

Suggested change
(send _ :add_development_dependency (str #forbidden_gem? ...) (...)*)
(send _ :add_development_dependency (str #forbidden_gem? ...) _? _?)

@Bhacaz Bhacaz force-pushed the fix_development_dependencies_cop_with_arguments branch from 46a1573 to e768851 Compare May 12, 2023 17:27
@Bhacaz Bhacaz requested a review from koic May 12, 2023 18:35
@koic koic merged commit 824441b into rubocop:master May 13, 2023
28 checks passed
@koic
Copy link
Member

koic commented May 13, 2023

Thanks!

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.

None yet

2 participants