-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Fix #12071] Fix Style/SymbolArray
false positives when using square brackets or interpolation in a symbol literal within a percent style array
#12088
Conversation
@@ -0,0 +1 @@ | |||
* [#12071](https://github.com/rubocop/rubocop/issues/12071): Fix `Style/SymbolArray` false positives. ([@jasondoc3][]) |
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.
Can you add a little more information to the description about what will be fixed?
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.
Added a bit more detail here
5233ac1
to
0fce99b
Compare
Style/SymbolArray
false positives when using square brackets or interpolation in a symbol literal within a percent style array
0fce99b
to
8e83725
Compare
content = content.to_s | ||
content_without_delimiter_pairs = content.gsub(/(\[\])|(\(\))/, '') | ||
content = *sym | ||
content = content.map { |c| c.respond_to?(:str_content) ? c.str_content : c.to_s }.join |
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.
Can you refactor to below?
content = content.map { |c| c.respond_to?(:str_content) ? c.str_content : c.to_s }.join | |
content = content.map { |c| c.is_a?(AST::Node) ? c.source : c }.join |
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.
Yes. That is much clearer 🙌 . I was looking for a more concise way to check this other than using respond_to?
. Done
b6ead16
to
ed09cd5
Compare
Looks good to me. Can you squash your commits into one? |
ed09cd5
to
c5cefae
Compare
@koic Squashed. Thanks for the quick review |
Thanks! |
Fixes #12071. Some false positives offenses were introduced in #12037.
For example,
%I[#{one}_two three]
and%i[one[2] three]
are currently returning offenses when they should not be.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.