diff --git a/CHANGELOG.md b/CHANGELOG.md index b57a4cbf043..46568f512b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [#7193](https://github.com/rubocop-hq/rubocop/issues/7193): Prevent `Style/PercentLiteralDelimiters` from changing `%i` literals that contain escaped delimiters. ([@buehmann][]) * [#7590](https://github.com/rubocop-hq/rubocop/issues/7590): Fix an error for `Layout/SpaceBeforeBlockBraces` when using with `EnforcedStyle: line_count_based` of `Style/BlockDelimiters` cop. ([@koic][]) * [#7569](https://github.com/rubocop-hq/rubocop/issues/7569): Make `Style/YodaCondition` accept `__FILE__ == $0`. ([@koic][]) +* [#7576](https://github.com/rubocop-hq/rubocop/issues/7576): Fix an error for `Gemspec/OrderedDependencies` when using a local variable in an argument of dependent gem. ([@koic][]) ## 0.78.0 (2019-12-18) diff --git a/lib/rubocop/cop/gemspec/ordered_dependencies.rb b/lib/rubocop/cop/gemspec/ordered_dependencies.rb index 9c5c50876c4..1d99019cf62 100644 --- a/lib/rubocop/cop/gemspec/ordered_dependencies.rb +++ b/lib/rubocop/cop/gemspec/ordered_dependencies.rb @@ -98,7 +98,7 @@ def get_dependency_name(node) end def_node_search :dependency_declarations, <<~PATTERN - (send (lvar _) {:add_dependency :add_runtime_dependency :add_development_dependency} ...) + (send (lvar _) {:add_dependency :add_runtime_dependency :add_development_dependency} (str _) ...) PATTERN end end diff --git a/spec/rubocop/cop/gemspec/ordered_dependencies_spec.rb b/spec/rubocop/cop/gemspec/ordered_dependencies_spec.rb index 085579fd136..027ee8cf5fc 100644 --- a/spec/rubocop/cop/gemspec/ordered_dependencies_spec.rb +++ b/spec/rubocop/cop/gemspec/ordered_dependencies_spec.rb @@ -198,4 +198,15 @@ RUBY end end + + context 'When using a local variable in an argument of dependent gem' do + it 'does not register any offenses' do + expect_no_offenses(<<~RUBY) + Gem::Specification.new do |spec| + %w(rubocop-performance rubocop-rails).each { |dep| spec.add_dependency dep } + spec.add_dependency 'parser' + end + RUBY + end + end end