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 #8582] Add new Layout/BeginEndAlignment
cop
#8628
[Fix #8582] Add new Layout/BeginEndAlignment
cop
#8628
Conversation
I'm fine with proposed solution, but I think we need to update the descriptions of |
cf806f8
to
1979f96
Compare
Ah, exactly! I updated the docs. |
Fixes rubocop#8582. This PR adds `Layout/BeginEndAlignment` cop to solve the issue. The following is an example: ```ruby % cat example.rb foo = bar rescue "{}" ``` ## Before The alignment was misaligned because `begin` was not awake. ```ruby % rubocop -a example.rb (snip) % cat example.rb foo = begin bar rescue StandardError '{}' end ``` ## After Awakened by `begin`, so aligned. ```ruby % rubocop -a example.rb (snip) % cat example.rb foo = begin bar rescue StandardError '{}' end ``` I was first planning to add `begin` processing to `Layout/EndAlignment` cop. However, `Layout/EndAlignment` cop with `EnforcedStyleAlignWith: keyword (default)` was not preferred code in the following: ```ruby longlonglonglonglonglonglonglonglong ||= begin do_something end ``` This style has been found to have very long line length with RuboCop's own code. Therefore, since this PR would like to use `EnforcedStyleAlignWith: start_of_line` by default against `foo ||= begin`, this PR added the new cop. ```ruby # EnforcedStyleAlignWith: start_of_line (default) longlonglonglonglonglonglonglonglong ||= begin do_something end ``` This solution allows configuration with minimal impact on existing code. It is configurable if user want to align to `begin`. ```ruby # EnforcedStyleAlignWith: begin longlonglonglonglonglonglonglonglong ||= begin do_something end ``` This PR also makes `Layout/RescueEnsureAlignment` cop aware of new `Layout/BeginEndAlignment` cop's config to align `rescue` indents.
1979f96
to
1b21b76
Compare
Awesome cop. I always thought the default begin/end alignment was strange 😉 |
…en fixed * Update Rubocop from [0.90](https://github.com/rubocop-hq/rubocop/releases/tag/v0.90.0) to [0.91](https://github.com/rubocop-hq/rubocop/releases/tag/v0.91.0), enabling: * [`Lint/UselessTimes`](rubocop/rubocop#8702) * [`Layout/BeginEndAlignment`](rubocop/rubocop#8628) * [`Lint/ConstantDefinitionInBlock`](rubocop/rubocop#8707) * [`Lint/IdentityComparison`](rubocop/rubocop#8699) re-enabling after bug fixes: * [`Bundler/DuplicatedGem`](rubocop/rubocop#8666) * [`Naming/BinaryOperatorParameterName`](rubocop/rubocop#8664)
Fixes #8582.
This PR adds
Layout/BeginEndAlignment
cop to solve the issue.The following is an example:
Before
The alignment was misaligned because
begin
was not awake.After
Awakened by
begin
, so aligned.I was first planning to add
begin
processing toLayout/EndAlignment
cop.However,
Layout/EndAlignment
cop withEnforcedStyleAlignWith: keyword (default)
was not preferred code in the following:This style has been found to have very long line length with RuboCop's own code.
Therefore, since this PR would like to use
EnforcedStyleAlignWith: start_of_line
by default againstfoo ||= begin
, this PR added the new cop.This solution allows configuration with minimal impact on existing code.
It is configurable if user want to align to
begin
.This PR also makes
Layout/RescueEnsureAlignment
cop aware of newLayout/BeginEndAlignment
cop's config to alignrescue
indents.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.