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 handling of escaped octals in duplicate regexp cop #11562

Merged
merged 4 commits into from
Jun 21, 2023

Conversation

rwstauner
Copy link
Contributor

@rwstauner rwstauner commented Feb 9, 2023

This improves the handling of escaped octals (as long as we allow regexp_parser < 2.7)
for the duplicate regexp character class element cop.


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.

if seen.include?(current_child_source)
next if start_with_escaped_zero_number?(current_child_source, next_child.to_s)
def group_expressions(node, expressions)
expressions = expressions.to_a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems unnecessary, right?

Suggested change
expressions = expressions.to_a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was using the array as a "enum" so i can just remove items until it's empty.
it required less state tracking than the original enumerator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

part of why i ended up here was because the original method was triggering several linters about method length and complexity, but i couldn't update the counter from a separate method, so in breaking it into smaller methods using a mutable array seemed simplest.


private
def pop_octal_digits(current_child, expressions)
2.times do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks better when named with 2 as a constant

te is the same as ts + length
plus te is angering the spell checker
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 26, 2023

As I'm not familiar with the nuances of regexp_parser I'll defer to @koic here.

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 20, 2023

@koic Are we good to merge this PR?

@koic
Copy link
Member

koic commented Jun 21, 2023

Yep! Let's take this change!

@koic koic merged commit 9c9c04a into rubocop:master Jun 21, 2023
@koic
Copy link
Member

koic commented Jun 21, 2023

Thanks!

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

3 participants