eslint rules for lodash code smells
ESLint-plugin-lodash-smells
===========================


ESLint rules for lodash uses I keep an eye out for when I am doing code reviews.
Install ESLint either locally or globally.
$ npm install eslint
If you installed ESLint globally, you have to install the lodash smells plugin globally as well. Otherwise, install it locally.
$ npm install eslint-plugin-lodash-smells
Add a plugins section to your .eslintrc (if it is not there already), and add lodash-smells to the list:
{
"plugins": [
"lodash-smells"
]
}
And then enable the rules you would like to use:
{
"rules": {
"lodash-smells/no-big-ifs": 1,
"lodash-smells/no-each-push": 1,
"lodash-smells/no-get-length": 1
}
}
Intended to avoid code in this form:
_.each(myList, function(item) {
if (someCondition(item) {
doSomething(item);
}
})
Prefered:
_(myList)
.filter(someCondition)
.each(doSomething);
_.each(_.filter(myList, someCondition), doSomething);
Intended to avoid code in this form:
var myNewList = []
_.each(myList, function(item) {
var newItem = doSomething(item);
myNewList.push(newItem);
});
Preferred:
var myNewList = _.map(myList, doSomething);
Intended to avoid code in this form:
var l = _.get(myList, 'length', 0);
Preferred:
var l = _.size(myList);