Code Monkey home page Code Monkey logo

Comments (11)

mik01aj avatar mik01aj commented on May 28, 2024

See #5 for explanation.

from eslint-plugin-lodash.

gajus avatar gajus commented on May 28, 2024

@mik01aj The example that you have provided has an extremely limited use case: it is only relevant when checking for variables in the inherited scope (globals, such as in the context of browser scripts).

Fair to say that the default behaviour should be to enforce the use of _.isUndefined through ESLint rules and use /* eslint-disable lodash3/prefer-lodash-typecheck */ in such very specific cases.

You will never get such an error when the variable declaration is present, e.g. when checking function parameter presence.

(a) => {
    // Does not produce an error.
    _.isUndefined(a);
};

from eslint-plugin-lodash.

mik01aj avatar mik01aj commented on May 28, 2024

Agreed. πŸ‘

from eslint-plugin-lodash.

gajus avatar gajus commented on May 28, 2024

@ganimomer any input?

from eslint-plugin-lodash.

ganimomer avatar ganimomer commented on May 28, 2024

The intent of the rule is to prefer Lodash versions of type checking, as long as they have the exact same meaning and behavior in all cases.
In the case of _.isUndefined, it is not the exact same is typeof(a) === 'undefined'.
I suppose the rule could use the context to check if either the expression is a variable that exists or isn't a variable (i.e., typeof a.b === 'undefined' or a => typeof(a) === 'undefined')
but the rule definitely shouldn't have 'false positives' like you're suggesting, where the replacement shouldn't happen and the rule should be turned off.
We could get around to implementing that soon, or anyone could submit a PR if you like.

from eslint-plugin-lodash.

mik01aj avatar mik01aj commented on May 28, 2024

I think that this could be configurable, so that the rule wouldn't warn about typechecks with undefined by default, but you could have a alsoForUndefined flag that would enable this.

from eslint-plugin-lodash.

ganimomer avatar ganimomer commented on May 28, 2024

I don't agree.
Under no configuration should any rule ever report in a case where fixing it would cause an error.
However, like I said, it can only report typeof <expression> === 'undefined' where fixing is possible.
ESLint enables rules to check which variables are declared with context.getDeclaredVariables()

from eslint-plugin-lodash.

mik01aj avatar mik01aj commented on May 28, 2024

@ganimomer so how about triggering a warning only when using it as typeof <declared-variable> === 'undefined'? In this case, lodash typecheck is equivalent.

from eslint-plugin-lodash.

ganimomer avatar ganimomer commented on May 28, 2024

That's the idea. :)
Well, that and checking any expression that isn't a literal.
technically typeof a.b === 'undefined' will behave the same way as _.isUndefined(a.b).
v0.4.0 we released yesterday fixed that part, but still hasn't fixed the part where it's a declared literal, since that's a bit more complicated.

from eslint-plugin-lodash.

mik01aj avatar mik01aj commented on May 28, 2024

Great, thanks! πŸ‘ I'm looking forward to more good news! :)

from eslint-plugin-lodash.

ganimomer avatar ganimomer commented on May 28, 2024

Technically, this issue is resolved. I'm closing it and opening a separate issue for typeof <declared-variable>.

from eslint-plugin-lodash.

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.