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

Layout/IndentationWidth conflicts with Layout/AccessModifierIndentation EnforcedStyle: outdent #6861

Closed
toy opened this issue Mar 25, 2019 · 3 comments · Fixed by #6866
Closed
Labels

Comments

@toy
Copy link
Contributor

toy commented Mar 25, 2019

Setting EnforcedStyle: outdent for Layout/AccessModifierIndentation causes conflict with Layout/IndentationWidth starting with rubocop 0.66.0.

Expected behavior

No error as there is no new cops relevant to the example file.
Running same commands using previous rubocop version rubocop _0.65.0_ and rubocop _0.65.0_ --auto-correct finishes successfully and without any corrections.

Actual behavior

Running rubocop reports an error, running rubocop --auto-correct reports two corrected errors then fails with message about infinite loop + backtrace.

Steps to reproduce the problem

Create file test.rb:

# frozen_string_literal: true

# Test Layout/IndentationWidth problem
class Test
private

  def test
    :test
  end
end

Create file .rubocop.yml:

Layout/AccessModifierIndentation:
  EnforcedStyle: outdent

Run rubocop:

Inspecting 1 file
C

Offenses:

test.rb:5:1: C: Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. (https://github.com/rubocop-hq/ruby-style-guide#spaces-indentation)
private


1 file inspected, 1 offense detected

Run rubocop --auto-correct:

Inspecting 1 file
C

Offenses:

test.rb:5:1: C: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation. (https://github.com/rubocop-hq/ruby-style-guide#spaces-indentation)
private

test.rb:5:3: C: [Corrected] Layout/AccessModifierIndentation: Outdent access modifiers like private. (https://github.com/rubocop-hq/ruby-style-guide#indent-public-private-protected)
  private
  ^^^^^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
Infinite loop detected in …/test.rb.
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:263:in `check_for_infinite_loop'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:246:in `block in iterate_until_no_changes'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:245:in `loop'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:245:in `iterate_until_no_changes'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:216:in `do_inspection_loop'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:119:in `block in file_offenses'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:137:in `file_offense_cache'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:117:in `file_offenses'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:105:in `process_file'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:82:in `block in each_inspected_file'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:81:in `each'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:81:in `reduce'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:81:in `each_inspected_file'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:73:in `inspect_files'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/runner.rb:39:in `run'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cli.rb:174:in `execute_runner'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cli.rb:75:in `execute_runners'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/lib/rubocop/cli.rb:47:in `run'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/exe/rubocop:13:in `block in <top (required)>'
…/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
…/lib/ruby/gems/2.5.0/gems/rubocop-0.66.0/exe/rubocop:12:in `<top (required)>'
…/bin/rubocop:23:in `load'
…/bin/rubocop:23:in `<main>'
…/bin/ruby_executable_hooks:15:in `eval'
…/bin/ruby_executable_hooks:15:in `<main>'

RuboCop version

0.66.0 (using Parser 2.6.2.0, running on ruby 2.5.3 x86_64-darwin18)

@koic
Copy link
Member

koic commented Mar 31, 2019

Thanks for the feedback. I opened a PR #6866.

toy added a commit to toy/fspath that referenced this issue Apr 19, 2019
toy added a commit to toy/progress that referenced this issue Apr 19, 2019
toy added a commit to toy/dump that referenced this issue Apr 19, 2019
@chucklor
Copy link

Any updates on this? I'm interested in having 4 spaces indent as well. I wonder if I can simply override it in the .rubocop.yml file. Thank you!

@mvastola
Copy link

Second this issue. Seems to only be a problem when the access modifier is the first line of code in the class/module.

koic added a commit to koic/rubocop that referenced this issue Jul 26, 2019
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.
jonas054 added a commit that referenced this issue Jul 27, 2019
…ntation_width

[Fix #6861] Fix a false positive for `Layout/IndentationWidth`
deivid-rodriguez added a commit to rubygems/bundler that referenced this issue Jul 31, 2019
And reenable exclusion because the bug why we added them has been fixed.
See rubocop/rubocop#6861.
matzbot pushed a commit to ruby/ruby that referenced this issue Aug 3, 2019
And reenable exclusion because the bug why we added them has been fixed.
See rubocop/rubocop#6861.

rubygems/bundler@bda63fcffc
tas50 added a commit to chef/cookstyle that referenced this issue Oct 30, 2019
This resolves a large number of warnings and gives us a new cop for
automatically migrating the namespace of the cop disables in comments

* [#7407](rubocop/rubocop#7407): Make `Style/FormatStringToken` work inside hashes. ([@buehmann][])
* [#7389](rubocop/rubocop#7389): Fix an issue where passing a formatter might result in an error depending on what character it started with. ([@jfhinchcliffe][])
* [#7397](rubocop/rubocop#7397): Fix extra comments being added to the correction of `Style/SafeNavigation`. ([@rrosenblum][])
* [#7378](rubocop/rubocop#7378): Fix heredoc edge cases in `Layout/EmptyLineAfterGuardClause`. ([@gsamokovarov][])
* [#7404](rubocop/rubocop#7404): Fix a false negative for `Layout/IndentAssignment` when multiple assignment with line breaks on each line. ([@koic][])
* [#7256](rubocop/rubocop#7256): Fix an error of `Style/RedundantParentheses` on method calls where the first argument begins with a hash literal. ([@halfwhole][])
* [#7263](rubocop/rubocop#7263): Make `Layout/SpaceInsideArrayLiteralBrackets` properly handle tab-indented arrays. ([@buehmann][])
* [#7252](rubocop/rubocop#7252): Prevent infinite loops by making `Layout/SpaceInsideStringInterpolation` skip over interpolations that start or end with a line break. ([@buehmann][])
* [#7262](rubocop/rubocop#7262): `Lint/FormatParameterMismatch` did not recognize named format sequences like `%.2<name>f` where the name appears after some modifiers. ([@buehmann][])
* [#7253](rubocop/rubocop#7253): Fix an error for `Lint/NumberConversion` when `#to_i` called without a receiver. ([@koic][])
* [#7271](rubocop/rubocop#7271), [#6498](rubocop/rubocop#6498): Fix an interference between `Style/TrailingCommaIn*Literal` and `Layout/Multiline*BraceLayout` for arrays and hashes. ([@buehmann][])
* [#7241](rubocop/rubocop#7241): Make `Style/FrozenStringLiteralComment` match only true & false. ([@tejasbubane][])
* [#7290](rubocop/rubocop#7290): Handle inner conditional inside `else` in `Style/ConditionalAssignment`. ([@jonas054][])
* [#5788](rubocop/rubocop#5788): Allow block arguments on separate lines if line would be too long in `Layout/MultilineBlockLayout`. ([@jonas054][])
* [#7305](rubocop/rubocop#7305): Register `Style/BlockDelimiters` offense when block result is assigned to an attribute. ([@mvz][])
* [#4802](rubocop/rubocop#4802): Don't leave any `Lint/UnneededCopEnableDirective` offenses undetected/uncorrected. ([@jonas054][])
* [#7326](rubocop/rubocop#7326): Fix a false positive for `Style/AccessModifierDeclarations` when access modifier name is used for hash literal value. ([@koic][])
* [#3591](rubocop/rubocop#3591): Handle modifier `if`/`unless` correctly in `Lint/UselessAssignment`. ([@jonas054][])
* [#7161](rubocop/rubocop#7161): Fix `Style/SafeNavigation` cop for preserve comments inside if expression. ([@tejasbubane][])
* [#5212](rubocop/rubocop#5212): Avoid false positive for braces that are needed to preserve semantics in `Style/BracesAroundHashParameters`. ([@jonas054][])
* [#7353](rubocop/rubocop#7353): Fix a false positive for `Style/RedundantSelf` when receiver and multiple assigned lvalue have the same name. ([@koic][])
* [#7353](rubocop/rubocop#7353): Fix a false positive for `Style/RedundantSelf` when a self receiver is used as a method argument. ([@koic][])
* [#7358](rubocop/rubocop#7358): Fix an incorrect autocorrect for `Style/NestedModifier` when parentheses are required in method arguments. ([@koic][])
* [#7361](rubocop/rubocop#7361): Fix a false positive for `Style/TernaryParentheses` when only the closing parenthesis is used in the last line of condition. ([@koic][])
* [#7369](rubocop/rubocop#7369): Fix an infinite loop error for `Layout/IndentAssignment` with `Layout/IndentFirstArgument` when using multiple assignment. ([@koic][])
* [#7177](rubocop/rubocop#7177), [#7370](rubocop/rubocop#7370): When correcting alignment, do not insert spaces into string literals. ([@buehmann][])
* [#7367](rubocop/rubocop#7367): Fix an error for `Style/OrAssignment` cop when `then` branch body is empty. ([@koic][])
* [#7363](rubocop/rubocop#7363): Fix an incorrect autocorrect for `Layout/SpaceInsideBlockBraces` and `Style/BlockDelimiters` when using multiline empty braces. ([@koic][])
* [#7212](rubocop/rubocop#7212): Fix a false positive for `Layout/EmptyLinesAroundAccessModifier` and `UselessAccessModifier` when using method with the same name as access modifier around a method definition. ([@koic][])
* [#7217](rubocop/rubocop#7217): Make `Style/TrailingMethodEndStatement` work on more than the first `def`. ([@buehmann][])
* [#7190](rubocop/rubocop#7190): Support lower case drive letters on Windows. ([@jonas054][])
* Fix the auto-correction of `Lint/UnneededSplatExpansion` when the splat expansion of `Array.new` with a block is assigned to a variable. ([@rrosenblum][])
* [#5628](rubocop/rubocop#5628): Fix an error of `Layout/SpaceInsideStringInterpolation` on interpolations with multiple statements. ([@buehmann][])
* [#7128](rubocop/rubocop#7128): Make `Metrics/LineLength` aware of shebang. ([@koic][])
* [#6861](rubocop/rubocop#6861): Fix a false positive for `Layout/IndentationWidth` when using `EnforcedStyle: outdent` of `Layout/AccessModifierIndentation`. ([@koic][])
* [#7235](rubocop/rubocop#7235): Fix an error where `Style/ConditionalAssignment` would swallow a nested `if` condition. ([@buehmann][])
* [#7242](rubocop/rubocop#7242): Make `Style/ConstantVisibility` work on non-trivial class and module bodies. ([@buehmann][])
* [#5265](rubocop/rubocop#5265): Improved `Layout/ExtraSpacing` cop to handle nested consecutive assignments. ([@jfelchner][])
* [#7215](rubocop/rubocop#7215): Make it clear what's wrong in the message from `Style/GuardClause`. ([@jonas054][])
* [#7245](rubocop/rubocop#7245): Make cops detect string interpolations in more contexts: inside of backticks, regular expressions, and symbols. ([@buehmann][])
 [#7275](rubocop/rubocop#7275): Make `Style/VariableName` aware argument names when invoking a method. ([@koic][])
* [#3534](rubocop/rubocop#3534): Make `Style/IfUnlessModifier` report and auto-correct modifier lines that are too long. ([@jonas054][])
* [#7261](rubocop/rubocop#7261): `Style/FrozenStringLiteralComment` no longer inserts an empty line after the comment. This is left to `Layout/EmptyLineAfterMagicComment`. ([@buehmann][])
* [#7091](rubocop/rubocop#7091): `Style/FormatStringToken` now detects format sequences with flags and modifiers. ([@buehmann][])
* [#7319](rubocop/rubocop#7319): Rename `IgnoredMethodPatterns` option to `IgnoredPatterns` option for `Style/MethodCallWithArgsParentheses`. ([@koic][])
* [#7345](rubocop/rubocop#7345): Mark unsafe for `Style/YodaCondition`. ([@koic][])
* [#7170](rubocop/rubocop#7170): Fix a false positive for `Layout/RescueEnsureAlignment` when def line is preceded with `private_class_method`. ([@tatsuyafw][])
* [#7186](rubocop/rubocop#7186): Fix a false positive for `Style/MixinUsage` when using inside multiline block and `if` condition is after `include`. ([@koic][])
* [#7099](rubocop/rubocop#7099): Fix an error of `Layout/RescueEnsureAlignment` on assigned blocks. ([@tatsuyafw][])
* [#5088](rubocop/rubocop#5088): Fix an error of `Layout/MultilineMethodCallIndentation` on method chains inside an argument. ([@buehmann][])
* [#4719](rubocop/rubocop#4719): Make `Layout/Tab` detect tabs between string literals. ([@buehmann][])
* [#7203](rubocop/rubocop#7203): Fix an infinite loop error for `Layout/SpaceInsideBlockBraces` when `EnforcedStyle: no_space` with `SpaceBeforeBlockParameters: false` are set in multiline block. ([@koic][])
* [#6653](rubocop/rubocop#6653): Fix a bug where `Layout/IndentHeredoc` would remove empty lines when autocorrecting heredocs. ([@buehmann][])
* [#7188](rubocop/rubocop#7188): Include inspected file location in auto-correction error. ([@pocke][])

Signed-off-by: Tim Smith <tsmith@chef.io>
ghost pushed a commit to rubygems/rubygems that referenced this issue Mar 11, 2020
And reenable exclusion because the bug why we added them has been fixed.
See rubocop/rubocop#6861.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants