Skip to content

Commit

Permalink
Merge pull request #11872 from Bhacaz/fix_development_dependencies_co…
Browse files Browse the repository at this point in the history
…p_with_arguments

Fix Gemspec/DevelopmentDependencies not trigger when add_development_…
  • Loading branch information
koic committed May 13, 2023
2 parents 7ef8629 + e768851 commit 824441b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11872](https://github.com/rubocop/rubocop/pull/11872): Fix `Gemspec/DevelopmentDependencies` not trigger when add_development_dependency has more then one arguments. ([@Bhacaz][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/gemspec/development_dependencies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? ...) _? _?)
PATTERN

# @!method gem?(node)
Expand Down
22 changes: 22 additions & 0 deletions spec/rubocop/cop/gemspec/development_dependencies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@
RUBY
end

it 'registers an offense when using `#add_development_dependency` in a gemspec a single version argument' do
expect_offense(<<~RUBY, 'example.gemspec', preferred_file: enforced_style)
Gem::Specification.new do |spec|
spec.name = 'example'
spec.add_development_dependency 'foo', '>= 1.0'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specify development dependencies in %{preferred_file}.
spec.add_development_dependency 'allowed', '>= 1.0'
end
RUBY
end

it 'registers an offense when using `#add_development_dependency` in a gemspec with two version' do
expect_offense(<<~RUBY, 'example.gemspec', preferred_file: enforced_style)
Gem::Specification.new do |spec|
spec.name = 'example'
spec.add_development_dependency 'foo', '>= 1.0', '< 2.0'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Specify development dependencies in %{preferred_file}.
spec.add_development_dependency 'allowed', '>= 1.0', '< 2.0'
end
RUBY
end

it 'registers no offenses when specifying dependencies in Gemfile' do
expect_no_offenses(<<~RUBY, 'Gemfile')
gem 'example'
Expand Down

0 comments on commit 824441b

Please sign in to comment.