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

Conflict Lint/AmbiguousRange and Style/RedundantParentheses on complex literals (i.e. string interpolation) #10230

Closed
Tietew opened this issue Nov 4, 2021 · 0 comments · Fixed by #10232
Labels

Comments

@Tietew
Copy link
Contributor

Tietew commented Nov 4, 2021

When complex literal (i.e. string interpolation) in range literals (.. and ...), rubocop detects Lint/AmbiguousRange.
But adding parentheses causes Style/RedundantParentheses.

Lint/AmbiguousRange seems to be a false positive.

# dstr
"#{foo}-#{bar}"..'123-4567'
# xstr
`date`..'foobar'
# dsym
:"#{foo}-#{bar}"..:baz
# regexp
/a/../b/

Lint/AmbiguousRange seems to be reasonable, Style/RedundantParentheses should not be detected.

# array
[1]..[2]
# hash
{1 => 2}..{3 => 4}

Expected behavior

No offences should be detected.

Actual behavior

Lint/AmbifuousRange detected.

"#{foo}-#{bar}"..'123-4567'
^^^^^^^^^^^^^^^ [Correctable] Lint/AmbiguousRange: Wrap complex range boundaries with parentheses to avoid ambiguity.
("#{foo}-#{bar}")..'123-4567'
^^^^^^^^^^^^^^^^^ [Correctable] Style/RedundantParentheses: Don't use parentheses around a literal.

RuboCop version

$ be rubocop -V
1.22.3 (using Parser 3.0.2.0, rubocop-ast 1.12.0, running on ruby 2.7.4 x86_64-linux)
  - rubocop-performance 1.12.0
  - rubocop-rails 2.12.4
  - rubocop-rspec 2.5.0
@koic koic added the bug label Nov 4, 2021
koic added a commit to koic/rubocop that referenced this issue Nov 12, 2021
Fixes rubocop#10230.

This PR fixes a false positive for `Lint/AmbiguousRange`
when a range is composed of all literals except basic literals.
If it's just literals, it's clear even without parentheses,
so this PR will accept them.
bbatsov pushed a commit that referenced this issue Nov 12, 2021
Fixes #10230.

This PR fixes a false positive for `Lint/AmbiguousRange`
when a range is composed of all literals except basic literals.
If it's just literals, it's clear even without parentheses,
so this PR will accept them.
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