-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 #11237] Fix Layout/CommentIndentation
comment aligned with acc…
#11343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#11237](https://github.com/rubocop/rubocop/issues/11237): Fix `Layout/CommentIndentation` comment aligned with access modifier indentation when EnforcedStyle is outdent. ([@soroktree][]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,4 +292,55 @@ def compile_sequence(seq, seq_var) | |
RUBY | ||
end | ||
end | ||
|
||
context 'when `Layout/AccessModifierIndentation EnforcedStyle: outdent`' do | ||
let(:allow_for_alignment) { true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this is not needed, because you redefine |
||
let(:indentation_width) { 2 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest removing this line (and from the top of the file) and inlining its value into the call, because it is never changed in the test file. |
||
let(:config) do | ||
RuboCop::Config.new( | ||
'Layout/AccessModifierIndentation' => { | ||
'Enabled' => true, | ||
'EnforcedStyle' => 'outdent' | ||
}, | ||
'Layout/CommentIndentation' => { | ||
'Enabled' => true | ||
}, | ||
'Layout/IndentationWidth' => { | ||
'Width' => indentation_width | ||
} | ||
) | ||
end | ||
|
||
it 'does not register an offense with indentation if aligned with code on previous line' do | ||
expect_no_offenses(<<~RUBY) | ||
class A | ||
# rubocop:disable | ||
def foo | ||
end | ||
# rubocop:enable | ||
|
||
private | ||
|
||
def bar | ||
end | ||
end | ||
RUBY | ||
end | ||
|
||
it 'registers an offense with indentation if aligned with access modifier on next line' do | ||
expect_offense(<<~RUBY) | ||
class A | ||
# rubocop:disable | ||
def foo | ||
end | ||
# rubocop:enable | ||
^^^^^^^^^^^^^^^^ Incorrect indentation detected (column 0 instead of 2). | ||
private | ||
|
||
def bar | ||
end | ||
end | ||
RUBY | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to extract
/\A\s*(#{access_modifier})\b/
into a constant or inlineaccess_modifier
into it, because this method call will always generate unnecessary allocations (needs measuring to know the impact).