Skip to content
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 #3

Open
mik01aj opened this issue Sep 10, 2015 · 5 comments
Open

Ideas for rules #3

mik01aj opened this issue Sep 10, 2015 · 5 comments

Comments

@mik01aj
Copy link

mik01aj commented Sep 10, 2015

It looks like this repo needs inspiration, so here's some from me:

  • 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; }) --> _.filter(stuff, 'field')

    _.filter(stuff, function(obj) { return obj.field === 'foo'; }) --> _.filter(stuff, {field: 'foo'})

  • detect stupid usages of _.find inside loops (with loops, I mean each, 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 of i is reading/writing c[i])

  • detect usages of _.each when _.map would be simpler

  • detect usages of _.each when _.filter would be simpler

  • detect usages of _.each or _.filter when _.find would be simpler

  • detect usages of _.each or _.filter when _.every or _.any would be simpler

  • or 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.

@mtscout6
Copy link
Member

These are fantastic ideas! We take Pull Requests!

@mik01aj
Copy link
Author

mik01aj commented Oct 2, 2015

I just found out that many of these are actually covered by eslint-plugin-lodash3...

I guess it might make sense to merge these 2 projects, since they have essentially the same goal.

@mtscout6
Copy link
Member

mtscout6 commented Oct 2, 2015

I'd be open to that 😄

@ganimomer @idok @mischah How would you feel about that? I'm fine with giving you guys push access to the npm module as well. You guys are more on top of this than we are at the moment. We just happened to grab the name first. I'm all about collaboration if it's something you'd like to persue. I started this org with hopes of collecting multiple useful plugins.

@AlexKVal
Copy link
Member

AlexKVal commented Oct 3, 2015

👍

@ganimomer
Copy link

Hi,
Thanks for the offer, but our plugin was written under the Wix organization and developed by us as Wix employees, so we can't merge it into a different organization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants