eslint-plugin-lodash
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -11,4 +11,11 @@ # Change Log | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v1.4.2...HEAD | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v1.5.0...HEAD | ||
## [1.5.0] - 2016-03-28 | ||
### Added | ||
- Added rule [`prefer-includes`][prefer-includes]. ([`d619539`][d619539]) | ||
[d619539]: https://github.com/wix/eslint-plugin-lodash/commit/d619539e98f6f5e4d0c7f13012e8f92b49431636 | ||
[1.5.0]: https://github.com/wix/eslint-plugin-lodash/compare/v1.5.0...v1.4.2 | ||
## [1.4.2] - 2016-03-20 | ||
@@ -197,2 +204,3 @@ ### Fixed | ||
[identity-shorthand]: docs/rules/identity-shorthand.md | ||
[prefer-includes]: docs/rules/prefer-includes.md | ||
@@ -199,0 +207,0 @@ <!-- |
@@ -21,3 +21,3 @@ /** | ||
var callExpressionReporters = { | ||
3: function (node, iteratee) { | ||
3: function _(node, iteratee) { | ||
if (isBound(iteratee)) { | ||
@@ -27,6 +27,6 @@ context.report(iteratee.callee.property, 'Unnecessary bind, pass `thisArg` to lodash method instead'); | ||
}, | ||
4: function (node, iteratee) { | ||
4: function _(node, iteratee) { | ||
var isTransformerMethod = transformerMethods.some(lodashUtil.isCallToMethod.bind(null, node, settings.version)); | ||
var iterateeIndex = node.arguments.indexOf(iteratee); | ||
if (iterateeIndex !== -1 && (isTransformerMethod && node.arguments[iterateeIndex + 2] || (!isTransformerMethod && node.arguments[iterateeIndex + 1]))) { | ||
if (iterateeIndex !== -1 && (isTransformerMethod && node.arguments[iterateeIndex + 2] || !isTransformerMethod && node.arguments[iterateeIndex + 1])) { | ||
context.report(iteratee, 'Do not use Lodash 3 thisArg, use binding instead'); | ||
@@ -40,2 +40,2 @@ } | ||
}; | ||
}; | ||
}; |
@@ -9,2 +9,3 @@ /** | ||
//------------------------------------------------------------------------------ | ||
module.exports = function (context) { | ||
@@ -15,3 +16,3 @@ var lodashUtil = require('../util/lodashUtil'); | ||
var callExpressionVisitors = { | ||
'as-needed': function (node) { | ||
'as-needed': function asNeeded(node) { | ||
if (lodashUtil.isExplicitChainStart(node, settings.pragma)) { | ||
@@ -31,3 +32,3 @@ var curr = node.parent.parent; | ||
}, | ||
implicit: function (node) { | ||
implicit: function implicit(node) { | ||
if (lodashUtil.isExplicitChainStart(node, settings.pragma)) { | ||
@@ -37,3 +38,3 @@ context.report(node, 'Do not use explicit chaining'); | ||
}, | ||
explicit: function (node) { | ||
explicit: function explicit(node) { | ||
if (lodashUtil.isImplicitChainStart(node, settings.pragma)) { | ||
@@ -50,6 +51,4 @@ context.report(node, 'Do not use implicit chaining'); | ||
module.exports.schema = [ | ||
{ | ||
enum: ['as-needed', 'implicit', 'explicit'] | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
enum: ['as-needed', 'implicit', 'explicit'] | ||
}]; |
@@ -29,3 +29,3 @@ /** | ||
if (node.parent.type === 'CallExpression' && lodashUtil.isLodashCollectionMethod(node.parent, settings.pragma, settings.version)) { | ||
callStack.push({node: node.parent}); | ||
callStack.push({ node: node.parent }); | ||
} | ||
@@ -35,14 +35,15 @@ } | ||
return { | ||
FunctionExpression: function (node) { | ||
FunctionExpression: function FunctionExpression(node) { | ||
addToCallStackIfCollectionMethod(node); | ||
callStack.push({node: node, found: false}); | ||
callStack.push({ node: node, found: false }); | ||
}, | ||
'FunctionExpression:exit': handleExitOfFunctionWithBlock, | ||
ArrowFunctionExpression: function (node) { | ||
ArrowFunctionExpression: function ArrowFunctionExpression(node) { | ||
addToCallStackIfCollectionMethod(node); | ||
if (node.body.type === 'BlockStatement') { | ||
callStack.push({node: node, found: false}); | ||
callStack.push({ node: node, found: false }); | ||
} | ||
}, | ||
'ArrowFunctionExpression:exit': function (node) { | ||
'ArrowFunctionExpression:exit': function ArrowFunctionExpressionExit(node) { | ||
var last = _.last(callStack); | ||
@@ -53,3 +54,3 @@ if (last && last.node === node) { | ||
}, | ||
ReturnStatement: function () { | ||
ReturnStatement: function ReturnStatement() { | ||
var last = _.last(callStack); | ||
@@ -60,3 +61,3 @@ if (last) { | ||
}, | ||
'CallExpression:exit': function (node) { | ||
'CallExpression:exit': function CallExpressionExit(node) { | ||
var last = _.last(callStack); | ||
@@ -68,2 +69,2 @@ if (last && last.node === node) { | ||
}; | ||
}; | ||
}; |
@@ -10,3 +10,2 @@ /** | ||
module.exports = function (context) { | ||
@@ -18,3 +17,2 @@ var _ = require('lodash'); | ||
function isExplicitIdentityFunction(iteratee) { | ||
@@ -27,7 +25,7 @@ var firstParamName = astUtil.getFirstParamName(iteratee); | ||
type: 'MemberExpression', | ||
object: {name: settings.pragma}, | ||
property: {name: 'identity'} | ||
object: { name: settings.pragma }, | ||
property: { name: 'identity' } | ||
}); | ||
var canUseIdentityShorthand = _.overSome(isExplicitIdentityFunction, isLodashIdentityFunction); | ||
var canUseShorthand = _.overSome(isExplicitIdentityFunction, isLodashIdentityFunction); | ||
@@ -40,3 +38,3 @@ function usesShorthand(node, iteratee) { | ||
CallExpression: lodashUtil.getShorthandVisitor(context, settings, { | ||
canUseShorthand: canUseIdentityShorthand, | ||
canUseShorthand: canUseShorthand, | ||
usesShorthand: usesShorthand | ||
@@ -50,6 +48,4 @@ }, { | ||
module.exports.schema = [ | ||
{ | ||
enum: ['always', 'never'] | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
enum: ['always', 'never'] | ||
}]; |
@@ -9,2 +9,3 @@ /** | ||
// ------------------------------------------------------------------------------ | ||
module.exports = function (context) { | ||
@@ -28,6 +29,6 @@ var lodashUtil = require('../util/lodashUtil'); | ||
var matchesPropertyChecks = { | ||
3: function (node, iteratee) { | ||
3: function _(node, iteratee) { | ||
return iteratee && iteratee.type === 'Literal' && callHasExtraParamAfterIteratee(node, iteratee); | ||
}, | ||
4: function (node, iteratee) { | ||
4: function _(node, iteratee) { | ||
return iteratee && iteratee.type === 'ArrayExpression'; | ||
@@ -48,6 +49,4 @@ } | ||
module.exports.schema = [ | ||
{ | ||
enum: ['always', 'never'] | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
enum: ['always', 'never'] | ||
}]; |
@@ -18,8 +18,6 @@ /** | ||
var isConjunction = _.matches({type: 'LogicalExpression', operator: '&&'}); | ||
var isConjunction = _.matches({ type: 'LogicalExpression', operator: '&&' }); | ||
function canBeObjectLiteralWithShorthandProperty(node, paramName) { | ||
return settingsUtil.isEcmaFeatureOn(context, 'objectLiteralShorthandProperties') && astUtil.isEqEqEq(node) && | ||
(astUtil.isMemberExpOf(node.left, paramName, 1) && node.left.property.type === 'Identifier' && node.right.type === 'Identifier' && node.left.property.name === node.right.name || | ||
astUtil.isMemberExpOf(node.right, paramName, 1) && node.right.property.type === 'Identifier' && node.left.type === 'Identifier' && node.right.property.name === node.left.name); | ||
return settingsUtil.isEcmaFeatureOn(context, 'objectLiteralShorthandProperties') && astUtil.isEqEqEq(node) && (astUtil.isMemberExpOf(node.left, paramName, 1) && node.left.property.type === 'Identifier' && node.right.type === 'Identifier' && node.left.property.name === node.right.name || astUtil.isMemberExpOf(node.right, paramName, 1) && node.right.property.type === 'Identifier' && node.left.type === 'Identifier' && node.right.property.name === node.left.name); | ||
} | ||
@@ -31,3 +29,3 @@ | ||
var checkStack = [exp]; | ||
var curr; | ||
var curr = void 0; | ||
var allParamMemberEq = true; | ||
@@ -60,3 +58,2 @@ curr = checkStack.pop(); | ||
return { | ||
@@ -73,12 +70,9 @@ CallExpression: lodashUtil.getShorthandVisitor(context, settings, { | ||
module.exports.schema = [ | ||
{ | ||
enum: ['always', 'never'] | ||
}, | ||
{ | ||
type: 'integer', | ||
minimum: 1 | ||
}, { | ||
type: 'boolean' | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
enum: ['always', 'never'] | ||
}, { | ||
type: 'integer', | ||
minimum: 1 | ||
}, { | ||
type: 'boolean' | ||
}]; |
@@ -15,3 +15,3 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isLodashChainStart(node, settings.pragma)) { | ||
@@ -27,2 +27,2 @@ do { | ||
}; | ||
}; | ||
}; |
@@ -15,21 +15,23 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isImplicitChainStart(node, settings.pragma)) { | ||
do { | ||
node = node.parent.parent; | ||
} while (astUtil.isMethodCall(node) && !lodashUtil.isChainBreaker(node, settings.version)); | ||
var caller = astUtil.getCaller(node); | ||
if (astUtil.isMethodCall(node) && !lodashUtil.isChainable(caller, settings.version)) { | ||
context.report({ | ||
node: node, | ||
message: 'Do not use .value() after chain-ending method {{method}}', | ||
data: {method: astUtil.getMethodName(caller)}, | ||
fix: function (fixer) { | ||
return fixer.removeRange([caller.range[1], node.range[1]]); | ||
} | ||
}); | ||
} | ||
(function () { | ||
do { | ||
node = node.parent.parent; | ||
} while (astUtil.isMethodCall(node) && !lodashUtil.isChainBreaker(node, settings.version)); | ||
var caller = astUtil.getCaller(node); | ||
if (astUtil.isMethodCall(node) && !lodashUtil.isChainable(caller, settings.version)) { | ||
context.report({ | ||
node: node, | ||
message: 'Do not use .value() after chain-ending method {{method}}', | ||
data: { method: astUtil.getMethodName(caller) }, | ||
fix: function fix(fixer) { | ||
return fixer.removeRange([caller.range[1], node.range[1]]); | ||
} | ||
}); | ||
} | ||
})(); | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
@@ -28,3 +28,3 @@ /** | ||
message: 'Too many arguments passed to `{{method}}` (expected {{expectedArity}}).', | ||
data: {method: astUtil.getMethodName(node), expectedArity: expectedArity} | ||
data: { method: astUtil.getMethodName(node), expectedArity: expectedArity } | ||
}); | ||
@@ -34,2 +34,2 @@ } | ||
}; | ||
}; | ||
}; |
@@ -23,3 +23,3 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isLodashChainStart(node, settings.pragma)) { | ||
@@ -37,2 +37,2 @@ var firstCall = node.parent.parent; | ||
// JSON Schema for rule options goes here | ||
]; | ||
]; |
@@ -14,14 +14,11 @@ /** | ||
var objectPathMethods = { | ||
regular: {methods: ['get', 'has', 'hasIn', 'set', 'unset', 'invoke'], index: 1}, | ||
higherOrder: {methods: ['property', 'matchesProperty'], index: 0} | ||
regular: { methods: ['get', 'has', 'hasIn', 'set', 'unset', 'invoke'], index: 1 }, | ||
higherOrder: { methods: ['property', 'matchesProperty'], index: 0 } | ||
}; | ||
var _ = require('lodash'); | ||
function getIndexByMethodName(node) { | ||
return _.chain(objectPathMethods).find(function (type) { | ||
return type.methods.some(lodashUtil.isCallToMethod.bind(null, node, settings.version)); | ||
}) | ||
.get('index', -1) | ||
.value(); | ||
}).get('index', -1).value(); | ||
} | ||
@@ -49,15 +46,7 @@ | ||
var reportIfViolates = { | ||
'as-needed': _.cond([ | ||
[isLiteralComplexPath, reportMessage('Use an array for deep paths')], | ||
[isShallowPathInArray, reportMessage('Use a string for single-level paths')] | ||
]), | ||
array: _.cond([ | ||
[_.matches({type: 'Literal'}), reportMessage('Use an array for paths')] | ||
]), | ||
string: _.cond([ | ||
[_.matches({type: 'ArrayExpression'}), reportMessage('Use a string for paths')] | ||
]) | ||
'as-needed': _.cond([[isLiteralComplexPath, reportMessage('Use an array for deep paths')], [isShallowPathInArray, reportMessage('Use a string for single-level paths')]]), | ||
array: _.cond([[_.matches({ type: 'Literal' }), reportMessage('Use an array for paths')]]), | ||
string: _.cond([[_.matches({ type: 'ArrayExpression' }), reportMessage('Use a string for paths')]]) | ||
}; | ||
return { | ||
@@ -64,0 +53,0 @@ CallExpression: lodashUtil.getLodashMethodVisitor(settings, function (node) { |
@@ -22,3 +22,3 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (isNestedNLevels(node, ruleDepth)) { | ||
@@ -31,7 +31,5 @@ context.report(astUtil.getCaller(node.arguments[0]), 'Prefer chaining to composition'); | ||
module.exports.schema = [ | ||
{ | ||
type: 'integer', | ||
minimum: 2 | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
type: 'integer', | ||
minimum: 2 | ||
}]; |
@@ -25,5 +25,3 @@ /** | ||
var paramName = astUtil.getFirstParamName(func); | ||
return func && func.type === 'Identifier' && func.name === 'Boolean' || | ||
(astUtil.isIdentifierOfParam(returnValue, paramName) || | ||
isDoubleNegationOfParam(returnValue, paramName) || isCallToBooleanCastOfParam(returnValue, paramName)); | ||
return func && func.type === 'Identifier' && func.name === 'Boolean' || astUtil.isIdentifierOfParam(returnValue, paramName) || isDoubleNegationOfParam(returnValue, paramName) || isCallToBooleanCastOfParam(returnValue, paramName); | ||
} | ||
@@ -38,2 +36,2 @@ | ||
}; | ||
}; | ||
}; |
@@ -38,3 +38,3 @@ /** | ||
FunctionExpression: handleFunctionExpression, | ||
ArrowFunctionExpression: function (node) { | ||
ArrowFunctionExpression: function ArrowFunctionExpression(node) { | ||
if (shouldCheckArrowFunctions) { | ||
@@ -47,6 +47,4 @@ handleFunctionExpression(node); | ||
module.exports.schema = [ | ||
{ | ||
type: 'boolean' | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
type: 'boolean' | ||
}]; |
@@ -22,5 +22,3 @@ /** | ||
function canBeShorthand(exp, paramName) { | ||
return astUtil.isIdentifierOfParam(exp, paramName) || | ||
astUtil.isMemberExpOf(exp, paramName, maxPropertyPathLength) || astUtil.isNegationOfParamMember(exp, paramName, maxPropertyPathLength) || | ||
astUtil.isEqEqEqToMemberOf(exp, paramName, maxPropertyPathLength) || astUtil.isNotEqEqToMemberOf(exp, paramName, maxPropertyPathLength); | ||
return astUtil.isIdentifierOfParam(exp, paramName) || astUtil.isMemberExpOf(exp, paramName, maxPropertyPathLength) || astUtil.isNegationOfMemberOf(exp, paramName, maxPropertyPathLength) || astUtil.isEqEqEqToMemberOf(exp, paramName, maxPropertyPathLength) || astUtil.isNotEqEqToMemberOf(exp, paramName, maxPropertyPathLength); | ||
} | ||
@@ -42,6 +40,4 @@ | ||
module.exports.schema = [ | ||
{ | ||
type: 'integer' | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
type: 'integer' | ||
}]; |
@@ -17,4 +17,3 @@ /** | ||
CallExpression: lodashUtil.getLodashMethodVisitor(settings, function (node) { | ||
if (lodashUtil.isCallToMethod(node, settings.version, 'flatten') && | ||
(lodashUtil.isCallToMethod(astUtil.getCaller(node), settings.version, 'map') || lodashUtil.isLodashCallToMethod(node.arguments[0], settings, 'map'))) { | ||
if (lodashUtil.isCallToMethod(node, settings.version, 'flatten') && (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.'); | ||
@@ -21,0 +20,0 @@ } |
@@ -17,3 +17,3 @@ /** | ||
function getState() { | ||
return expStates[expStates.length - 1] || {depth: 0}; | ||
return expStates[expStates.length - 1] || { depth: 0 }; | ||
} | ||
@@ -26,3 +26,3 @@ | ||
return { | ||
LogicalExpression: function (node) { | ||
LogicalExpression: function LogicalExpression(node) { | ||
var state = getState(); | ||
@@ -32,3 +32,3 @@ var rightMemberExp = astUtil.isEqEqEq(node.right) && state.depth === 0 ? node.right.left : node.right; | ||
if (shouldCheckDeeper(node, rightMemberExp, state.node)) { | ||
expStates.push({depth: state.depth + 1, node: rightMemberExp.object}); | ||
expStates.push({ depth: state.depth + 1, node: rightMemberExp.object }); | ||
if (astUtil.isEquivalentExp(node.left, rightMemberExp.object) && state.depth >= ruleDepth - 2) { | ||
@@ -39,3 +39,3 @@ context.report(node, "Prefer _.get or _.has over an '&&' chain"); | ||
}, | ||
'LogicalExpression:exit': function (node) { | ||
'LogicalExpression:exit': function LogicalExpressionExit(node) { | ||
var state = getState(); | ||
@@ -49,7 +49,5 @@ if (state && state.node === node.right.object) { | ||
module.exports.schema = [ | ||
{ | ||
type: 'integer', | ||
minimum: 2 | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
type: 'integer', | ||
minimum: 2 | ||
}]; |
@@ -25,2 +25,2 @@ /** | ||
}; | ||
}; | ||
}; |
@@ -17,7 +17,7 @@ /** | ||
null: { | ||
isValue: _.matches({type: 'Literal', value: null}), | ||
isValue: _.matches({ type: 'Literal', value: null }), | ||
expressionChecks: [getLodashTypeCheckedBy('isNull'), getValueComparedTo('null')] | ||
}, | ||
undefined: { | ||
isValue: _.matches({type: 'Identifier', name: 'undefined'}), | ||
isValue: _.matches({ type: 'Identifier', name: 'undefined' }), | ||
expressionChecks: [getLodashTypeCheckedBy('isUndefined'), getValueComparedTo('undefined'), getValueWithTypeofUndefinedComparison] | ||
@@ -35,30 +35,22 @@ } | ||
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)); | ||
return node.type === 'BinaryExpression' && node.operator === operator && (nilChecks[nil].isValue(node.right) && node.left || nilChecks[nil].isValue(node.left) && node.right); | ||
}; | ||
} | ||
var getTypeofArgument = _.cond([[_.matches({ type: 'UnaryExpression', operator: 'typeof' }), _.property('argument')]]); | ||
var getTypeofArgument = _.cond([ | ||
[_.matches({type: 'UnaryExpression', operator: 'typeof'}), _.property('argument')] | ||
]); | ||
var isUndefinedString = _.matches({ type: 'Literal', value: 'undefined' }); | ||
var isUndefinedString = _.matches({type: 'Literal', value: 'undefined'}); | ||
function getValueWithTypeofUndefinedComparison(node, operator) { | ||
return node.type === 'BinaryExpression' && node.operator === operator && | ||
((isUndefinedString(node.right) && getTypeofArgument(node.left)) || | ||
(isUndefinedString(node.left) && getTypeofArgument(node.right))); | ||
return node.type === 'BinaryExpression' && node.operator === operator && (isUndefinedString(node.right) && getTypeofArgument(node.left) || isUndefinedString(node.left) && getTypeofArgument(node.right)); | ||
} | ||
function checkExpression(nil, operator, node) { | ||
return _(nilChecks[nil].expressionChecks) | ||
.map(function (check) { | ||
return check(node, operator); | ||
}) | ||
.find(); | ||
return _(nilChecks[nil].expressionChecks).map(function (check) { | ||
return check(node, operator); | ||
}).find(); | ||
} | ||
function checkNegatedExpression(nil, node) { | ||
return (astUtil.isNegationExpression(node) && checkExpression(nil, '===', node.argument)) || checkExpression(nil, '!==', node); | ||
return astUtil.isNegationExpression(node) && checkExpression(nil, '===', node.argument) || checkExpression(nil, '!==', node); | ||
} | ||
@@ -77,10 +69,8 @@ | ||
return { | ||
LogicalExpression: function (node) { | ||
LogicalExpression: function LogicalExpression(node) { | ||
if (node.operator === '||') { | ||
if (isEquivalentExistingExpression(node, 'undefined', 'null') || | ||
isEquivalentExistingExpression(node, 'null', 'undefined')) { | ||
if (isEquivalentExistingExpression(node, 'undefined', 'null') || isEquivalentExistingExpression(node, 'null', 'undefined')) { | ||
context.report(node, 'Prefer isNil over checking for undefined or null.'); | ||
} | ||
} else if (isEquivalentExistingNegation(node, 'undefined', 'null') || | ||
isEquivalentExistingNegation(node, 'null', 'undefined')) { | ||
} else if (isEquivalentExistingNegation(node, 'undefined', 'null') || isEquivalentExistingNegation(node, 'null', 'undefined')) { | ||
context.report(node, 'Prefer isNil over checking for undefined or null.'); | ||
@@ -90,2 +80,2 @@ } | ||
}; | ||
}; | ||
}; |
@@ -17,3 +17,3 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isLodashChainStart(node, settings.pragma)) { | ||
@@ -26,8 +26,8 @@ do { | ||
if (lodashUtil.isNativeCollectionMethodCall(callAfterChainBreak) || lodashUtil.isLodashWrapperMethod(callAfterChainBreak, settings.version)) { | ||
context.report({node: callAfterChainBreak, message: REPORT_MESSAGE, data: {method: astUtil.getMethodName(callAfterChainBreak)}}); | ||
context.report({ node: callAfterChainBreak, message: REPORT_MESSAGE, data: { method: astUtil.getMethodName(callAfterChainBreak) } }); | ||
} | ||
} | ||
} else if (lodashUtil.isLodashCall(node, settings.pragma)) { | ||
if (node.parent.type === 'MemberExpression' && astUtil.isMethodCall(node.parent.parent) && (lodashUtil.isNativeCollectionMethodCall(node.parent.parent))) { | ||
context.report({node: node.parent.parent, message: REPORT_MESSAGE, data: {method: astUtil.getMethodName(node.parent.parent)}}); | ||
if (node.parent.type === 'MemberExpression' && astUtil.isMethodCall(node.parent.parent) && lodashUtil.isNativeCollectionMethodCall(node.parent.parent)) { | ||
context.report({ node: node.parent.parent, message: REPORT_MESSAGE, data: { method: astUtil.getMethodName(node.parent.parent) } }); | ||
} | ||
@@ -37,2 +37,2 @@ } | ||
}; | ||
}; | ||
}; |
@@ -24,3 +24,3 @@ /** | ||
var callerName = _.get(node, 'callee.object.name'); | ||
return (callerName in staticMethods) && _.includes(staticMethods[callerName], astUtil.getMethodName(node)); | ||
return callerName in staticMethods && _.includes(staticMethods[callerName], astUtil.getMethodName(node)); | ||
} | ||
@@ -41,5 +41,5 @@ | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (!isRuleException(node) && canUseLodash(node) && !isUsingLodash(node)) { | ||
context.report(node, REPORT_MESSAGE, {method: astUtil.getMethodName(node)}); | ||
context.report(node, REPORT_MESSAGE, { method: astUtil.getMethodName(node) }); | ||
} | ||
@@ -50,14 +50,12 @@ } | ||
module.exports.schema = [ | ||
{ | ||
type: 'object', | ||
properties: { | ||
except: { | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
module.exports.schema = [{ | ||
type: 'object', | ||
properties: { | ||
except: { | ||
type: 'array', | ||
items: { | ||
type: 'string' | ||
} | ||
} | ||
} | ||
]; | ||
}]; |
@@ -42,3 +42,3 @@ /** | ||
return { | ||
BinaryExpression: function (node) { | ||
BinaryExpression: function BinaryExpression(node) { | ||
var typeofCompareType = getTypeofCompareType(node); | ||
@@ -53,3 +53,3 @@ if (typeofCompareType) { | ||
if (node.right.type === 'Identifier' && lodashEquivalent) { | ||
context.report(node, REPORT_MESSAGE, {method: lodashEquivalent, actual: '\'instanceof ' + node.right.name + '\''}); | ||
context.report(node, REPORT_MESSAGE, { method: lodashEquivalent, actual: '\'instanceof ' + node.right.name + '\'' }); | ||
} | ||
@@ -59,2 +59,2 @@ } | ||
}; | ||
}; | ||
}; |
@@ -27,2 +27,2 @@ /** | ||
}; | ||
}; | ||
}; |
@@ -18,8 +18,7 @@ /** | ||
function getState() { | ||
return expStates[expStates.length - 1] || {depth: 0}; | ||
return expStates[expStates.length - 1] || { depth: 0 }; | ||
} | ||
function isMemberExpOfNodeOrRightmost(node, toCompare) { | ||
return node.type === 'MemberExpression' && !astUtil.isComputed(node) && | ||
(!toCompare || astUtil.isEquivalentExp(node.object, toCompare)); | ||
return node.type === 'MemberExpression' && !astUtil.isComputed(node) && (!toCompare || astUtil.isEquivalentExp(node.object, toCompare)); | ||
} | ||
@@ -32,6 +31,6 @@ | ||
return { | ||
LogicalExpression: function (node) { | ||
LogicalExpression: function LogicalExpression(node) { | ||
var state = getState(); | ||
if (shouldCheckDeeper(node, state.node)) { | ||
expStates.push({depth: state.depth + 1, node: node.right.left.object}); | ||
expStates.push({ depth: state.depth + 1, node: node.right.left.object }); | ||
if (astUtil.isEquivalentExp(_.get(node, 'left.left.object'), _.get(node, 'right.left.object')) && state.depth >= ruleDepth - 2) { | ||
@@ -42,3 +41,3 @@ context.report(node, 'Prefer _.matches over conditions on the same object'); | ||
}, | ||
'LogicalExpression:exit': function (node) { | ||
'LogicalExpression:exit': function LogicalExpressionExit(node) { | ||
var state = getState(); | ||
@@ -52,7 +51,5 @@ if (state && state.node === _.get(node, 'right.left.object')) { | ||
module.exports.schema = [ | ||
{ | ||
type: 'integer', | ||
minimum: 2 | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
type: 'integer', | ||
minimum: 2 | ||
}]; |
@@ -23,2 +23,2 @@ /** | ||
}; | ||
}; | ||
}; |
@@ -32,3 +32,2 @@ /** | ||
function isOnlyParamInvocationsWithOperator(node, paramName, operator) { | ||
@@ -39,5 +38,3 @@ if (node.type === 'CallExpression') { | ||
if (node.type === 'LogicalExpression') { | ||
return node.operator === operator && | ||
isOnlyParamInvocationsWithOperator(node.left, paramName, operator) && | ||
isOnlyParamInvocationsWithOperator(node.right, paramName, operator); | ||
return node.operator === operator && isOnlyParamInvocationsWithOperator(node.left, paramName, operator) && isOnlyParamInvocationsWithOperator(node.right, paramName, operator); | ||
} | ||
@@ -61,4 +58,3 @@ } | ||
function reportIfDoubleFilterLiteral(node) { | ||
if (onlyPassesIdentifier(node) && astUtil.isObjectOfMethodCall(node) && | ||
isCallToConditionMethod(node.parent.parent) && onlyPassesIdentifier(node.parent.parent)) { | ||
if (onlyPassesIdentifier(node) && astUtil.isObjectOfMethodCall(node) && isCallToConditionMethod(node.parent.parent) && onlyPassesIdentifier(node.parent.parent)) { | ||
context.report(node, message, reportConstants['&&']); | ||
@@ -65,0 +61,0 @@ } |
@@ -20,4 +20,3 @@ /** | ||
var firstParamName = astUtil.getFirstParamName(func); | ||
return astUtil.isNegationOfParamMember(returnValue, firstParamName, maxPropertyPathLength) || | ||
astUtil.isNotEqEqToMemberOf(returnValue, firstParamName, maxPropertyPathLength); | ||
return astUtil.isNegationOfMemberOf(returnValue, firstParamName, maxPropertyPathLength) || astUtil.isNotEqEqToMemberOf(returnValue, firstParamName, maxPropertyPathLength); | ||
} | ||
@@ -34,6 +33,4 @@ | ||
module.exports.schema = [ | ||
{ | ||
type: 'integer' | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
type: 'integer' | ||
}]; |
@@ -12,22 +12,5 @@ /** | ||
var astUtil = require('../util/astUtil'); | ||
var comparisonOperators = ['==', '!=', '===', '!==']; | ||
function getExpressionComparedToZero(node) { | ||
if (comparisonOperators.indexOf(node.operator) !== -1) { | ||
if (node.right.value === 0) { | ||
return node.left; | ||
} | ||
if (node.left.value === 0) { | ||
return node.right; | ||
} | ||
} | ||
} | ||
function isIndexOfCall(node) { | ||
return astUtil.isMethodCall(node) && astUtil.getMethodName(node) === 'indexOf'; | ||
} | ||
return { | ||
BinaryExpression: function (node) { | ||
if (isIndexOfCall(getExpressionComparedToZero(node))) { | ||
BinaryExpression: function BinaryExpression(node) { | ||
if (astUtil.isIndexOfCall(astUtil.getExpressionComparedToValue(node, 0))) { | ||
context.report(node, 'Prefer _.startsWith instead of comparing indexOf() to 0'); | ||
@@ -37,2 +20,2 @@ } | ||
}; | ||
}; | ||
}; |
@@ -18,3 +18,3 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isLodashChainStart(node, settings.pragma) && isSingleArgumentFunctionCall(node.arguments[0])) { | ||
@@ -25,2 +25,2 @@ context.report(node, 'Prefer using thru instead of function call in chain start.'); | ||
}; | ||
}; | ||
}; |
@@ -16,3 +16,2 @@ /** | ||
function getObjectPatternProperties(node) { | ||
@@ -30,10 +29,7 @@ return _.flatMap(node.properties, function (prop) { | ||
var getParamNames = _.cond([ | ||
[_.matches({type: 'Identifier'}), _.property('name')], | ||
[_.matches({type: 'ObjectPattern'}), getObjectPatternProperties] | ||
]); | ||
var getParamNames = _.cond([[_.matches({ type: 'Identifier' }), _.property('name')], [_.matches({ type: 'ObjectPattern' }), getObjectPatternProperties]]); | ||
function handleFunctionExpression(node) { | ||
if (lodashUtil.isCallToMethod(node.parent, settings.version, 'map') && (lodashUtil.isLodashCall(node.parent, settings.pragma) || lodashUtil.isLodashWrapper(node.parent, settings.pragma, settings.version))) { | ||
callStack.push({func: node, params: _.flatMap(node.params, getParamNames), anyUsed: false}); | ||
callStack.push({ func: node, params: _.flatMap(node.params, getParamNames), anyUsed: false }); | ||
} | ||
@@ -55,7 +51,6 @@ } | ||
ArrowFunctionExpression: handleFunctionExpression, | ||
Identifier: function (node) { | ||
Identifier: function Identifier(node) { | ||
var state = _.last(callStack); | ||
if (state) { | ||
var isIterateeParamDefinition = (node.parent === state.func && _.includes(node.parent.params, node)) || | ||
(node.parent.type === 'AssignmentPattern' && node.parent.parent === state.func); | ||
var isIterateeParamDefinition = node.parent === state.func && _.includes(node.parent.params, node) || node.parent.type === 'AssignmentPattern' && node.parent.parent === state.func; | ||
if (!isIterateeParamDefinition && _.includes(state.params, node.name)) { | ||
@@ -66,5 +61,6 @@ state.anyUsed = true; | ||
}, | ||
'FunctionExpression:exit': handleExitFunctionExpression, | ||
'ArrowFunctionExpression:exit': handleExitFunctionExpression | ||
}; | ||
}; | ||
}; |
@@ -14,8 +14,8 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isLodashChainStart(node, settings.pragma) && lodashUtil.isLodashWrapperMethod(node.arguments[0], settings.version)) { | ||
context.report(node, 'Prefer {{name}} with wrapper method over inside the chain start.', {name: node.arguments[0].callee.property.name}); | ||
context.report(node, 'Prefer {{name}} with wrapper method over inside the chain start.', { name: node.arguments[0].callee.property.name }); | ||
} | ||
} | ||
}; | ||
}; | ||
}; |
@@ -18,8 +18,5 @@ /** | ||
var expandedAliases = _.reduce(aliases, function (result, aliasesForKey, key) { | ||
var mapToMainKey = _(aliasesForKey) | ||
.map(function (alias) { | ||
return [alias, key]; | ||
}) | ||
.fromPairs() | ||
.value(); | ||
var mapToMainKey = _(aliasesForKey).map(function (alias) { | ||
return [alias, key]; | ||
}).fromPairs().value(); | ||
return _.assign(result, mapToMainKey); | ||
@@ -39,3 +36,3 @@ }, {}); | ||
}, | ||
fix: function (fixer) { | ||
fix: function fix(fixer) { | ||
return fixer.replaceText(node.callee.property, expandedAliases[methodName]); | ||
@@ -47,3 +44,2 @@ } | ||
}; | ||
} | ||
; | ||
}; |
@@ -10,3 +10,2 @@ /** | ||
module.exports = function (context) { | ||
@@ -40,6 +39,4 @@ var lodashUtil = require('../util/lodashUtil'); | ||
module.exports.schema = [ | ||
{ | ||
enum: ['always', 'never'] | ||
} | ||
]; | ||
module.exports.schema = [{ | ||
enum: ['always', 'never'] | ||
}]; |
@@ -20,3 +20,3 @@ /** | ||
return { | ||
CallExpression: function (node) { | ||
CallExpression: function CallExpression(node) { | ||
if (lodashUtil.isEndOfChain(node, settings.pragma, settings.version) && (!isEvaluatedWhenLazy(node) || isExplicitChainWithoutBreaker(node))) { | ||
@@ -27,2 +27,2 @@ context.report(node, 'Missing unwrapping at end of chain'); | ||
}; | ||
}; | ||
}; |
'use strict'; | ||
var _ = require('lodash'); | ||
@@ -23,3 +24,3 @@ | ||
*/ | ||
var isMethodCall = _.matches({type: 'CallExpression', callee: {type: 'MemberExpression'}}); | ||
var isMethodCall = _.matches({ type: 'CallExpression', callee: { type: 'MemberExpression' } }); | ||
@@ -31,6 +32,3 @@ /** | ||
*/ | ||
var isFunctionDefinitionWithBlock = _.overSome( | ||
_.matchesProperty('type', 'FunctionExpression'), | ||
_.matches({type: 'ArrowFunctionExpression', body: {type: 'BlockStatement'}}) | ||
); | ||
var isFunctionDefinitionWithBlock = _.overSome(_.matchesProperty('type', 'FunctionExpression'), _.matches({ type: 'ArrowFunctionExpression', body: { type: 'BlockStatement' } })); | ||
@@ -42,6 +40,3 @@ /** | ||
*/ | ||
var getFirstFunctionLine = _.cond([ | ||
[isFunctionDefinitionWithBlock, _.property(['body', 'body', 0])], | ||
[_.matches({type: 'ArrowFunctionExpression'}), _.property('body')] | ||
]); | ||
var getFirstFunctionLine = _.cond([[isFunctionDefinitionWithBlock, _.property(['body', 'body', 0])], [_.matches({ type: 'ArrowFunctionExpression' }), _.property('body')]]); | ||
@@ -53,3 +48,3 @@ /** | ||
*/ | ||
var isPropAccess = _.overSome(_.matches({computed: false}), _.matchesProperty(['property', 'type'], 'Literal')); | ||
var isPropAccess = _.overSome(_.matches({ computed: false }), _.matchesProperty(['property', 'type'], 'Literal')); | ||
@@ -120,8 +115,5 @@ /** | ||
function isBinaryExpWithMemberOf(operator, exp, objectName, maxPropertyPathLength, allowComputed) { | ||
return exp && exp.type === 'BinaryExpression' && exp.operator === operator && | ||
(isMemberExpOf(exp.left, objectName, maxPropertyPathLength, allowComputed) || | ||
isMemberExpOf(exp.right, objectName, maxPropertyPathLength, allowComputed)); | ||
return exp && exp.type === 'BinaryExpression' && exp.operator === operator && (isMemberExpOf(exp.left, objectName, maxPropertyPathLength, allowComputed) || isMemberExpOf(exp.right, objectName, maxPropertyPathLength, allowComputed)); | ||
} | ||
/** | ||
@@ -132,3 +124,3 @@ * Returns whether the specified expression is a negation. | ||
*/ | ||
var isNegationExpression = _.matches({type: 'UnaryExpression', operator: '!'}); | ||
var isNegationExpression = _.matches({ type: 'UnaryExpression', operator: '!' }); | ||
@@ -220,4 +212,37 @@ /** | ||
*/ | ||
var isEqEqEq = _.matches({type: 'BinaryExpression', operator: '==='}); | ||
var isEqEqEq = _.matches({ type: 'BinaryExpression', operator: '===' }); | ||
var comparisonOperators = ['==', '!=', '===', '!==']; | ||
var isMinus = function isMinus(node) { | ||
return node.type === 'UnaryExpression' && node.operator === '-'; | ||
}; | ||
/** | ||
* Returns the expression compared to the value in a binary expression, or undefined if there isn't one | ||
* @param {Object} node | ||
* @param {number} value | ||
* @returns {Object|undefined} | ||
*/ | ||
function getExpressionComparedToValue(node, value) { | ||
if (_.includes(comparisonOperators, node.operator)) { | ||
var isValue = value < 0 ? _.overEvery(isMinus, _.matches({ argument: { value: -value } })) : _.matches({ value: value }); | ||
if (isValue(node.right)) { | ||
return node.left; | ||
} | ||
if (isValue(node.left)) { | ||
return node.right; | ||
} | ||
} | ||
} | ||
/** | ||
* Returns whether the node is a call to indexOf | ||
* @param {Object} node | ||
* @returns {boolean} | ||
*/ | ||
var isIndexOfCall = function isIndexOfCall(node) { | ||
return isMethodCall(node) && getMethodName(node) === 'indexOf'; | ||
}; | ||
module.exports = { | ||
@@ -234,3 +259,3 @@ getCaller: getCaller, | ||
isNotEqEqToMemberOf: isBinaryExpWithMemberOf.bind(null, '!=='), | ||
isNegationOfParamMember: isNegationOfMemberOf, | ||
isNegationOfMemberOf: isNegationOfMemberOf, | ||
isIdentifierOfParam: isIdentifierOfParam, | ||
@@ -242,3 +267,5 @@ isNegationExpression: isNegationExpression, | ||
isEquivalentExp: isEquivalentExp, | ||
isEqEqEq: isEqEqEq | ||
}; | ||
isEqEqEq: isEqEqEq, | ||
getExpressionComparedToValue: getExpressionComparedToValue, | ||
isIndexOfCall: isIndexOfCall | ||
}; |
'use strict'; | ||
var _ = require('lodash'); | ||
@@ -174,3 +175,3 @@ var methodDataUtil = require('./methodDataUtil'); | ||
return function (node) { | ||
var iterateeIndex; | ||
var iterateeIndex = void 0; | ||
if (isLodashChainStart(node, settings.pragma)) { | ||
@@ -210,3 +211,3 @@ node = node.parent.parent; | ||
return getLodashMethodVisitor(settings, { | ||
always: function (node, iteratee) { | ||
always: function always(node, iteratee) { | ||
if (methodSupportsShorthand(settings.version, node) && checks.canUseShorthand(iteratee)) { | ||
@@ -216,3 +217,3 @@ context.report(iteratee, messages.always); | ||
}, | ||
never: function (node, iteratee) { | ||
never: function never(node, iteratee) { | ||
if (checks.usesShorthand(node, iteratee)) { | ||
@@ -219,0 +220,0 @@ context.report(iteratee || node.callee.property, messages.never); |
'use strict'; | ||
module.exports = { | ||
3: { | ||
aliases: { | ||
forEach: [ | ||
'each' | ||
], | ||
assign: [ | ||
'extend' | ||
], | ||
first: [ | ||
'head' | ||
], | ||
zipObject: [ | ||
'object' | ||
], | ||
rest: [ | ||
'tail' | ||
], | ||
uniq: [ | ||
'unique' | ||
], | ||
reduce: [ | ||
'foldl', | ||
'inject' | ||
], | ||
reduceRight: [ | ||
'foldr' | ||
], | ||
some: [ | ||
'any' | ||
], | ||
map: [ | ||
'collect' | ||
], | ||
includes: [ | ||
'contains', | ||
'include' | ||
], | ||
flowRight: [ | ||
'backflow', | ||
'compose' | ||
], | ||
isEqual: [ | ||
'eq' | ||
], | ||
every: [ | ||
'all' | ||
], | ||
find: [ | ||
'detect' | ||
], | ||
forEachRight: [ | ||
'eachRight' | ||
], | ||
filter: [ | ||
'select' | ||
], | ||
functions: [ | ||
'methods' | ||
], | ||
callback: [ | ||
'iteratee' | ||
] | ||
forEach: ['each'], | ||
assign: ['extend'], | ||
first: ['head'], | ||
zipObject: ['object'], | ||
rest: ['tail'], | ||
uniq: ['unique'], | ||
reduce: ['foldl', 'inject'], | ||
reduceRight: ['foldr'], | ||
some: ['any'], | ||
map: ['collect'], | ||
includes: ['contains', 'include'], | ||
flowRight: ['backflow', 'compose'], | ||
isEqual: ['eq'], | ||
every: ['all'], | ||
find: ['detect'], | ||
forEachRight: ['eachRight'], | ||
filter: ['select'], | ||
functions: ['methods'], | ||
callback: ['iteratee'] | ||
}, | ||
wrapper: [ | ||
'concat', | ||
'join', | ||
'pop', | ||
'push', | ||
'reverse', | ||
'shift', | ||
'slice', | ||
'sort', | ||
'splice', | ||
'unshift', | ||
'replace', | ||
'split' | ||
], | ||
wrapper: ['concat', 'join', 'pop', 'push', 'reverse', 'shift', 'slice', 'sort', 'splice', 'unshift', 'replace', 'split'], | ||
wrapperAliases: { | ||
value: [ | ||
'run', | ||
'toJSON', | ||
'valueOf' | ||
] | ||
value: ['run', 'toJSON', 'valueOf'] | ||
}, | ||
shorthand: [ | ||
'dropRightWhile', | ||
'dropWhile', | ||
'findIndex', | ||
'findLastIndex', | ||
'remove', | ||
'sortedIndex', | ||
'sortedLastIndex', | ||
'map', | ||
'takeRightWhile', | ||
'takeWhile', | ||
'uniq', | ||
'countBy', | ||
'every', | ||
'filter', | ||
'find', | ||
'result', | ||
'groupBy', | ||
'indexBy', | ||
'partition', | ||
'reject', | ||
'some', | ||
'sortBy', | ||
'sortByOrder', | ||
'max', | ||
'min', | ||
'sum', | ||
'findKey', | ||
'findLastKey', | ||
'mapValues' | ||
], | ||
chainable: [ | ||
'after', | ||
'ary', | ||
'assign', | ||
'at', | ||
'before', | ||
'bind', | ||
'bindAll', | ||
'bindKey', | ||
'callback', | ||
'chain', | ||
'chunk', | ||
'commit', | ||
'compact', | ||
'concat', | ||
'constant', | ||
'countBy', | ||
'create', | ||
'curry', | ||
'debounce', | ||
'defaults', | ||
'defaultsDeep', | ||
'defer', | ||
'delay', | ||
'difference', | ||
'drop', | ||
'dropRight', | ||
'dropRightWhile', | ||
'dropWhile', | ||
'fill', | ||
'filter', | ||
'flatten', | ||
'flattenDeep', | ||
'flow', | ||
'flowRight', | ||
'forEach', | ||
'forEachRight', | ||
'forIn', | ||
'forInRight', | ||
'forOwn', | ||
'forOwnRight', | ||
'functions', | ||
'groupBy', | ||
'indexBy', | ||
'initial', | ||
'intersection', | ||
'invert', | ||
'invoke', | ||
'keys', | ||
'keysIn', | ||
'map', | ||
'mapKeys', | ||
'mapValues', | ||
'matches', | ||
'matchesProperty', | ||
'memoize', | ||
'merge', | ||
'method', | ||
'methodOf', | ||
'mixin', | ||
'modArgs', | ||
'negate', | ||
'omit', | ||
'once', | ||
'pairs', | ||
'partial', | ||
'partialRight', | ||
'partition', | ||
'pick', | ||
'plant', | ||
'pluck', | ||
'property', | ||
'propertyOf', | ||
'pull', | ||
'pullAt', | ||
'push', | ||
'range', | ||
'rearg', | ||
'reject', | ||
'remove', | ||
'rest', | ||
'restParam', | ||
'reverse', | ||
'set', | ||
'shuffle', | ||
'slice', | ||
'sort', | ||
'sortBy', | ||
'sortByAll', | ||
'sortByOrder', | ||
'splice', | ||
'spread', | ||
'take', | ||
'takeRight', | ||
'takeRightWhile', | ||
'takeWhile', | ||
'tap', | ||
'throttle', | ||
'thru', | ||
'times', | ||
'toArray', | ||
'toPlainObject', | ||
'transform', | ||
'union', | ||
'uniq', | ||
'unshift', | ||
'unzip', | ||
'unzipWith', | ||
'values', | ||
'valuesIn', | ||
'where', | ||
'without', | ||
'wrap', | ||
'xor', | ||
'zip', | ||
'zipObject', | ||
'zipWith' | ||
], | ||
shorthand: ['dropRightWhile', 'dropWhile', 'findIndex', 'findLastIndex', 'remove', 'sortedIndex', 'sortedLastIndex', 'map', 'takeRightWhile', 'takeWhile', 'uniq', 'countBy', 'every', 'filter', 'find', 'result', 'groupBy', 'indexBy', 'partition', 'reject', 'some', 'sortBy', 'sortByOrder', 'max', 'min', 'sum', 'findKey', 'findLastKey', 'mapValues'], | ||
chainable: ['after', 'ary', 'assign', 'at', 'before', 'bind', 'bindAll', 'bindKey', 'callback', 'chain', 'chunk', 'commit', 'compact', 'concat', 'constant', 'countBy', 'create', 'curry', 'debounce', 'defaults', 'defaultsDeep', 'defer', 'delay', 'difference', 'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'fill', 'filter', 'flatten', 'flattenDeep', 'flow', 'flowRight', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'functions', 'groupBy', 'indexBy', 'initial', 'intersection', 'invert', 'invoke', 'keys', 'keysIn', 'map', 'mapKeys', 'mapValues', 'matches', 'matchesProperty', 'memoize', 'merge', 'method', 'methodOf', 'mixin', 'modArgs', 'negate', 'omit', 'once', 'pairs', 'partial', 'partialRight', 'partition', 'pick', 'plant', 'pluck', 'property', 'propertyOf', 'pull', 'pullAt', 'push', 'range', 'rearg', 'reject', 'remove', 'rest', 'restParam', 'reverse', 'set', 'shuffle', 'slice', 'sort', 'sortBy', 'sortByAll', 'sortByOrder', 'splice', 'spread', 'take', 'takeRight', 'takeRightWhile', 'takeWhile', 'tap', 'throttle', 'thru', 'times', 'toArray', 'toPlainObject', 'transform', 'union', 'uniq', 'unshift', 'unzip', 'unzipWith', 'values', 'valuesIn', 'where', 'without', 'wrap', 'xor', 'zip', 'zipObject', 'zipWith'], | ||
iteratee: { | ||
any: ['dropRightWhile', 'dropWhile', 'findIndex', 'findLastIndex', 'remove', 'sortedIndex', 'sortedLastIndex', 'takeRightWhile', | ||
'takeWhile', 'uniq', 'unzipWith', 'zipWith', 'tap', 'thru', 'countBy', 'every', 'filter', 'find', 'findLast', 'forEach', 'forEachRight', 'groupBy', 'indexBy', 'map', 'partition', 'reduce', | ||
'reduceRight', 'reject', 'some', 'sortBy', 'max', 'min', 'sum', 'findKey', 'findLastKey', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'mapKeys', 'mapValues', 'transform', 'times' | ||
], | ||
any: ['dropRightWhile', 'dropWhile', 'findIndex', 'findLastIndex', 'remove', 'sortedIndex', 'sortedLastIndex', 'takeRightWhile', 'takeWhile', 'uniq', 'unzipWith', 'zipWith', 'tap', 'thru', 'countBy', 'every', 'filter', 'find', 'findLast', 'forEach', 'forEachRight', 'groupBy', 'indexBy', 'map', 'partition', 'reduce', 'reduceRight', 'reject', 'some', 'sortBy', 'max', 'min', 'sum', 'findKey', 'findLastKey', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'mapKeys', 'mapValues', 'transform', 'times'], | ||
differentIndex: { | ||
@@ -413,211 +206,16 @@ sortedIndex: 2, | ||
aliases: { | ||
head: [ | ||
'first' | ||
], | ||
forEach: [ | ||
'each' | ||
], | ||
forEachRight: [ | ||
'eachRight' | ||
], | ||
assignIn: [ | ||
'extend' | ||
], | ||
assignInWith: [ | ||
'extendWith' | ||
] | ||
head: ['first'], | ||
forEach: ['each'], | ||
forEachRight: ['eachRight'], | ||
assignIn: ['extend'], | ||
assignInWith: ['extendWith'] | ||
}, | ||
wrapper: [ | ||
'concat', | ||
'join', | ||
'pop', | ||
'push', | ||
'shift', | ||
'sort', | ||
'splice', | ||
'unshift', | ||
'replace', | ||
'split' | ||
], | ||
wrapper: ['concat', 'join', 'pop', 'push', 'shift', 'sort', 'splice', 'unshift', 'replace', 'split'], | ||
wrapperAliases: { | ||
value: [ | ||
'toJSON', | ||
'valueOf' | ||
] | ||
value: ['toJSON', 'valueOf'] | ||
}, | ||
shorthand: [ | ||
'differenceBy', | ||
'dropRightWhile', | ||
'dropWhile', | ||
'every', | ||
'filter', | ||
'find', | ||
'findIndex', | ||
'findKey', | ||
'findLastKey', | ||
'findLastIndex', | ||
'groupBy', | ||
'intersectionBy', | ||
'map', | ||
'mapValues', | ||
'maxBy', | ||
'minBy', | ||
'partition', | ||
'reject', | ||
'some', | ||
'sortedIndexBy', | ||
'sortedLastIndexBy', | ||
'sumBy', | ||
'takeRightWhile', | ||
'takeWhile', | ||
'unionBy', | ||
'uniqBy', | ||
'xorBy' | ||
], | ||
chainable: [ | ||
'after', | ||
'ary', | ||
'assign', | ||
'assignIn', | ||
'assignInWith', | ||
'assignWith', | ||
'at', | ||
'before', | ||
'bind', | ||
'bindAll', | ||
'bindKey', | ||
'chain', | ||
'chunk', | ||
'commit', | ||
'compact', | ||
'concat', | ||
'conforms', | ||
'constant', | ||
'countBy', | ||
'create', | ||
'curry', | ||
'debounce', | ||
'defaults', | ||
'defaultsDeep', | ||
'defer', | ||
'delay', | ||
'difference', | ||
'differenceBy', | ||
'differenceWith', | ||
'drop', | ||
'dropRight', | ||
'dropRightWhile', | ||
'dropWhile', | ||
'fill', | ||
'filter', | ||
'flatten', | ||
'flattenDeep', | ||
'flip', | ||
'flow', | ||
'flowRight', | ||
'fromPairs', | ||
'functions', | ||
'functionsIn', | ||
'groupBy', | ||
'initial', | ||
'intersection', | ||
'intersectionBy', | ||
'intersectionWith', | ||
'invert', | ||
'invokeMap', | ||
'iteratee', | ||
'keyBy', | ||
'keys', | ||
'keysIn', | ||
'map', | ||
'mapKeys', | ||
'mapValues', | ||
'matches', | ||
'matchesProperty', | ||
'memoize', | ||
'merge', | ||
'mergeWith', | ||
'method', | ||
'methodOf', | ||
'mixin', | ||
'negate', | ||
'nthArg', | ||
'omit', | ||
'omitBy', | ||
'once', | ||
'orderBy', | ||
'over', | ||
'overArgs', | ||
'overEvery', | ||
'overSome', | ||
'partial', | ||
'partialRight', | ||
'partition', | ||
'pick', | ||
'pickBy', | ||
'plant', | ||
'property', | ||
'propertyOf', | ||
'pull', | ||
'pullAll', | ||
'pullAllBy', | ||
'pullAt', | ||
'push', | ||
'range', | ||
'rangeRight', | ||
'rearg', | ||
'reject', | ||
'remove', | ||
'rest', | ||
'reverse', | ||
'sampleSize', | ||
'set', | ||
'setWith', | ||
'shuffle', | ||
'slice', | ||
'sort', | ||
'sortBy', | ||
'splice', | ||
'spread', | ||
'tail', | ||
'take', | ||
'takeRight', | ||
'takeRightWhile', | ||
'takeWhile', | ||
'tap', | ||
'throttle', | ||
'thru', | ||
'toArray', | ||
'toPairs', | ||
'toPairsIn', | ||
'toPath', | ||
'toPlainObject', | ||
'transform', | ||
'unary', | ||
'union', | ||
'unionBy', | ||
'unionWith', | ||
'uniq', | ||
'uniqBy', | ||
'uniqWith', | ||
'unset', | ||
'unshift', | ||
'unzip', | ||
'unzipWith', | ||
'values', | ||
'valuesIn', | ||
'without', | ||
'wrap', | ||
'xor', | ||
'xorBy', | ||
'xorWith', | ||
'zip', | ||
'zipObject', | ||
'zipWith' | ||
], | ||
shorthand: ['differenceBy', 'dropRightWhile', 'dropWhile', 'every', 'filter', 'find', 'findIndex', 'findKey', 'findLastKey', 'findLastIndex', 'groupBy', 'intersectionBy', 'map', 'mapValues', 'maxBy', 'minBy', 'partition', 'reject', 'some', 'sortedIndexBy', 'sortedLastIndexBy', 'sumBy', 'takeRightWhile', 'takeWhile', 'unionBy', 'uniqBy', 'xorBy'], | ||
chainable: ['after', 'ary', 'assign', 'assignIn', 'assignInWith', 'assignWith', 'at', 'before', 'bind', 'bindAll', 'bindKey', 'chain', 'chunk', 'commit', 'compact', 'concat', 'conforms', 'constant', 'countBy', 'create', 'curry', 'debounce', 'defaults', 'defaultsDeep', 'defer', 'delay', 'difference', 'differenceBy', 'differenceWith', 'drop', 'dropRight', 'dropRightWhile', 'dropWhile', 'fill', 'filter', 'flatten', 'flattenDeep', 'flip', 'flow', 'flowRight', 'fromPairs', 'functions', 'functionsIn', 'groupBy', 'initial', 'intersection', 'intersectionBy', 'intersectionWith', 'invert', 'invokeMap', 'iteratee', 'keyBy', 'keys', 'keysIn', 'map', 'mapKeys', 'mapValues', 'matches', 'matchesProperty', 'memoize', 'merge', 'mergeWith', 'method', 'methodOf', 'mixin', 'negate', 'nthArg', 'omit', 'omitBy', 'once', 'orderBy', 'over', 'overArgs', 'overEvery', 'overSome', 'partial', 'partialRight', 'partition', 'pick', 'pickBy', 'plant', 'property', 'propertyOf', 'pull', 'pullAll', 'pullAllBy', 'pullAt', 'push', 'range', 'rangeRight', 'rearg', 'reject', 'remove', 'rest', 'reverse', 'sampleSize', 'set', 'setWith', 'shuffle', 'slice', 'sort', 'sortBy', 'splice', 'spread', 'tail', 'take', 'takeRight', 'takeRightWhile', 'takeWhile', 'tap', 'throttle', 'thru', 'toArray', 'toPairs', 'toPairsIn', 'toPath', 'toPlainObject', 'transform', 'unary', 'union', 'unionBy', 'unionWith', 'uniq', 'uniqBy', 'uniqWith', 'unset', 'unshift', 'unzip', 'unzipWith', 'values', 'valuesIn', 'without', 'wrap', 'xor', 'xorBy', 'xorWith', 'zip', 'zipObject', 'zipWith'], | ||
iteratee: { | ||
any: ['dropRightWhile', 'dropWhile', 'findIndex', 'findLastIndex', 'flatMap', 'pullAllBy', 'remove', 'sortedIndexBy', 'sortedLastIndexBy', 'sortedUniqBy', 'takeRightWhile', | ||
'takeWhile', 'uniqBy', 'unzipWith', 'xorBy', 'zipWith', 'countBy', 'every', 'filter', 'find', 'findLast', 'forEach', 'forEachRight', 'groupBy', 'indexBy', 'keyBy', 'map', 'partition', 'reduce', | ||
'reduceRight', 'reject', 'some', 'tap', 'thru', 'maxBy', 'minBy', 'sumBy', 'findKey', 'findLastKey', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'mapKeys', | ||
'mapValues', 'omitBy', 'pickBy', 'transform', 'times', 'cloneDeepWith', 'cloneWith'], | ||
any: ['dropRightWhile', 'dropWhile', 'findIndex', 'findLastIndex', 'flatMap', 'pullAllBy', 'remove', 'sortedIndexBy', 'sortedLastIndexBy', 'sortedUniqBy', 'takeRightWhile', 'takeWhile', 'uniqBy', 'unzipWith', 'xorBy', 'zipWith', 'countBy', 'every', 'filter', 'find', 'findLast', 'forEach', 'forEachRight', 'groupBy', 'indexBy', 'keyBy', 'map', 'partition', 'reduce', 'reduceRight', 'reject', 'some', 'tap', 'thru', 'maxBy', 'minBy', 'sumBy', 'findKey', 'findLastKey', 'forIn', 'forInRight', 'forOwn', 'forOwnRight', 'mapKeys', 'mapValues', 'omitBy', 'pickBy', 'transform', 'times', 'cloneDeepWith', 'cloneWith'], | ||
differentIndex: { | ||
@@ -861,2 +459,2 @@ sortedIndex: 2, | ||
} | ||
}; | ||
}; |
'use strict'; | ||
var _ = require('lodash'); | ||
@@ -9,13 +10,11 @@ module.exports = { | ||
*/ | ||
getSettings: function (context) { | ||
return _.chain(context) | ||
.get(['settings', 'lodash']) | ||
.clone() | ||
.defaults({ | ||
pragma: '_', | ||
version: 4 | ||
}) | ||
.value(); | ||
getSettings: function getSettings(context) { | ||
return _.chain(context).get(['settings', 'lodash']).clone().defaults({ | ||
pragma: '_', | ||
version: 4 | ||
}).value(); | ||
}, | ||
/** | ||
@@ -26,4 +25,4 @@ * Gets whether the ecmaFeature specified is on for the context | ||
*/ | ||
isEcmaFeatureOn: function (context, featureName) { | ||
return _.get(context, ['ecmaFeatures', featureName]) || (_.get(context, ['parserOptions', 'ecmaVersion'], 0) > 5); | ||
isEcmaFeatureOn: function isEcmaFeatureOn(context, featureName) { | ||
return _.get(context, ['ecmaFeatures', featureName]) || _.get(context, ['parserOptions', 'ecmaVersion'], 0) > 5; | ||
} | ||
@@ -30,0 +29,0 @@ }; |
{ | ||
"name": "eslint-plugin-lodash", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"author": "Omer Ganim <ganimomer@gmail.com>", | ||
@@ -11,3 +11,4 @@ "description": "Lodash specific linting rules for ESLint", | ||
"test": "npm run lint && npm run unit-test", | ||
"unit-test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --reporter dot" | ||
"unit-test": "istanbul cover --dir reports/coverage node_modules/mocha/bin/_mocha tests/**/*.js -- --reporter dot", | ||
"prepublish": "babel src -d lib" | ||
}, | ||
@@ -17,3 +18,2 @@ "files": [ | ||
"README.md", | ||
"index.js", | ||
"lib" | ||
@@ -31,2 +31,4 @@ ], | ||
"devDependencies": { | ||
"babel-cli": "6.6.5", | ||
"babel-preset-es2015": "6.6.0", | ||
"coveralls": "2.11.8", | ||
@@ -33,0 +35,0 @@ "eslint": "2.4.0", |
@@ -53,3 +53,3 @@ ESLint-Plugin-Lodash | ||
# List of provided rules | ||
Rules are divided into categories for your convenience. All rules are off by default. | ||
Rules are divided into categories for your convenience. All rules are off by default, unless you use one of the plugin's configurations which turn all relevant rules on. | ||
### Possible Errors | ||
@@ -98,5 +98,6 @@ The following rules point out areas where you might have made mistakes. | ||
* [prefer-over-quantifier](docs/rules/prefer-over-quantifier.md): Prefer `_.overSome` and `_.overEvery` instead of checks with `&&` and `||` for methods that have a boolean check iteratee. | ||
* [prefer-includes](docs/rules/perfer-includes.md): Prefer `_.includes` over comparing `indexOf` to 1-11. | ||
# Contributing | ||
Contributions are always welcome! For more info, read our [contribution guide](/CONTRIBUTING.md). | ||
Contributions are always welcome! For more info, read our [contribution guide](.github/CONTRIBUTING.md). | ||
@@ -103,0 +104,0 @@ # License |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
44
118
118723
7
2445