Skip to content

Commit

Permalink
Merge pull request #8542 from tejasbubane/fix-8518
Browse files Browse the repository at this point in the history
[Fix #8518] Fix `Lint/ConstantResolution` cop reporting offense for `module` and `class` definitions
  • Loading branch information
koic committed Aug 19, 2020
2 parents 57d647d + ed0f187 commit 75365cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -18,6 +18,7 @@
* [#8507](https://github.com/rubocop-hq/rubocop/issues/8507): Fix `Style/RescueModifier` to handle parentheses around rescue modifiers. ([@dsavochkin][])
* [#8527](https://github.com/rubocop-hq/rubocop/pull/8527): Prevent an incorrect auto-correction for `Style/CaseEquality` cop when comparing with `===` against a regular expression receiver. ([@koic][])
* [#8524](https://github.com/rubocop-hq/rubocop/issues/8524): Fix `Layout/EmptyLinesAroundClassBody` and `Layout/EmptyLinesAroundModuleBody` to correctly handle an access modifier as a first child. ([@dsavochkin][])
* [#8518](https://github.com/rubocop-hq/rubocop/issues/8518): Fix `Lint/ConstantResolution` cop reporting offense for `module` and `class` definitions. ([@tejasbubane][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/constant_resolution.rb
Expand Up @@ -63,7 +63,7 @@ class ConstantResolution < Base
PATTERN

def on_const(node)
return unless unqualified_const?(node)
return if !unqualified_const?(node) || node.parent&.defined_module

add_offense(node)
end
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/lint/constant_resolution_spec.rb
Expand Up @@ -27,6 +27,15 @@
RUBY
end

context 'module & class definitions' do
it 'does not register offense' do
expect_no_offenses(<<~RUBY)
module Foo; end
class Bar; end
RUBY
end
end

context 'with Only set' do
let(:cop_config) { { 'Only' => ['MY_CONST'] } }

Expand Down

0 comments on commit 75365cd

Please sign in to comment.