Skip to content

Style/TernaryParentheses reported incorrectly #13378

@dkan75

Description

@dkan75

cop incorrectly reports when using &. and comparators.

[Before rubocop -a]

code:

value = 100
puts (value&.> 10) ? 1000 : 2000

value = nil
puts (value&.> 10) ? 1000 : 2000

result:

1000
2000

[After rubocop -a]

code:

value = 100
puts value&.> 10 ? 1000 : 2000

value = nil
puts value&.> 10 ? 1000 : 2000

result:

false


Expected behavior

cop should not report Style/TernaryParentheses. Additionally, do not auto-correct.

Actual behavior

C: [Correctable] Style/TernaryParentheses: Omit parentheses for ternary conditions.
puts (value&.> 10) ? 1000 : 2000
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

execute rubocop -a

RuboCop version

1.67.0 (using Parser 3.3.5.0, rubocop-ast 1.32.3, analyzing as Ruby 3.3, running on ruby 3.3.5) [x86_64-linux]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions