-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #6861] Fix a false positive for Layout/IndentationWidth
#6866
[Fix #6861] Fix a false positive for Layout/IndentationWidth
#6866
Conversation
|
||
check_indentation(base, member) | ||
end | ||
check_members_for_non_rails_style(base, members) |
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 extracted to the method because it was warned by Metrics
cops.
Hi @koic, # example.rb
class Foo
private
def do_something
# something
end
end Auto-correction changes it to # example.rb
class Foo
private
def do_something
# something
end
end |
@jonas054 Sure! I was not aware of this problem 💦 I'll look it up. Thanks for your checking. |
Hello @koic! Thanks for working on this, do you still plan to wrap this up? |
Wanted to second merging this PR once the remaining issues are fixed. If it helps, this only seems to be a problem if the access modifier is the first line of code in the class/module. So maybe the issue with autocorrect could be fixed by limiting changes to the first line of code in this case? |
@koic What's the state here? |
26f8733
to
778c557
Compare
Sorry I'm late. I updated this PR and added the following mentioned issue as a test. |
0661cc6
to
fe3ea26
Compare
Fixes rubocop#6861. This is a regression by rubocop#6792. This PR fixes infinite loop for `Layout/IndentationWidth` cop and `Layout/AccessModifierIndentation` cop. ```ruby # exmaple.rb class Foo private def do_something end end ``` ```yaml # .rubocop.yml % cat .rubocop.yml Layout/AccessModifierIndentation: EnforcedStyle: outdent ``` First, auto-corrected by `Layout/IndentationWidth`. ```console % rubocop -v 0.66.0 % rubocop -a --only Layout/IndentationWidth Inspecting 1 file C Offenses: example.rb:2:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. private 1 file inspected, 1 offense detected, 1 offense corrected ``` ```diff % git diff example.rb diff --git a/example.rb b/example.rb index 063e6a5..081b80a 100644 --- a/example.rb +++ b/example.rb @@ -1,5 +1,5 @@ class Foo -private + private def do_something end ``` Next, auto-corrected by `Layout/Layout/AccessModifierIndentation` (`EnforcedStyle: outdent`). ```console % rubocop -a --only Layout/AccessModifierIndentation Inspecting 1 file C Offenses: example.rb:2:3: C: [Corrected] Layout/AccessModifierIndentation: Outdent access modifiers like private. private ^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected ``` This will return to the original code. ```diff % git diff diff --git a/example.rb b/example.rb index 081b80a..063e6a5 100644 --- a/example.rb +++ b/example.rb @@ -1,5 +1,5 @@ class Foo - private +private def do_something end ``` That caused the infinite loop in `Layout/IndentationWidth` and `Layout/AccessModifierIndentation` (`EnforcedStyle: outdent`). With this PR, `Layout/indentationWidth` cop makes aware of `Layout/AccessModifierIndentation` cop.
fe3ea26
to
20d76ec
Compare
Thanks for fixing this @koic!! ❤️ |
Fixes #6861.
This is a regression by #6792.
This PR fixes infinite loop for
Layout/IndentationWidth
cop andLayout/AccessModifierIndentation
cop.First, auto-corrected by
Layout/IndentationWidth
.Next, auto-corrected by
Layout/Layout/AccessModifierIndentation
(EnforcedStyle: outdent
).This will return to the original code.
That caused the infinite loop in
Layout/IndentationWidth
andLayout/AccessModifierIndentation
(EnforcedStyle: outdent
).With this PR,
Layout/indentationWidth
cop makes aware ofLayout/AccessModifierIndentation
cop.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.