-
-
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
Ideas for some new %-style literal cops #835
Comments
@jonas054 Would like this task? I think that writing a few cops might be a welcome break for you from fixing bugs. :-) |
Yes, that might be nice. I'm putting it on my todo list. |
Newbie here. I've got a first stab at %W vs. %w that I'm polishing up. My main question right now is that I borrowed some helper methods from percent_literal_delimiters.rb and don't know where I should factor them out to. Anyone got a few minutes to help me acclimate to the conventions of the project? :) |
@sfeldon Thanks for helping out! Create a new module under |
@sfeldon I'd suggest extracting the common code into a mixin or a force. You can see examples of this done in |
Examining the force code, I've decided that I could have it done with a mixin before I could understand how to do it with a force. Thanks for the info, gents--working on it. |
@sfeldon Any progress? |
His cop is already merged. On Sunday, April 27, 2014, Jonas Arvidsson notifications@github.com wrote:
Best Regards, |
I forgot about that. I'll get started on the rest then. |
Aigh. If you were holding on working on stuff because of me, please And thank you both for the support and the experience. :) steve On Sat, Apr 26, 2014 at 11:36 PM, Jonas Arvidsson
|
@sfeldon No worries! I'll leave the autocorrect for the |
Part of rubocop#835.
Part of rubocop#835.
|
Sounds good. — On Sat, Jun 21, 2014 at 10:33 AM, Jonas Arvidsson
|
My rules for when to use For literal strings, my primary concern is to distinguish strings that use variable interpolation vs those that don't. When I see a string quoted with I always try to quote a string using However the |
@dkubb I think your style preference makes sense, and hopefully we can support it as a configuration choice. The current implementation of The style guide doesn't go into much detail, and really doesn't cover these corner cases, so I wouldn't say we're in violation of it as it is right now. |
Checks `%Q` vs `%q`, and allow configuration to decide if `%q` should be used when possible or if `%Q` should be used always. For rubocop#835.
Regular expressions starting with % or %Q were treated as string literals starting with those delimiters. Related to rubocop#835.
The style guide says: Use %() (it's a shorthand for %Q) for single-line strings which require both interpolation and embedded double-quotes. This cop's job is to check that you use % rather than %Q, or the opposite if so configured.
…Style If %q(') is preferred over "'", then the value static should be used. This also affects the Style/UnneededPercentQ cop, which will not report the use of %q(') if Style/StringLiterals is configured for static strings.
@dkubb Your preferred style could not be supported without adding too much complexity. That brings this issue to a close. |
#834 reminded me about some cops, that might be nice to have:
%q
or%(Q)
. Obviously it's always a better idea to use''
and""
unless you really need%q
or%Q
. And sometimes you might have used%Q
when%q
would do.%x
where ```` would do.%W
where%w
would do.All of those should be fairly easy to implement. Feel free to hack on any of them. //cc @yujinakayama @jonas054 @hannestyden
The text was updated successfully, but these errors were encountered: