[Fix #8582] Add new Layout/BeginEndAlignment cop#8628
Merged
koic merged 1 commit intorubocop:masterfrom Sep 6, 2020
Merged
Conversation
Collaborator
|
I'm fine with proposed solution, but I think we need to update the descriptions of |
cf806f8 to
1979f96
Compare
Member
Author
|
Ah, exactly! I updated the docs. |
bbatsov
approved these changes
Sep 6, 2020
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 😉 |
jmkoni
pushed a commit
to standardrb/standard
that referenced
this pull request
Sep 16, 2020
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8582.
This PR adds
Layout/BeginEndAlignmentcop to solve the issue.The following is an example:
Before
The alignment was misaligned because
beginwas not awake.After
Awakened by
begin, so aligned.I was first planning to add
beginprocessing toLayout/EndAlignmentcop.However,
Layout/EndAlignmentcop 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_lineby 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/RescueEnsureAlignmentcop aware of newLayout/BeginEndAlignmentcop's config to alignrescueindents.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.