-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 new Style/HashArrayLastItem
cop
#8271
Conversation
I think we should also mention this in the style guide with a suggestion to use braces for the sake of clarity. |
Can you open a PR as the rule to the style guide? |
990e598
to
5908cae
Compare
Changed name to |
Looks good, but will you start using |
Didn't get it. Can you point to code? |
Here's what I had in mind. What do you think of this style? class HashAsLastArrayItem < Base
include ConfigurableEnforcedStyle
def on_hash(node)
return unless node.parent&.array_type?
if braces_style?
check_braces(node)
else
check_no_brances(node)
end
end
private
def check_braces(node)
return unless node.braces
add_offense(node, message: 'Wrap hash in `{` and `}`.') do |corrector|
corrector.wrap(node, '{', '}')
end
end
def check_no_braces(node)
return if node.braces
add_offense(node, message: 'Omit the braces around the hash.') do |corrector|
corrector.remove(node.loc.begin)
corrector.remove(node.loc.end)
end
end
def braces_style?
style == :braces
end
end |
5908cae
to
b307d03
Compare
Ah, got it. Looks nicer 👍 |
Thanks! |
Closes #4286