Skip to content

Commit

Permalink
Merge pull request #11587 from fatkodima/documentation_method-ruby2_k…
Browse files Browse the repository at this point in the history
…eywords

Handle `ruby2_keywords` in `Style/DocumentationMethod` cop
  • Loading branch information
koic committed Feb 17, 2023
2 parents b42d46e + fb8e518 commit b46b9b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11586](https://github.com/rubocop/rubocop/issues/11586): Handle `ruby2_keywords` in `Style/DocumentationMethod` cop. ([@fatkodima][])
8 changes: 4 additions & 4 deletions lib/rubocop/cop/style/documentation_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ class DocumentationMethod < Base

MSG = 'Missing method documentation comment.'

# @!method module_function_node?(node)
def_node_matcher :module_function_node?, <<~PATTERN
(send nil? :module_function ...)
# @!method modifier_node?(node)
def_node_matcher :modifier_node?, <<~PATTERN
(send nil? {:module_function :ruby2_keywords} ...)
PATTERN

def on_def(node)
return if node.method?(:initialize)

parent = node.parent
module_function_node?(parent) ? check(parent) : check(node)
modifier_node?(parent) ? check(parent) : check(node)
end
alias on_defs on_def

Expand Down
20 changes: 20 additions & 0 deletions spec/rubocop/cop/style/documentation_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,16 @@ def bar
RUBY
end
end

it 'registers an offense for inline def with ruby2_keywords' do
expect_offense(<<~RUBY)
module Foo
ruby2_keywords def bar
^^^^^^^^^^^^^^^^^^^^^^ Missing method documentation comment.
end
end
RUBY
end
end

context 'with documentation comment' do
Expand Down Expand Up @@ -665,6 +675,16 @@ def bar; end
RUBY
end
end

it 'does not register an offense for inline def with ruby2_keywords' do
expect_no_offenses(<<~RUBY)
module Foo
# Documentation
ruby2_keywords def bar
end
end
RUBY
end
end

context 'with both public and private methods' do
Expand Down

0 comments on commit b46b9b5

Please sign in to comment.