eslint-plugin-lodash
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -11,4 +11,13 @@ # Change Log | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v1.2.0...HEAD | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v1.2.1...HEAD | ||
## [1.2.1] - 2016-02-25 | ||
### Fixed | ||
- Fixed rules `prefer-get`, `prefer-matches`, and `prefer-is-nil` that stopped reporting in ESLint v2. ([`5054431`][5054431]); | ||
[5054431]: https://github.com/wix/eslint-plugin-lodash/commit/50544315414c01980cf1580b8f28f3d1324287a7 | ||
[1.2.1]: https://github.com/wix/eslint-plugin-lodash/compare/v1.2.1...v1.2.0 | ||
## [1.2.0] - 2016-02-24 | ||
@@ -15,0 +24,0 @@ ### Fixed |
@@ -18,8 +18,4 @@ /** | ||
function isCallToLodashMatchesProperty(iteratee) { | ||
return lodashUtil.isLodashCall(iteratee, settings.pragma) && lodashUtil.isCallToMethod(iteratee, settings.version, 'matchesProperty'); | ||
} | ||
function canUseShorthand(iteratee) { | ||
return isFunctionDeclarationThatCanUseShorthand(iteratee) || isCallToLodashMatchesProperty(iteratee); | ||
return isFunctionDeclarationThatCanUseShorthand(iteratee) || lodashUtil.isLodashCallToMethod(iteratee, settings, 'matchesProperty'); | ||
} | ||
@@ -26,0 +22,0 @@ |
@@ -50,8 +50,4 @@ /** | ||
function isCallToLodashMatches(iteratee) { | ||
return lodashUtil.isLodashCall(iteratee, settings.pragma) && lodashUtil.isCallToMethod(iteratee, settings.version, 'matches'); | ||
} | ||
function canUseShorthand(iteratee) { | ||
return isFunctionDeclarationThatCanUseShorthand(iteratee) || isCallToLodashMatches(iteratee); | ||
return isFunctionDeclarationThatCanUseShorthand(iteratee) || lodashUtil.isLodashCallToMethod(iteratee, settings, 'matches'); | ||
} | ||
@@ -58,0 +54,0 @@ |
@@ -15,10 +15,6 @@ /** | ||
function isCallToLodashMap(node) { | ||
return lodashUtil.isLodashCall(node, settings.pragma) && lodashUtil.isCallToMethod(node, settings.version, 'map'); | ||
} | ||
return { | ||
CallExpression: lodashUtil.getLodashMethodVisitor(settings, function (node) { | ||
if (lodashUtil.isCallToMethod(node, settings.version, 'flatten') && | ||
(lodashUtil.isCallToMethod(astUtil.getCaller(node), settings.version, 'map') || isCallToLodashMap(node.arguments[0]))) { | ||
(lodashUtil.isCallToMethod(astUtil.getCaller(node), settings.version, 'map') || lodashUtil.isLodashCallToMethod(node.arguments[0], settings, 'map'))) { | ||
context.report(node, 'Prefer _.flatMap over consecutive map and flatten.'); | ||
@@ -25,0 +21,0 @@ } |
@@ -14,34 +14,34 @@ /** | ||
var settings = require('../util/settingsUtil').getSettings(context); | ||
var _ = require('lodash'); | ||
var nilChecks = { | ||
null: { | ||
isValue: function isNullLiteral(node) { | ||
return node.type === 'Literal' && node.value === null; | ||
}, | ||
expressionChecks: [getLodashTypeChecked.bind(null, 'isNull'), getValueComparedToNil.bind(null, 'null')] | ||
isValue: _.matches({type: 'Literal', value: null}), | ||
expressionChecks: [getLodashTypeCheckedBy('isNull'), getValueComparedTo('null')] | ||
}, | ||
undefined: { | ||
isValue: function isUndefinedIdentifier(node) { | ||
return node.type === 'Identifier' && node.name === 'undefined'; | ||
}, | ||
expressionChecks: [getLodashTypeChecked.bind(null, 'isUndefined'), getValueComparedToNil.bind(null, 'undefined'), getValueWithTypeofUndefinedComparison] | ||
isValue: _.matches({type: 'Identifier', name: 'undefined'}), | ||
expressionChecks: [getLodashTypeCheckedBy('isUndefined'), getValueComparedTo('undefined'), getValueWithTypeofUndefinedComparison] | ||
} | ||
}; | ||
function getLodashTypeChecked(typecheck, node) { | ||
return lodashUtil.isLodashCall(node, settings.pragma) && lodashUtil.isCallToMethod(node, settings.version, typecheck) && node.arguments[0]; | ||
function getLodashTypeCheckedBy(typecheck) { | ||
return function (node) { | ||
return lodashUtil.isLodashCallToMethod(node, settings, typecheck) && node.arguments[0]; | ||
}; | ||
} | ||
function getValueComparedToNil(nil, node, operator) { | ||
return node.type === 'BinaryExpression' && node.operator === operator && | ||
((nilChecks[nil].isValue(node.right) && node.left) || (nilChecks[nil].isValue(node.left) && node.right)); | ||
function getValueComparedTo(nil) { | ||
return function (node, operator) { | ||
return node.type === 'BinaryExpression' && node.operator === operator && | ||
((nilChecks[nil].isValue(node.right) && node.left) || (nilChecks[nil].isValue(node.left) && node.right)); | ||
}; | ||
} | ||
function getTypeofArgument(node) { | ||
return node.type === 'UnaryExpression' && node.operator === 'typeof' && node.argument; | ||
} | ||
function isUndefinedString(node) { | ||
return node.type === 'Literal' && node.value === 'undefined'; | ||
} | ||
var getTypeofArgument = _.cond([ | ||
[_.matches({type: 'UnaryExpression', operator: 'typeof'}), _.property('argument')] | ||
]); | ||
var isUndefinedString = _.matches({type: 'Literal', value: 'undefined'}); | ||
function getValueWithTypeofUndefinedComparison(node, operator) { | ||
@@ -54,8 +54,7 @@ return node.type === 'BinaryExpression' && node.operator === operator && | ||
function checkExpression(nil, operator, node) { | ||
var valueCompared; | ||
nilChecks[nil].expressionChecks.some(function (check) { | ||
valueCompared = check(node, operator); | ||
return valueCompared; | ||
}); | ||
return valueCompared; | ||
return _(nilChecks[nil].expressionChecks) | ||
.map(function (check) { | ||
return check(node, operator); | ||
}) | ||
.find(); | ||
} | ||
@@ -62,0 +61,0 @@ |
@@ -20,10 +20,6 @@ /** | ||
function isCallToProperty(node) { | ||
return lodashUtil.isLodashCall(node, settings.pragma) && lodashUtil.isCallToMethod(node, settings.version, 'property'); | ||
function canUseShorthand(iteratee) { | ||
return lodashUtil.isLodashCallToMethod(iteratee, settings, 'property') || isExplicitParamFunction(iteratee); | ||
} | ||
function canUseShorthand(node) { | ||
return isCallToProperty(node) || isExplicitParamFunction(node); | ||
} | ||
function usesShorthand(node, iteratee) { | ||
@@ -30,0 +26,0 @@ return iteratee && iteratee.type === 'Literal' && !node.arguments[node.arguments.indexOf(iteratee) + 1]; |
@@ -9,5 +9,3 @@ 'use strict'; | ||
*/ | ||
function getCaller(node) { | ||
return _.get(node, 'callee.object'); | ||
} | ||
var getCaller = _.property(['callee', 'object']); | ||
@@ -19,5 +17,3 @@ /** | ||
*/ | ||
function getMethodName(node) { | ||
return _.get(node, 'callee.property.name'); | ||
} | ||
var getMethodName = _.property(['callee', 'property', 'name']); | ||
@@ -27,7 +23,5 @@ /** | ||
* @param {Object} node | ||
* @returns {boolean|undefined} | ||
* @returns {boolean} | ||
*/ | ||
function isMethodCall(node) { | ||
return node && node.type === 'CallExpression' && node.callee.type === 'MemberExpression'; | ||
} | ||
var isMethodCall = _.matches({type: 'CallExpression', callee: {type: 'MemberExpression'}}); | ||
@@ -39,5 +33,6 @@ /** | ||
*/ | ||
function isFunctionDefinitionWithBlock(node) { | ||
return (node.type === 'FunctionExpression' || (node.type === 'ArrowFunctionExpression' && node.body.type === 'BlockStatement')); | ||
} | ||
var isFunctionDefinitionWithBlock = _.overSome( | ||
_.matchesProperty('type', 'FunctionExpression'), | ||
_.matches({type: 'ArrowFunctionExpression', body: {type: 'BlockStatement'}}) | ||
); | ||
@@ -47,15 +42,8 @@ /** | ||
* @param {Object} node | ||
* @returns {node|null} | ||
* @returns {node|undefined} | ||
*/ | ||
function getFirstFunctionLine(node) { | ||
if (node) { | ||
if (isFunctionDefinitionWithBlock(node)) { | ||
return _.get(node, 'body.body[0]'); | ||
} | ||
if (node.type === 'ArrowFunctionExpression') { | ||
return node.body; | ||
} | ||
} | ||
return null; | ||
} | ||
var getFirstFunctionLine = _.cond([ | ||
[isFunctionDefinitionWithBlock, _.property(['body', 'body', 0])], | ||
[_.matches({type: 'ArrowFunctionExpression'}), _.property('body')] | ||
]); | ||
@@ -67,7 +55,3 @@ /** | ||
*/ | ||
function isPropAccess(node) { | ||
return node && | ||
node.computed === false || | ||
(node.computed === true && node.property.type === 'Literal'); | ||
} | ||
var isPropAccess = _.overSome(_.matches({computed: false}), _.matchesProperty(['property', 'type'], 'Literal')); | ||
@@ -101,5 +85,3 @@ /** | ||
*/ | ||
function getFirstParamName(func) { | ||
return _.get(func, 'params[0].name'); | ||
} | ||
var getFirstParamName = _.property(['params', 0, 'name']); | ||
@@ -111,5 +93,3 @@ /** | ||
*/ | ||
function isReturnStatement(exp) { | ||
return exp && exp.type === 'ReturnStatement'; | ||
} | ||
var isReturnStatement = _.matchesProperty('type', 'ReturnStatement'); | ||
@@ -155,5 +135,3 @@ /** | ||
*/ | ||
function isNegationExpression(exp) { | ||
return exp && exp.type === 'UnaryExpression' && exp.operator === '!'; | ||
} | ||
var isNegationExpression = _.matches({type: 'UnaryExpression', operator: '!'}); | ||
@@ -226,3 +204,3 @@ /** | ||
return _.isEqualWith(a, b, function (left, right, key) { | ||
if (_.includes(['loc', 'range', 'computed'], key)) { | ||
if (_.includes(['loc', 'range', 'computed', 'start', 'end'], key)) { | ||
return true; | ||
@@ -246,5 +224,3 @@ } | ||
*/ | ||
function isEqEqEq(node) { | ||
return node && node.type === 'BinaryExpression' && node.operator === '==='; | ||
} | ||
var isEqEqEq = _.matches({type: 'BinaryExpression', operator: '==='}); | ||
@@ -251,0 +227,0 @@ module.exports = { |
@@ -222,2 +222,6 @@ 'use strict'; | ||
function isLodashCallToMethod(node, settings, method) { | ||
return isLodashCall(node, settings.pragma) && isCallToMethod(node, settings.version, method); | ||
} | ||
module.exports = { | ||
@@ -232,2 +236,3 @@ isLodashCall: isLodashCall, | ||
isCallToMethod: isCallToMethod, | ||
isLodashCallToMethod: isLodashCallToMethod, | ||
isLodashWrapperMethod: isLodashWrapperMethod, | ||
@@ -234,0 +239,0 @@ getIsTypeMethod: getIsTypeMethod, |
@@ -12,2 +12,3 @@ 'use strict'; | ||
.get(['settings', 'lodash']) | ||
.clone() | ||
.defaults({ | ||
@@ -14,0 +15,0 @@ pragma: '_', |
{ | ||
"name": "eslint-plugin-lodash", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": "Omer Ganim <ganimomer@gmail.com>", | ||
@@ -26,10 +26,10 @@ "description": "Lodash specific linting rules for ESLint", | ||
"dependencies": { | ||
"lodash": "4.0.0" | ||
"lodash": "4.5.1" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "2.11.4", | ||
"eslint": "1.9.0", | ||
"eslint-config-wix-editor": "0.1.1", | ||
"istanbul": "0.4.0", | ||
"mocha": "2.3.3" | ||
"coveralls": "2.11.6", | ||
"eslint": "2.2.0", | ||
"eslint-config-wix-editor": "0.2.2", | ||
"istanbul": "0.4.2", | ||
"mocha": "2.4.5" | ||
}, | ||
@@ -36,0 +36,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117696
2788
+ Addedlodash@4.5.1(transitive)
- Removedlodash@4.0.0(transitive)
Updatedlodash@4.5.1