eslint-plugin-lodash-smells

0.2.0 • Public • Published

ESLint-plugin-lodash-smells

Codeship Status for rayners/eslint-plugin-lodash-smells Coverage Status

ESLint rules for lodash uses I keep an eye out for when I am doing code reviews.

Installation

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

Configuration

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
    }
}

Rules

no-big-ifs

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);

no-each-push

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);

no-get-length

Intended to avoid code in this form:

var l = _.get(myList, 'length', 0);

Preferred:

var l = _.size(myList);

Package Sidebar

Install

npm i eslint-plugin-lodash-smells

Weekly Downloads

159

Version

0.2.0

License

BSD-3-Clause

Last publish

Collaborators

  • rayners