Underscore specific linting rules for ESLint
npm install eslint-plugin-underscore
Forked from eslint-plugin-lodash
ESLint-plugin-underscore
===================
Linting rules for Underscore
Install ESLint either locally or globally.
npm install eslint
If you installed ESLint globally, you have to install the Underscore plugin
globally too. Otherwise, install it locally.
$ npm install eslint-plugin-underscore
Add plugins section and specify ESLint-plugin-underscore as a plugin.
``json`
{
"plugins": ["underscore"]
}
Finally, enable all of the rules that you would like to use.
`javascript
{
"rules": {
"underscore/collection-return": 2,
"underscore/identity-shorthand": [2, "always"],
"underscore/jquery-each": [2, "never"],
"underscore/jquery-extend": [2, "never"],
"underscore/jquery-proxy": [2, "never"],
"underscore/matches-shorthand": [2, "always"],
"underscore/no-return-value-from-each-iteratee": 2,
"underscore/no-unnecessary-bind": 2,
"underscore/prefer-chain": [2, 3],
"underscore/prefer-compact": 2,
"underscore/prefer-constant": 2,
"underscore/prefer-filter": 2,
"underscore/prefer-findwhere": 2,
"underscore/prefer-invoke": 2,
"underscore/prefer-map": 2,
"underscore/prefer-matches": 2,
"underscore/prefer-noop": 2,
"underscore/prefer-pluck": 2,
"underscore/prefer-reject": 2,
"underscore/prefer-times": 2,
"underscore/prefer-underscore-method": 2,
"underscore/prefer-underscore-typecheck": 2,
"underscore/prefer-where": 2,
"underscore/preferred-alias": 2,
"underscore/prop-shorthand": [2, "always"],
// The below rules are not (yet) supported
"underscore/no-single-chain": 2,
"underscore/unwrap": 2,
"underscore/no-double-unwrap": 2,
"underscore/prefer-wrapper-method": 2,
"underscore/prefer-lodash-chain": 2,
"underscore/chain-style": [2, "as-needed"]
}
}
`
* collection-return: Always return a value in iteratees of Underscore collection methods that aren't each._.each
* identity-shorthand: Prefer identity shorthand syntax.
* jquery-each: Standardize on either Underscore's or jQuery's each function.
* jquery-extend: Standardize on either Underscore's or jQuery's extend function.
* jquery-proxy: Standardize on either Underscore's bind or jQuery's proxy function.
* matches-shorthand: Prefer matches shorthand syntax.
* no-return-value-from-each-iteratee: Do not return a value from the iteratee of .thisArg
* no-unnecessary-bind: Prefer passing over binding._.compact
* prefer-chain: Prefer chain over nested Underscore calls.
* prefer-compact: Prefer over _.filter for only truthy values._.constant
* prefer-constant: Prefer over functions returning literals._.filter
* prefer-filter: Prefer over _.each with an if statement inside._.findWhere
* prefer-findwhere: Prefer over _.find when using matcher shorthand. (fixable)_.invoke
* prefer-invoke: Prefer using over _.map with a method call inside._.map
* prefer-map: Prefer over _.each with a push inside._.matches
* prefer-matches: Prefer over conditions like a.foo === 1 && a.bar === 2 && a.baz === 3._.noop
* prefer-noop: Prefer over empty functions._.pluck
* prefer-pluck: Prefer over _.map when using property shorthand. (fixable)_.reject
* prefer-reject: Prefer over filter with !(expression) or x.prop1 !== value._.times
* prefer-times: Prefer over _.map without using the iteratee's arguments._.map
* prefer-underscore-method: Prefer using Underscore collection methods (e.g. ) over native array methods._.is
prefer-underscore-typecheck: Prefer using methods over typeof and instanceof checks when applicable._.where
* prefer-where: Prefer over _.filter when using matcher shorthand. (fixable)
* preferred-alias: Preferred aliases.
* prop-shorthand: Prefer property shorthand syntax. (fixable)
* no-single-chain: Prevent chaining syntax for single method, e.g. _(x).map().value().value()
* unwrap: Prevent chaining without evaluation via or non-chainable methods like max()..value()
* no-double-unwrap: Do not use on chains that have already ended (e.g. with max() or reduce())._(str).split(' ')...
* prefer-wrapper-method: Prefer using array and string methods in the chain and not the initial value, e.g. _.map`) over native and mixed chains.
* prefer-lodash-chain: Prefer using Lodash chains (e.g.
* chain-style: Enforce a specific chain style: explicit, implicit, or explicit only when necessary.
ESLint-plugin-underscore is licensed under the MIT License.
[npm-url]: https://npmjs.org/package/eslint-plugin-underscore
[npm-image]: http://img.shields.io/npm/v/eslint-plugin-underscore.svg?style=flat-square