diff --git a/changelog/fix_error_for_style_documentation b/changelog/fix_error_for_style_documentation new file mode 100644 index 00000000000..edd6c887add --- /dev/null +++ b/changelog/fix_error_for_style_documentation @@ -0,0 +1 @@ +* [#10234](https://github.com/rubocop/rubocop/pull/10234): Fix an error for `Style/Documentation` when using a cbase class. ([@koic][]) diff --git a/lib/rubocop/cop/style/documentation.rb b/lib/rubocop/cop/style/documentation.rb index 3dd1567d865..1dd2fc7405d 100644 --- a/lib/rubocop/cop/style/documentation.rb +++ b/lib/rubocop/cop/style/documentation.rb @@ -176,7 +176,7 @@ def identifier(node) end def qualify_const(node) - return if node.nil? + return if node.nil? || node.cbase_type? [qualify_const(node.namespace), node.short_name].compact end diff --git a/spec/rubocop/cop/style/documentation_spec.rb b/spec/rubocop/cop/style/documentation_spec.rb index 2d8bc509b08..a8336d49c46 100644 --- a/spec/rubocop/cop/style/documentation_spec.rb +++ b/spec/rubocop/cop/style/documentation_spec.rb @@ -17,6 +17,16 @@ def method RUBY end + it 'registers an offense for non-empty cbase class' do + expect_offense(<<~RUBY) + class ::MyClass + ^^^^^^^^^^^^^^^ Missing top-level documentation comment for `class MyClass`. + def method + end + end + RUBY + end + it 'does not consider comment followed by empty line to be class documentation' do expect_offense(<<~RUBY) # Copyright 2014