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 Layout/CommentIndentation for comment-only pattern matching #12882

Merged
merged 1 commit into from
May 3, 2024

Conversation

nekketsuuu
Copy link
Contributor

@nekketsuuu nekketsuuu commented May 3, 2024

I'd like to allow the following code which uses pattern matching:

case instruction
in :nop
  # do nothing
in :inc
  ret += 1
end

Before this patch, the indentation of "do nothing" comment is corrected to the same indent level as that of in, which is inconsistent with the indentation rule of case ... when ... end.

$ ruby --version
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
$ bundle show rubocop
/home/nek/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/rubocop-1.63.4
$ cat test.rb
case instruction
in :nop
  # do nothing
in :inc
  ret += 1
end
$ bundle exec rubocop test.rb --only Layout/CommentIndentation
Inspecting 1 file
C

Offenses:

test.rb:3:3: C: [Correctable] Layout/CommentIndentation: Incorrect indentation detected (column 2 instead of 0).
  # do nothing
  ^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense autocorrectable

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
    • No related issues
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

I'd like to allow the following code which uses pattern matching:

```ruby
case instruction
in :nop
  # do nothing
in :inc
  ret += 1
end
```

Before this patch, the indentation of "do nothing" comment is
corrected to the same indent level as that of `in`,
which is inconsistent with the indentation rule of `case ... when ... end`.
@nekketsuuu nekketsuuu marked this pull request as ready for review May 3, 2024 15:31
@koic koic merged commit 7f9595a into rubocop:master May 3, 2024
33 checks passed
@koic
Copy link
Member

koic commented May 3, 2024

Thanks!

@nekketsuuu nekketsuuu deleted the nekketsuuu-case-in-comment branch May 3, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants