Skip to content

[Fix #438] Fix an incorrect autocorrect for Performance/ConstantRegex… - #529

Open
pcbeingused333 wants to merge 1 commit into
rubocop:masterfrom
pcbeingused333:fix/constant-regexp-pattern-matching
Open

[Fix #438] Fix an incorrect autocorrect for Performance/ConstantRegex…#529
pcbeingused333 wants to merge 1 commit into
rubocop:masterfrom
pcbeingused333:fix/constant-regexp-pattern-matching

Conversation

@pcbeingused333

Copy link
Copy Markdown

…p in pattern matching

Fixes #438.

Performance/ConstantRegexp autocorrects an interpolated-constant regexp by appending the /o option. When the regexp is used as a pattern in pattern matching (case/in, one-line in), /o is invalid Ruby and the autocorrection produces broken code (NODE_ONCE: unknown node).

This skips registering an offense when the regexp is in a pattern-matching pattern position, mirroring the existing within_allowed_assignment? guard. Added specs for the case/in and one-line in forms.


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.

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.

Autocorrection for Performance/ConstantRegexp is not working with pattern matching

1 participant