-
-
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 Lint/TripleQuotes
cop
#9402
Conversation
Lint/TripleQuotes
cop.Lint/TripleQuotes
cop
On further thought, maybe it might be worthwhile to handle triple quotes and other implicit string concatenation in the same |
Lint/TripleQuotes
copLint/TripleQuotes
cop
b869ad5
to
fa0bc1e
Compare
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.
LGTM, just a small comment
Either way works for me. Separate cop makes sense though as |
fa0bc1e
to
39a7107
Compare
39a7107
to
498afca
Compare
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.
Incredible, thank you!
opening_quotes = node.source.scan(/(?<=\A)['"]*/)[0] | ||
return if opening_quotes.size < 3 | ||
|
||
# If the entire `dstr` is empty `str` nodes, leave one so that there is |
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.
What do you think of "If dstr
node is composed of empty strings only, keep one"?
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.
Sounds good!
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.
Updated, I worded it slightly differently but I think it's clearer now.
expect_no_offenses(<<~RUBY) | ||
'' '' | ||
'a''b''c' | ||
'a''''b' |
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 believe this one line is offensive as well, but it's not a dstr
, and not such a big deal anyway.
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.
Yeah it's not technically a "triple quote" so I didn't want to cover it if we're going to have a separate cop for these situations (as discussed above), but I wanted it to be in the tests for clarity there.
498afca
to
81bb0ba
Compare
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.
This looks good to me.
Nicely done! |
* Update rubocop from 1.12.1 to [1.13.0](https://github.com/rubocop-hq/rubocop/releases/tag/v1.13.0) * Update rubocop-performance from 1.9.2 to [1.11.1](https://github.com/rubocop-hq/rubocop-performance/releases/tag/v1.11.1) * Enabled the following rules: * [`Performance/RedundantSplitRegexpArgument`](rubocop/rubocop-performance#190) * [`Style/IfWithBooleanLiteralBranches`](rubocop/rubocop#9396) * [`Lint/TripleQuotes`](rubocop/rubocop#9402) * [`Lint/SymbolConversion`](rubocop/rubocop#9362) * [`Lint/OrAssignmentToConstant`](rubocop/rubocop#9363) * [`Lint/NumberedParameterAssignment`](rubocop/rubocop#9326) * [`Style/HashConversion`](rubocop/rubocop#9478) * [`Gemspec/DateAssignment`](rubocop/rubocop#9496) * [`Style/StringChars`](rubocop/rubocop#9615)
Follows #9394 (comment).
Looks for instances of triple (or quintuple, or septuple, etc.) quotes and registers an offense for them as they do not have a special meaning in Ruby but could cause confusion that they do.
The case of useless implicit concatenation (ie.
'a' 'b' 'c'
,'' ''
, etc.) is not registered by this cop to keep things simple (but I'm going to look at adding a cop for that as well).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.