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
Add support for variable alignment to Layout/RescueEnsureAlignment #7531
Add support for variable alignment to Layout/RescueEnsureAlignment #7531
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏 thank you kindly
x ||= begin | ||
1 | ||
rescue | ||
^^^^^^ `rescue` at 3, 6 is not aligned with `x` at 1, 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
@@ -6,22 +6,48 @@ module Layout | |||
# This cop checks whether the rescue and ensure keywords are aligned | |||
# properly. | |||
# | |||
# @example | |||
# Three modes are supported through the `EnforcedStyleAlignWith` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to make this configurable
f017348
to
5e3cd02
Compare
@@ -995,6 +995,10 @@ Layout/ParameterAlignment: | |||
|
|||
Layout/RescueEnsureAlignment: | |||
Description: 'Align rescues and ensures correctly.' | |||
EnforcedStyleAlignWith: keyword |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply EnforcedStyle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looked like the alignment cops were using EnforcedStyleAlignWith
, so I was just trying to be consistent with them. Why not simply EnforcedStyle
for Layout/BlockAlignment
, Layout/DefEndAlignment
, Layout/EndAlignment
and Layout/RescueEnsureAlignment
? I'm fine either way. Did you want me to change it to EnforcedStyle
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looked like the alignment cops were using
EnforcedStyleAlignWith
That is my experience/expectation as well, FWIW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I no longer remember why we did it like this in the past, but I definitely don't like it today. Probably it was to avoid styles named align_with_*
, but I think that's fine.
Apart from my small remark the suggested changes seem reasonable to me. |
I came here from #6918 ... Can I request a test case be added? The code in question is: private memoize def do_something
"Something"
rescue NameError
nil
end Rubocop private memoize def do_something
"Something"
rescue NameError
nil
end If I remove private def do_something
"Something"
rescue NameError
nil
end Should I open a separate issue for supporting |
5e3cd02
to
7e16075
Compare
It would make sense to add support for |
…eEnsureAlignment
7e16075
to
22d5d6a
Compare
Any input on the status of this PR? |
I'd love to see that merged, @bbatsov any final decision on |
I'm closing this PR due to no recent activity. Feel free to re-open it if you ever come back to it. |
I was under the impression that this PR was waiting for a response by @bbatsov to the following questions:
|
Well, if that's the case - I prefer the use of |
As mentioned in the referenced issue (#6918 (comment)), I think this problem is addressed by the Layout/BeginEndAlignment cop with the |
A problem that solves itself - that's my favourite kind. 😄 Thanks! |
No, I don't remember. I've found that we changed the name from |
Fixes #6918
The Layout/RescueEnsureAlignment cop was always enforcing alignment of the
rescue
keyword with thebegin
keyword, even when thebegin
block was being assigned to a variable. For example, it would expect code likebut reject code aligning
rescue
with a variable likeeven though a variable style is supported for similar cops, such as Layout/EndAlignment.
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.