-
-
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
default
key in Style/PercentLiteralDelimiters
#4038
default
key in Style/PercentLiteralDelimiters
#4038
Conversation
I think |
all
key in Style/PercentLiteralDelimiters
default
key in Style/PercentLiteralDelimiters
@bbatsov Yeah I agree. I've updated the code and merged in master. Do you have further thoughts on this? |
@@ -4,6 +4,9 @@ module RuboCop | |||
module Cop | |||
module Style | |||
# This cop enforces the consistent usage of `%`-literal delimiters. | |||
# Specify the 'default' key to set all preferred delimiters at once. You | |||
# can continue to specify individual preferred delimiters to override the | |||
# default. |
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.
Btw, you can give a few code examples here.
def preferred_delimiters | ||
@preferred_delimiters ||= | ||
if cop_config['PreferredDelimiters'].key?('default') | ||
Hash[%w(% %i %I %q %Q %r %s %w %W %x).map do |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.
I'd make this array a constant.
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.
And we can probably add some error checking for unknown delimiters in case users mistype something.
config/default.yml
Outdated
@@ -912,16 +912,8 @@ Style/ParenthesesAroundCondition: | |||
|
|||
Style/PercentLiteralDelimiters: | |||
PreferredDelimiters: | |||
'%': () |
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.
Although this is more or less clear you can add some comment here explaining the configuration of the cop.
Apart from the failing and my small remarks, the changes look ok to me. |
Great, I've updated with that feedback in mind. Let me know what you think. Thanks for the quick responses! |
Looks good! You'll just have to rebase on top of the current |
Oftentimes people want to set the default percent literal delimiter to [], but have to override every available option in order to get that behavior. This commit adds the ability to specify an 'all' key that will specify the default for every possible delimiter, which you can then overwrite with others.
Create PERCENT_LITERAL_TYPES constant for the different supported types and ensure valid configuration is passed to the PercentLiteralDelimiters cop.
Sounds good, just rebased. |
Oftentimes people want to set the default percent literal delimiter to [], but have to override every available option in order to get that behavior. This commit adds the ability to specify an 'all' key that will specify the default for every possible delimiter, which you can then overwrite with others.