Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false positive for Layout/EmptyLinesAroundAttributeAccessor #8150

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
* [#8124](https://github.com/rubocop-hq/rubocop/issues/8124): Fix a false positive for `Lint/FormatParameterMismatch` when using named parameters with escaped `%`. ([@koic][])
* [#7979](https://github.com/rubocop-hq/rubocop/issues/7979): Fix "uninitialized constant DidYouMean::SpellChecker" exception. ([@bquorning][])
* [#8098](https://github.com/rubocop-hq/rubocop/issues/8098): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using interpolations. ([@owst][])
* [#8150](https://github.com/rubocop-hq/rubocop/pull/8150): Fix a false positive for `Layout/EmptyLinesAroundAttributeAccessor` when using attribute accessors in `if` ... `else` branches. ([@koic][])

### Changes

Expand Down
Expand Up @@ -96,6 +96,8 @@ def require_empty_line?(node)
end

def next_line_node(node)
return if node.parent.if_type?

node.parent.children[node.sibling_index + 1]
end

Expand Down
Expand Up @@ -75,6 +75,16 @@ class Foo
RUBY
end

it 'does not registers an offense and corrects when using `if` ... `else` branches' do
expect_no_offenses(<<~RUBY)
if condition
attr_reader :foo
else
do_something
end
RUBY
end

context 'when `AllowAliasSyntax: true`' do
let(:cop_config) do
{ 'AllowAliasSyntax' => true }
Expand Down