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

Lint/MixedCaseRange raises an error for some non-literal ranges #12259

Closed
jaynetics opened this issue Oct 11, 2023 · 0 comments · Fixed by #12260
Closed

Lint/MixedCaseRange raises an error for some non-literal ranges #12259

jaynetics opened this issue Oct 11, 2023 · 0 comments · Fixed by #12260
Labels

Comments

@jaynetics
Copy link
Contributor

The begin or end of Regexp ranges can be non-literals (e.g. subsets, unicode properties, posix classes, codepoint lists).

It is better not to do that because it sometimes leads to weird Regexp behavior. There should perhaps be a cop against it. Either way, MixedCaseRange should not raise errors when encountering such constructs.

It will probably suffice to change this comparison to != :literal.

Expected behavior

No error.

Actual behavior

undefined method `begin' for nil
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:105:in `rewrite_regexp_range'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:51:in `block (2 levels) in on_regexp'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/base.rb:377:in `correct'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/base.rb:181:in `add_offense'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:50:in `block in on_regexp'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:65:in `block (2 levels) in each_unsafe_regexp_range'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:60:in `reject'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:60:in `block in each_unsafe_regexp_range'
[...]/gems/3.3.0+0/gems/regexp_parser-2.8.1/lib/regexp_parser/expression/methods/traverse.rb:75:in `block in each_expression_without_index'
[...]/gems/3.3.0+0/gems/regexp_parser-2.8.1/lib/regexp_parser/expression/subexpression.rb:28:in `each'
[...]/gems/3.3.0+0/gems/regexp_parser-2.8.1/lib/regexp_parser/expression/subexpression.rb:28:in `each'
[...]/gems/3.3.0+0/gems/regexp_parser-2.8.1/lib/regexp_parser/expression/methods/traverse.rb:74:in `each_expression_without_index'
[...]/gems/3.3.0+0/gems/regexp_parser-2.8.1/lib/regexp_parser/expression/methods/traverse.rb:13:in `each_expression'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:57:in `each_unsafe_regexp_range'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/lint/mixed_case_range.rb:49:in `on_regexp'
[...]/gems/3.3.0+0/gems/rubocop-1.56.4/lib/rubocop/cop/commissioner.rb:107:in `public_send'

Steps to reproduce the problem

echo '/[a-[bc]]/' > foo.rb
rubocop --only Lint/MixedCaseRange -d foo.rb

RuboCop version

1.56.4 (using Parser 3.2.2.4, rubocop-ast 1.29.0, running on ruby 3.3.0) [arm64-darwin22]
@koic koic added the bug label Oct 11, 2023
koic added a commit to koic/rubocop that referenced this issue Oct 11, 2023
Fixes rubocop#12259.

This PR fixes an error for `Lint/MixedCaseRange`
when using nested character class in regexp.
bbatsov pushed a commit that referenced this issue Oct 11, 2023
Fixes #12259.

This PR fixes an error for `Lint/MixedCaseRange`
when using nested character class in regexp.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants