Skip to content

Commit

Permalink
Merge pull request #8660 from koic/fix_a_false_positive_for_class_and…
Browse files Browse the repository at this point in the history
…_module_children

Fix a false positive for `Style/ClassAndModuleChildren`
  • Loading branch information
koic committed Sep 7, 2020
2 parents 79ee786 + 0408e2a commit 79b43f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
* [#8653](https://github.com/rubocop-hq/rubocop/pull/8653): Fix a false positive for `Layout/DefEndAlignment` when using refinements and `private def`. ([@koic][])
* [#8655](https://github.com/rubocop-hq/rubocop/pull/8655): Fix a false positive for `Style/ClassAndModuleChildren` when using cbase class name. ([@koic][])
* [#8654](https://github.com/rubocop-hq/rubocop/pull/8654): Fix a false positive for `Style/SafeNavigation` when checking `foo&.empty?` in a conditional. ([@koic][])
* [#8660](https://github.com/rubocop-hq/rubocop/pull/8660): Fix a false positive for `Style/ClassAndModuleChildren` when using cbase module name. ([@koic][])

### Changes

Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/class_and_module_children.rb
Expand Up @@ -32,7 +32,6 @@ class ClassAndModuleChildren < Base
'nested style.'

def on_class(node)
return if node.identifier.children[0]&.cbase_type?
return if node.parent_class && style != :nested

check_style(node, node.body)
Expand Down Expand Up @@ -113,6 +112,8 @@ def indent_width
end

def check_style(node, body)
return if node.identifier.children[0]&.cbase_type?

if style == :nested
check_nested_style(node)
else
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/style/class_and_module_children_spec.rb
Expand Up @@ -67,6 +67,13 @@ class ::Foo
RUBY
end

it 'accepts cbase module name' do
expect_no_offenses(<<~RUBY)
module ::Foo
end
RUBY
end

it 'accepts :: in parent class on inheritance' do
expect_no_offenses(<<~RUBY)
class FooClass
Expand Down

0 comments on commit 79b43f7

Please sign in to comment.