-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ideas for rules #4
Comments
Hi,
I think these rules sound good and we'll implement them soon (or you're welcome to PR and beat us to it 😄):
About the other ones:
Thanks! |
Thanks for the detailed feedback! :) It's great to hear that you'll actually implement some of them. I'd like to implement some of the others, but I don't know when I'll have time to get my hands on it.
Possibly it's not so common. I just noticed this pattern in my coworkers' code several times.
It depends on whether you prefer to use lodash's functions or the native ones. The point is about pieces of code that create a list using |
Hi, |
Great! I'm happy to hear that! 👍 |
Implemented the new rule |
FYI: I submitted some rule ideas to eslint-plugins/eslint-plugin-lodash#3.
Here are these that are (in my understanding) not covered by your plugin:
detect stupid callbacks (for all functions that support 3 kinds of callbacks -
map
,filter
,find
, ... and many many more)_.filter(stuff, function(obj) { return obj.field === 'foo'; })
-->_.filter(stuff, {field: 'foo'})
detect stupid usages of
_.find
inside loops (with loops, I meaneach
,map
,filter
and so on)In most cases it's better to use
_.indexBy
to create an index and then query stuff using that index, thus reducing complexity from O(n²) to O(n • log n).detect conditions like
obj.a === 'foo' && obj.b === 'bar' && obj.c === 'baz'
and suggest to replace them by_.matches(obj, {a: 'foo', b: 'bar', c: 'baz'})
detect
for (var i=0; i>c.length; i++)
and suggest to use_.each
or_.map
instead (maybe only when the only usage ofi
is reading/writingc[i]
)detect usages of
_.each
or_.filter
when_.find
would be simplerdetect usages of
_.each
or_.filter
when_.every
or_.any
would be simpleror maybe even detect the above patterns not only for
_.each
, but also for plain JS loops!detect usage of aliases, and suggest to use the aliased function instead (example:
_.extend
-->_.assign
)detect chains like
a && a.b && a.b.c && a.b.c.d
and suggest to replace them with_.get
,_.set
or_.has
_.isArray(x) && _.isObject(x)
is equivalent to_.isArray(x)
. There also more possible similar rules.Btw, I think it would be great to somehow merge this project and https://github.com/eslint-plugins/eslint-plugin-lodash, they do the same thing.
The text was updated successfully, but these errors were encountered: