Skip to content
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

Merged

Conversation

jasondoc3
Copy link
Contributor

@jasondoc3 jasondoc3 commented Aug 1, 2023

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:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@@ -0,0 +1 @@
* [#12071](https://github.com/rubocop/rubocop/issues/12071): Fix `Style/SymbolArray` false positives. ([@jasondoc3][])
Copy link
Member

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?

Copy link
Contributor Author

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

@jasondoc3 jasondoc3 force-pushed the jason/fix-false-positive-symbol-array branch from 5233ac1 to 0fce99b Compare August 1, 2023 02:21
@jasondoc3 jasondoc3 changed the title [Fix #12071] Fix Style/SymbolArray false positives [Fix #12071] Fix Style/SymbolArray false positives when using square brackets or interpolation in a symbol literal within a percent style array Aug 1, 2023
@jasondoc3 jasondoc3 force-pushed the jason/fix-false-positive-symbol-array branch from 0fce99b to 8e83725 Compare August 1, 2023 02:38
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
Copy link
Member

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?

Suggested change
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

Copy link
Contributor Author

@jasondoc3 jasondoc3 Aug 1, 2023

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

@jasondoc3 jasondoc3 force-pushed the jason/fix-false-positive-symbol-array branch 3 times, most recently from b6ead16 to ed09cd5 Compare August 1, 2023 02:51
@koic
Copy link
Member

koic commented Aug 1, 2023

Looks good to me. Can you squash your commits into one?

@jasondoc3 jasondoc3 force-pushed the jason/fix-false-positive-symbol-array branch from ed09cd5 to c5cefae Compare August 1, 2023 02:55
@jasondoc3
Copy link
Contributor Author

@koic Squashed. Thanks for the quick review

@koic koic merged commit d8646b4 into rubocop:master Aug 1, 2023
28 checks passed
@koic
Copy link
Member

koic commented Aug 1, 2023

Thanks!

@jasondoc3 jasondoc3 deleted the jason/fix-false-positive-symbol-array branch August 1, 2023 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positives for Style/SymbolArray in literal symbol array
2 participants