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

AccessModifierIndentation and CommentIndentation does not work well together #11237

Closed
yskkin opened this issue Dec 6, 2022 · 0 comments · Fixed by #11343
Closed

AccessModifierIndentation and CommentIndentation does not work well together #11237

yskkin opened this issue Dec 6, 2022 · 0 comments · Fixed by #11343
Labels

Comments

@yskkin
Copy link

yskkin commented Dec 6, 2022

# rubocop: enable and # rubocop:disable may wrap whole method definition.
In such case, indentation should be based on wrapped method.


Expected behavior

No offenses.

Actual behavior

Having one offense.
We cannot suppress offense as long as comment is followed by access modifier.

rubocop -c test.rubocop.yml foo.rb
Inspecting 1 file
C

Offenses:

foo.rb:5:3: C: [Correctable] Layout/CommentIndentation: Incorrect indentation detected (column 2 instead of 0).
  # rubocop:enable
  ^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

Steps to reproduce the problem

Lint following file with the setting below:

foo.rb

class A
  # rubocop:disable
  def foo
  end
  # rubocop:enable

private

  def bar
  end
end

test.rubocop.yml

AllCops:
  DisabledByDefault: true

Layout/AccessModifierIndentation:
  Enabled: true
  EnforcedStyle: outdent

Layout/CommentIndentation:
  Enabled: true

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

1.39.0 (using Parser 3.1.3.0, rubocop-ast 1.24.0, running on ruby 2.7.6) [x86_64-darwin21]
  - rubocop-rails 2.15.1
  - rubocop-rspec 2.11.1
@koic koic added the bug label Dec 7, 2022
soroktree added a commit to soroktree/rubocop that referenced this issue Dec 28, 2022
…ith access modifier indentation when EnforcedStyle is outdent
koic added a commit that referenced this issue Dec 28, 2022
[Fix #11237] Fix `Layout/CommentIndentation` comment aligned with acc…
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.

2 participants