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 #11237] Fix Layout/CommentIndentation comment aligned with acc… #11343

Merged
merged 1 commit into from Dec 28, 2022

Conversation

soroktree
Copy link
Contributor

[Fixed #11237]


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).
  • 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.

@koic
Copy link
Member

koic commented Dec 28, 2022

Can you add a changelog entry?

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.

@koic
Copy link
Member

koic commented Dec 28, 2022

This looks good to me. Can you squash your commits into one?

…ith access modifier indentation when EnforcedStyle is outdent
@soroktree
Copy link
Contributor Author

done. thanks for quick review

@koic koic merged commit fb6ac44 into rubocop:master Dec 28, 2022
@koic
Copy link
Member

koic commented Dec 28, 2022

Thanks!

/^\s*(end\b|[)}\]])/.match?(line)
rule = config.for_cop('Layout/AccessModifierIndentation')['EnforcedStyle'] == 'outdent'
access_modifier = 'private|protected|public'
/\A\s*(end\b|[)}\]])/.match?(line) || (rule && /\A\s*(#{access_modifier})\b/.match?(line))
Copy link
Contributor

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 inline access_modifier into it, because this method call will always generate unnecessary allocations (needs measuring to know the impact).


context 'when `Layout/AccessModifierIndentation EnforcedStyle: outdent`' do
let(:allow_for_alignment) { true }
let(:indentation_width) { 2 }
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is not needed, because you redefine config in this block (the single place where it was used).

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.

AccessModifierIndentation and CommentIndentation does not work well together
3 participants