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
Style/AccessorGrouping: Fix detection of Sorbet sig {}
blocks
#11650
Style/AccessorGrouping: Fix detection of Sorbet sig {}
blocks
#11650
Conversation
9dce847
to
bb70257
Compare
bb70257
to
ff1ce4c
Compare
Force-pushed to add backticks to the cop name in the changelog. |
@@ -90,6 +90,13 @@ def previous_line_comment?(node) | |||
|
|||
def groupable_accessor?(node) | |||
return true unless (previous_expression = node.left_siblings.last) | |||
|
|||
if previous_expression.block_type? |
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.
Might be good to add a small comment here explaining what this bit of code targets.
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.
Yup. Done!
annotation_method :one | ||
attr_reader :one | ||
|
||
annotation_method :two | ||
attr_reader :two | ||
|
||
sig { returns(Integer) } |
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.
You can also mention such an example explicitly in the cop's description.
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.
Thanks, done!
- Sorbet `sig { returns(Integer) }` annotations above `attr_reader` methods should be ignored after 9921cdc, per the docs, but they weren't being. - Sorbet `sig {}` constructs are blocks (hence the braces), not `send_type?` directly. - Hence, we now check if the previous expression is a block and if so, descend into its child nodes until we find a `send_type`, then use that to determine if the accessor is groupable. - Relates to rubocop#11596.
ff1ce4c
to
7fa0439
Compare
Thanks! |
sig { returns(Integer) }
annotations aboveattr_reader
methods should be ignored after9921cdcdf7c4cd, per the docs, but they weren't being (see the test I added here for evidence).sig {}
constructs are blocks (hence the braces), notsend_type?
directly.send_type
, then use that to determine if the accessor is groupable.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 runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.