Skip to content

Commit

Permalink
Fix an error for Style/Documentation
Browse files Browse the repository at this point in the history
This PR fixes the following error for `Style/Documentation` when using a cbase class.

```ruby
% cat example.rb
class ::MyClass
  def method
  end
end
```

```console
% bundle exec rubocop --only Style/Documentation -d
(snip)

An error occurred while Style/Documentation cop was inspecting
/Users/koic/src/github.com/koic/rubocop-issues/bar/example.rb:1:0.
undefined method `namespace' for s(:cbase):RuboCop::AST::Node
/Users/koic/src/github.com/rubocop/rubocop/lib/rubocop/cop/style/documentation.rb:181:in `qualify_const'
```
  • Loading branch information
koic authored and bbatsov committed Nov 4, 2021
1 parent 51bac9d commit df440de
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions 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][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/documentation.rb
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/style/documentation_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit df440de

Please sign in to comment.