Skip to content

Commit

Permalink
[Fix #8424] Fix an error for Lint/IneffectiveAccessModifier
Browse files Browse the repository at this point in the history
Fixes #8424.

This PR fixes an error for `Lint/IneffectiveAccessModifier`
when there is `begin...end` before a method definition.
  • Loading branch information
koic committed Jul 31, 2020
1 parent cad8d8a commit 304a464
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* [#8330](https://github.com/rubocop-hq/rubocop/issues/8330): Fix a false positive for `Style/MissingRespondToMissing` when defined method with inline access modifier. ([@koic][])
* [#8422](https://github.com/rubocop-hq/rubocop/issues/8422): Fix an error for `Lint/SelfAssignment` when using or-assignment for constant. ([@koic][])
* [#8423](https://github.com/rubocop-hq/rubocop/issues/8423): Fix an error for `Style/SingleArgumentDig` when without a receiver. ([@koic][])
* [#8424](https://github.com/rubocop-hq/rubocop/issues/8424): Fix an error for `Lint/IneffectiveAccessModifier` when there is `begin...end` before a method definition. ([@koic][])

### Changes

Expand Down
4 changes: 1 addition & 3 deletions lib/rubocop/cop/lint/ineffective_access_modifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ def format_message(modifier)
end

# rubocop:disable Metrics/CyclomaticComplexity
def ineffective_modifier(node, modifier = nil, &block)
ignored_methods = nil

def ineffective_modifier(node, ignored_methods = nil, modifier = nil, &block)
node.each_child_node do |child|
case child.type
when :send
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/lint/ineffective_access_modifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,18 @@ def self.method
RUBY
end
end

context 'when there is `begin` before a method definition' do
it 'does not register an offense' do
expect_no_offenses(<<~RUBY)
class C
begin
end
def do_something
end
end
RUBY
end
end
end

0 comments on commit 304a464

Please sign in to comment.