Comments (11)
See #5 for explanation.
from eslint-plugin-lodash.
@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.
Agreed. π
from eslint-plugin-lodash.
@ganimomer any input?
from eslint-plugin-lodash.
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.
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.
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.
@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.
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.
Great, thanks! π I'm looking forward to more good news! :)
from eslint-plugin-lodash.
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)
- `prop-shorthand` does not report on `_.orderBy` HOT 1
- Dependabot couldn't reach repo.dev.wixpress.com/artifactory/api/npm/npm-repos as it timed out
- `collection-ordering`: Require same number of iteratees and orders
- Error when typing `_()`
- chaining rule doesnβt work when chain is imported from lodash/chain HOT 1
- Can I autofix by `preferred-alias` rule? HOT 1
- `path-style` rule has bug
- False positive for prefer-lodash-chain with _.range? HOT 1
- Version 7.1.0 is failing on the project with Lodash v3 HOT 1
- prefer-noop shouldn't trigger if a function has comment inside
- path-style is supposed to be "as-needed" by default
- bug: lodash/prefer-lodash-method false positive with nextjs (react) router replace
- path-style rule auto-fix incorrectly formats object accessor causing regressions! HOT 1
- Whitesource scan vulnerability on lodash < 4.19.19
- Support ESLint 8.x HOT 1
- Recommending `_.split` for v3 despite it not existing
- type import produces false positive under lodash/import-scope HOT 1
- `prefer-is-undefined` and `prefer-is-null`
- Combine rules for `import-scope`, accept both 'member' and 'method' HOT 2
- lodash/prefer-* rules cause problems with Jest mocks HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-lodash.