Git Product home page Git Product logo

Comments (5)

sambostock avatar sambostock commented on September 26, 2024 2

AFAIK this is not possible with RuboCop, as it's not evaluating any code. At most, you could detect if value is a local variable, and if that local variable has been assigned the literal nil, but I would advise against that, as it doesn't seem very useful. If you must know if the method is being called with nil values, the only way to really know is to check at runtime. Another approach would be to use a type checker like Sorbet.

from rubocop.

koic avatar koic commented on September 26, 2024 1

RuboCop is fundamentally a static analysis tool for single files, and therefore, it cannot perform analysis across multiple files. As already mentioned, it is impossible to determine if any case, other than nil literals and local variables, is nil. So, it might be possible to ascertain the value of local variables by traversing for nodes where the value is assigned.

from rubocop.

syedasaranaseer2 avatar syedasaranaseer2 commented on September 26, 2024

This is one way I could do it but the problem here is that it fails on every type of value and not just nil.

def_node_matcher :must_equal_nil?, <<~PATTERN
            {
              (send _ :must_equal (lvar _))
              (send _ :must_equal (nil))
          }
        PATTERN

Any way to just make it work for nil values?

from rubocop.

obaidashfaq20 avatar obaidashfaq20 commented on September 26, 2024

I've tried several solutions, but none have worked so far. It's possible that we're dealing with a static analyzer and cannot obtain the value beforehand. I'm hoping someone from the Rubocop family can provide additional guidance.

from rubocop.

obaidashfaq20 avatar obaidashfaq20 commented on September 26, 2024

Yes, I have used the sorbet in some other context, which bulk up the project and I can't convince everyone to opt in for that in this case!

Thanks for the input

from rubocop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.