eslint-plugin-lodash-fp
Advanced tools
Comparing version 2.1.3 to 2.2.0-a1
@@ -7,4 +7,10 @@ # Change Log | ||
## [Unreleased] | ||
- (none) | ||
### Added | ||
- Added lodash-fp to recommended preset ([#66], thanks [@iddan]]). | ||
- Added [`no-extraneous-partials`] rule ([#68]). | ||
### Fixed | ||
- Fixed [`no-unused-result`] by exempting [`_.defer`] and [`_.delay`] as side | ||
effect methods ([#64], thanks [@friday]). | ||
## [2.1.3] - 2016-11-08 | ||
@@ -158,2 +164,4 @@ ### Fixed | ||
[`_.reject`]: https://lodash.com/docs#reject | ||
[`_.defer`]: https://lodash.com/docs#defer | ||
[`_.delay`]: https://lodash.com/docs#delay | ||
@@ -165,2 +173,4 @@ [`ast-utils`]: https://github.com/jfmengels/eslint-ast-utils | ||
[#68]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/68 | ||
[#64]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/64 | ||
[#42]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/42 | ||
@@ -170,2 +180,3 @@ [#36]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/36 | ||
[#11]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/11 | ||
[#13]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/13 | ||
@@ -175,4 +186,5 @@ [#41]: https://github.com/jfmengels/eslint-plugin-lodash-fp/issues/41 | ||
[#30]: https://github.com/jfmengels/eslint-plugin-lodash-fp/issues/30 | ||
[#13]: https://github.com/jfmengels/eslint-plugin-lodash-fp/pull/13 | ||
[@iddan]: https://github.com/iddan | ||
[@friday]: https://github.com/friday | ||
[@dfadler]: https://github.com/dfadler | ||
@@ -179,0 +191,0 @@ [@godu]: https://github.com/godu |
@@ -17,2 +17,3 @@ 'use strict'; | ||
recommended: { | ||
plugins: ['lodash-fp'], | ||
rules: recommendedRules | ||
@@ -19,0 +20,0 @@ } |
{ | ||
"name": "eslint-plugin-lodash-fp", | ||
"version": "2.1.3", | ||
"version": "2.2.0a1", | ||
"description": "ESLint rules for lodash/fp", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=4.0.0" | ||
"node": ">=6.0.0" | ||
}, | ||
@@ -42,12 +42,12 @@ "scripts": { | ||
"lodash": "^4.11.1", | ||
"req-all": "^0.1.0" | ||
"req-all": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.16.0", | ||
"eslint": "^3.0.1", | ||
"ava": "^0.17.0", | ||
"eslint": "^5.1.0", | ||
"eslint-ava-rule-tester": "^2.0.0", | ||
"inject-in-tag": "^1.1.1", | ||
"nyc": "^6.4.0", | ||
"pify": "^2.3.0", | ||
"xo": "^0.17.0" | ||
"nyc": "^12.0.2", | ||
"pify": "^3.0.0", | ||
"xo": "^0.18.2" | ||
}, | ||
@@ -54,0 +54,0 @@ "peerDependencies": { |
@@ -42,2 +42,3 @@ # eslint-plugin-lodash-fp [![Build Status](https://travis-ci.org/jfmengels/eslint-plugin-lodash-fp.svg?branch=master)](https://travis-ci.org/jfmengels/eslint-plugin-lodash-fp) | ||
"lodash-fp/no-extraneous-iteratee-args": "error", | ||
"lodash-fp/no-extraneous-partials": "error", | ||
"lodash-fp/no-for-each": "off", | ||
@@ -82,2 +83,3 @@ "lodash-fp/no-partial-of-curried": "error", | ||
- [no-extraneous-function-wrapping](docs/rules/no-extraneous-function-wrapping.md) - Avoid unnecessary function wrapping. | ||
- [no-extraneous-partials](docs/rules/no-extraneous-partials.md) - Avoid unnecessary intermediate partials in curried methods. | ||
- [no-extraneous-iteratee-args](docs/rules/no-extraneous-iteratee-args.md) - No extraneous parameters in iteratees. | ||
@@ -110,5 +112,2 @@ - [no-for-each](docs/rules/no-for-each.md) - Forbid the use of [`_.forEach`](https://lodash.com/docs#forEach) | ||
"eslintConfig": { | ||
"plugins": [ | ||
"lodash-fp" | ||
], | ||
"extends": "plugin:lodash-fp/recommended" | ||
@@ -115,0 +114,0 @@ } |
@@ -14,3 +14,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isComposeMethod(node); | ||
@@ -17,0 +17,0 @@ if (method && method.name !== composeMethod) { |
@@ -12,3 +12,3 @@ 'use strict'; | ||
function hasDefaultSpecifier(node) { | ||
return node.specifiers.some(function (specifier) { | ||
return node.specifiers.some(specifier => { | ||
return specifier.type === 'ImportDefaultSpecifier'; | ||
@@ -25,3 +25,3 @@ }); | ||
return info.merge({ | ||
ImportDeclaration: function (node) { | ||
ImportDeclaration(node) { | ||
if (isLodash(node.source.value) && hasDefaultSpecifier(node)) { | ||
@@ -31,3 +31,3 @@ importNode = node; | ||
}, | ||
VariableDeclarator: function (node) { | ||
VariableDeclarator(node) { | ||
if (node.init && astUtils.isStaticRequire(node.init)) { | ||
@@ -39,7 +39,7 @@ if (isLodash(node.init.arguments[0].value)) { | ||
}, | ||
'Program:exit': function () { | ||
'Program:exit'() { | ||
const importValues = _.values(info.imports); | ||
if (// `lodash`/`lodash/fp` was imported | ||
(importValues.indexOf('') !== -1 || importValues.indexOf('fp') !== -1) && | ||
// but <expectedName> does not refer to either `lodash` or `lodash/fp` | ||
// But <expectedName> does not refer to either `lodash` or `lodash/fp` | ||
!info.helpers.isAnyLodash(expectedName) | ||
@@ -46,0 +46,0 @@ ) { |
@@ -66,3 +66,3 @@ 'use strict'; | ||
function isEquivalentExp(a, b) { | ||
return _.isEqualWith(function (left, right, key) { | ||
return _.isEqualWith((left, right, key) => { | ||
if (_.includes(key, ['loc', 'range', 'computed', 'start', 'end'])) { | ||
@@ -69,0 +69,0 @@ return true; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
const FOREACH_METHODS = ['forEach', 'forEachRight', 'each', 'eachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight']; | ||
const SIDE_EFFECT_METHODS = FOREACH_METHODS.concat(['bindAll']); | ||
const SIDE_EFFECT_METHODS = FOREACH_METHODS.concat(['bindAll', 'defer', 'delay']); | ||
@@ -8,0 +8,0 @@ module.exports = { |
@@ -30,7 +30,7 @@ 'use strict'; | ||
const predefinedRules = { | ||
ImportDeclaration: function (node) { | ||
ImportDeclaration(node) { | ||
const name = node.source.value; | ||
if (isLodashModule(name)) { | ||
const strippedName = stripLodash(name); | ||
node.specifiers.forEach(function (specifier) { | ||
node.specifiers.forEach(specifier => { | ||
if (specifier.type === 'ImportDefaultSpecifier') { | ||
@@ -50,3 +50,3 @@ // `import _ from 'lodash';` --> {'_': ''} | ||
}, | ||
VariableDeclarator: function (node) { | ||
VariableDeclarator(node) { | ||
if (node.init && astUtils.isStaticRequire(node.init)) { | ||
@@ -63,3 +63,3 @@ const name = node.init.arguments[0].value; | ||
} else if (node.id.type === 'ObjectPattern') { | ||
node.id.properties.forEach(function (prop) { | ||
node.id.properties.forEach(prop => { | ||
// `const {find, invoke: i} = require('lodash');` --> {'find': 'find', 'i': 'invoke'} | ||
@@ -66,0 +66,0 @@ // `const {find, invoke: i} = require('lodash/fp');` --> {'find': 'fp/find', 'i': 'fp/invoke'} |
@@ -9,4 +9,4 @@ 'use strict'; | ||
.map(_.parseInt(10)) | ||
.reduce(function (res, n) { | ||
mapping.aryMethod[n].forEach(function (name) { | ||
.reduce((res, n) => { | ||
mapping.aryMethod[n].forEach(name => { | ||
res[name] = n; | ||
@@ -22,3 +22,3 @@ }); | ||
return _.keys(mapping.iterateeAry) | ||
.reduce(function (res, name) { | ||
.reduce((res, name) => { | ||
const methodAry = ary[name]; | ||
@@ -25,0 +25,0 @@ const rearg = mapping.methodRearg[name] || mapping.aryRearg[methodAry]; |
@@ -47,3 +47,3 @@ 'use strict'; | ||
const findName = _.curry(function (methods, method) { | ||
const findName = _.curry((methods, method) => { | ||
return _.find(_.eq(method.name), _.isArray(methods) ? methods : [methods]) && method; | ||
@@ -88,3 +88,3 @@ }); | ||
const isMethodOf = _.curry(function (methods, node) { | ||
const isMethodOf = _.curry((methods, node) => { | ||
const method = isMethod(node); | ||
@@ -94,3 +94,3 @@ return method && findName(methods, method); | ||
const isAnyMethodOf = _.curry(function (methods, node) { | ||
const isAnyMethodOf = _.curry((methods, node) => { | ||
const method = isAnyMethod(node); | ||
@@ -104,3 +104,3 @@ return method && findName(methods, method); | ||
const isMethodCallOf = _.curry(function (methods, node) { | ||
const isMethodCallOf = _.curry((methods, node) => { | ||
const method = isMethodCall(node); | ||
@@ -111,3 +111,3 @@ return method && findName(methods, method); | ||
// Is `X.Y` a Lodash method? | ||
const isMember = _.curry(function (node) { | ||
const isMember = _.curry(node => { | ||
return isMemberExpression(node) && | ||
@@ -123,4 +123,4 @@ isIdentifier(node.object) && | ||
const getComposeMethodArgMethods = _.curry(function (name, node) { | ||
const methodNames = node.arguments.map(function (arg) { | ||
const getComposeMethodArgMethods = _.curry((name, node) => { | ||
const methodNames = node.arguments.map(arg => { | ||
return isMethodCall(arg) || isMember(arg); | ||
@@ -127,0 +127,0 @@ }); |
@@ -12,3 +12,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
if (node.arguments.length !== 0) { | ||
@@ -15,0 +15,0 @@ return; |
@@ -15,3 +15,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const callee = node.callee; | ||
@@ -18,0 +18,0 @@ if (isLodashWrap(helpers, callee) || info.helpers.isAnyMethodOf('chain', callee)) { |
@@ -30,3 +30,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isMethodCall(node); | ||
@@ -33,0 +33,0 @@ |
@@ -36,5 +36,5 @@ 'use strict'; | ||
if (callExpression.type !== 'CallExpression' || | ||
// or if `lastArgName` is used somewhere else in the function | ||
// Or if `lastArgName` is used somewhere else in the function | ||
astUtils.containsIdentifier(lastArgName, callExpression.callee) || | ||
// or in `lastArgName` is used among the other arguments | ||
// Or in `lastArgName` is used among the other arguments | ||
astUtils.someContainIdentifier(lastArgName, _.initial(callExpression.arguments)) | ||
@@ -67,3 +67,3 @@ ) { | ||
return info.merge({ | ||
FunctionDeclaration: function (node) { | ||
FunctionDeclaration(node) { | ||
if (isExtraneous(info, node)) { | ||
@@ -73,8 +73,8 @@ context.report(node, errorMessage); | ||
}, | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
node.arguments | ||
.filter(function (argNode) { | ||
.filter(argNode => { | ||
return isExtraneous(info, argNode); | ||
}) | ||
.forEach(function (arg) { | ||
.forEach(arg => { | ||
context.report(arg, errorMessage); | ||
@@ -81,0 +81,0 @@ }); |
@@ -18,3 +18,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isMethodCall(node); | ||
@@ -21,0 +21,0 @@ if (!method) { |
@@ -14,3 +14,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isForEachMethod(node); | ||
@@ -17,0 +17,0 @@ if (method) { |
@@ -9,3 +9,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isMethodCallOf(['partial', 'partialRight'], node); | ||
@@ -12,0 +12,0 @@ if (!method || node.arguments.length === 0) { |
@@ -10,3 +10,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isComposeMethod(node); | ||
@@ -13,0 +13,0 @@ if (!method || node.arguments.length > 1 || _.get([0, 'type'], node.arguments) === 'SpreadElement') { |
@@ -26,3 +26,3 @@ 'use strict'; | ||
return info.merge({ | ||
ImportDeclaration: function (node) { | ||
ImportDeclaration(node) { | ||
if (isLodashSubModule(node.source.value)) { | ||
@@ -35,3 +35,3 @@ const importSpecifier = _.find(isImportSpecifier, node.specifiers); | ||
}, | ||
VariableDeclarator: function (node) { | ||
VariableDeclarator(node) { | ||
if (node.init && isObjectPattern(node.id) && isRequireOfLodashSubModule(node.init)) { | ||
@@ -38,0 +38,0 @@ context.report(node.init, errorMessage); |
@@ -27,3 +27,3 @@ 'use strict'; | ||
return info.merge({ | ||
ExpressionStatement: function (node) { | ||
ExpressionStatement(node) { | ||
const method = isMethodCall(info, node.expression); | ||
@@ -30,0 +30,0 @@ if (method && !isForEach(method)) { |
@@ -21,3 +21,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
if (isFilterWithIdentity(node)) { | ||
@@ -24,0 +24,0 @@ context.report(node, 'Prefer `_.compact` over `_.filter` with identity function'); |
@@ -36,3 +36,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isComposeMethod(node); | ||
@@ -43,3 +43,3 @@ if (!method) { | ||
const methods = info.helpers.getComposeMethodArgMethods(method.name, node); | ||
consecutiveOperations(methods).forEach(function (operation) { | ||
consecutiveOperations(methods).forEach(operation => { | ||
context.report(node, errorMessage(operation)); | ||
@@ -46,0 +46,0 @@ }); |
@@ -34,3 +34,3 @@ 'use strict'; | ||
FunctionDeclaration: handleFunctionExpression, | ||
ArrowFunctionExpression: function (node) { | ||
ArrowFunctionExpression(node) { | ||
if (shouldCheckArrowFunctions) { | ||
@@ -37,0 +37,0 @@ handleFunctionExpression(node); |
@@ -46,3 +46,3 @@ 'use strict'; | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
if (isDirectCall(node) || isCompositionCall(info, node)) { | ||
@@ -49,0 +49,0 @@ context.report(node, 'Prefer `_.flatMap` over consecutive `_.map` and `_.flatten`'); |
@@ -24,3 +24,3 @@ 'use strict'; | ||
return { | ||
LogicalExpression: function (node) { | ||
LogicalExpression(node) { | ||
const state = getState(); | ||
@@ -36,3 +36,3 @@ const rightMemberExp = astUtil.isEqEqEq(node.right) && state.depth === 0 ? node.right.left : node.right; | ||
}, | ||
'LogicalExpression:exit': function (node) { | ||
'LogicalExpression:exit'(node) { | ||
const state = getState(); | ||
@@ -39,0 +39,0 @@ if (state && state.node === node.right.object) { |
@@ -18,3 +18,3 @@ 'use strict'; | ||
FunctionDeclaration: handleFunctionExpression, | ||
ArrowFunctionExpression: function (node) { | ||
ArrowFunctionExpression(node) { | ||
if (shouldCheckArrowFunctions) { | ||
@@ -21,0 +21,0 @@ handleFunctionExpression(node); |
@@ -8,8 +8,8 @@ 'use strict'; | ||
function checkOverrides(overrides) { | ||
overrides.map(function (override) { | ||
overrides.map(override => { | ||
return { | ||
override: override, | ||
override, | ||
target: data.aliasToReal[override] || override | ||
}; | ||
}).reduce(function (res, item) { | ||
}).reduce((res, item) => { | ||
if (res[item.target]) { | ||
@@ -34,3 +34,3 @@ throw new Error(`\`override\` contains \`${res[item.target]}\` and \`${item.override}\` that target \`${item.target}\``); | ||
return info.merge({ | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
const method = info.helpers.isMethodCall(node); | ||
@@ -37,0 +37,0 @@ if (!method) { |
@@ -18,6 +18,6 @@ 'use strict'; | ||
return info.merge({ | ||
ImportDeclaration: function (node) { | ||
ImportDeclaration(node) { | ||
reportIfLodashButNotFp(context, node, node.source.value); | ||
}, | ||
CallExpression: function (node) { | ||
CallExpression(node) { | ||
if (astUtils.isStaticRequire(node)) { | ||
@@ -24,0 +24,0 @@ reportIfLodashButNotFp(context, node, node.arguments[0].value); |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
52630
31
1223
2
118
2
+ Added@eslint-community/regexpp@4.10.1(transitive)
+ Added@eslint/config-array@0.16.0(transitive)
+ Added@eslint/js@9.5.0(transitive)
+ Addedeslint@9.5.0(transitive)
+ Addedreq-all@1.0.0(transitive)
- Removed@eslint-community/regexpp@4.11.0(transitive)
- Removed@eslint/config-array@0.17.0(transitive)
- Removed@eslint/js@9.6.0(transitive)
- Removedeslint@9.6.0(transitive)
- Removedreq-all@0.1.0(transitive)
Updatedreq-all@^1.0.0