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 a false positive for Style/Alias #12095

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

koic
Copy link
Member

@koic koic commented Aug 4, 2023

This PR fixes the following false positive to prevent incorrect autocorrection for Style/Alias when EncforcedStyle: prefer_alias and using alias with interpolated symbol argument:

$ ruby -ce 'alias :"string#{interpolation}" :symbol'
Syntax OK
$ echo 'alias :"string#{interpolation}" :symbol' | bundle exec rubocop --stdin example.rb -a --only Style/Alias
Inspecting 1 file
F

Offenses:

example.rb:1:7: F: Lint/Syntax: unexpected token tSTRING_BEG
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
alias "string#{interpolation}" symbol
      ^
example.rb:1:7: C: [Corrected] Style/Alias: Use alias "string#{interpolation}" symbol instead of alias :"string#{interpolation}" :symbol.
alias :"string#{interpolation}" :symbol
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
example.rb:1:32: F: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
alias "string#{interpolation}" symbol
                               ^^^^^^

1 file inspected, 3 offenses detected, 1 offense corrected
====================
alias "string#{interpolation}" symbol

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.

@koic koic force-pushed the fix_a_false_positive_for_style_alias branch from ad955c8 to 668a1cc Compare August 4, 2023 03:36
This PR fixes the following false positive to prevent incorrect autocorrection for `Style/Alias`
when `EncforcedStyle: prefer_alias` and using `alias` with interpolated symbol argument:

```console
$ ruby -ce 'alias :"string#{interpolation}" :symbol'
Syntax OK
```

```console
$ echo 'alias :"string#{interpolation}" :symbol' | bundle exec rubocop --stdin example.rb -a --only Style/Alias
Inspecting 1 file
F

Offenses:

example.rb:1:7: F: Lint/Syntax: unexpected token tSTRING_BEG
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
alias "string#{interpolation}" symbol
      ^
example.rb:1:7: C: [Corrected] Style/Alias: Use alias "string#{interpolation}" symbol instead of alias :"string#{interpolation}" :symbol.
alias :"string#{interpolation}" :symbol
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
example.rb:1:32: F: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)
alias "string#{interpolation}" symbol
                               ^^^^^^

1 file inspected, 3 offenses detected, 1 offense corrected
====================
alias "string#{interpolation}" symbol
```
@koic koic force-pushed the fix_a_false_positive_for_style_alias branch from 668a1cc to d5e5720 Compare August 4, 2023 04:48
@koic koic merged commit 8b98c53 into rubocop:master Aug 4, 2023
28 checks passed
@koic koic deleted the fix_a_false_positive_for_style_alias branch August 4, 2023 15:28
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.

None yet

1 participant