Skip to content

Style/TernaryParentheses still not necessarily safe autocorrect for defined? keyword #8782

@OmriSama

Description

@OmriSama

I have a project with this line in it:

val = (defined? inc.name) ? inc.name : inc

rubocop -a autocorrects this to:

val = defined? inc.name || inc

Which is clearly not the same thing because one returns a Boolean and another returns the name.

The correct way to fix this, IMO, to make Rubocop happy:

val = defined?(inc.name) ? inc.name : inc

I thought this issue was common enough that I would've been able to find someone who had it before, and I did find:

#3505
#3450

But it seems like this problem has persisted...

Thoughts?

RuboCop version

$ bundle exec rubocop -V
0.91.1 (using Parser 2.7.1.4, rubocop-ast 0.4.2, running on ruby 2.7.1 x86_64-darwin19)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy