diff --git a/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb b/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb index dcf36b49c521..f1956529a762 100644 --- a/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +++ b/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb @@ -97,7 +97,7 @@ def formatted_message(directive, actual_name, method_name) def insert_directive(corrector, node, actual_name) # If the pattern matcher uses arguments (`%1`, `%2`, etc.), include them in the directive - arguments = pattern_arguments(node.arguments[1].value) + arguments = pattern_arguments(node.arguments[1].source) range = range_with_surrounding_space( range: node.loc.expression, diff --git a/spec/rubocop/cop/internal_affairs/node_matcher_directive_spec.rb b/spec/rubocop/cop/internal_affairs/node_matcher_directive_spec.rb index 2f4d7fafd7c5..6db361b25a5f 100644 --- a/spec/rubocop/cop/internal_affairs/node_matcher_directive_spec.rb +++ b/spec/rubocop/cop/internal_affairs/node_matcher_directive_spec.rb @@ -29,6 +29,18 @@ RUBY end + it 'registers an offense if the matcher does not have a directive and a method call is used for a pattern argument' do + expect_offense(<<~RUBY, method: method) + #{method} :foo?, format(PATTERN, type: 'const') + ^{method}^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Preceed `#{method}` with a `@!method` YARD directive. + RUBY + + expect_correction(<<~RUBY) + # @!method foo?(node) + #{method} :foo?, format(PATTERN, type: 'const') + RUBY + end + it 'registers an offense if the matcher does not have a directive but has preceeding comments' do expect_offense(<<~RUBY, method: method) # foo