eslint-plugin-lodash
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -11,4 +11,12 @@ # Change Log | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v3.0.0...HEAD | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v3.1.0...HEAD | ||
## [3.1.0] - 2018-09-19 | ||
### Added | ||
- Added `implicit` option to `chaining`. ([`c4cbbce`][c4cbbce]) | ||
[170e31f]: https://github.com/wix/eslint-plugin-lodash/commit/c4cbbcee438ca5c069f95da90e6aaaee34230296 | ||
[3.1.0]: https://github.com/wix/eslint-plugin-lodash/compare/v3.1.0...v3.0.0 | ||
## [3.0.0] - 2018-09-19 | ||
@@ -15,0 +23,0 @@ ### Fixed |
@@ -77,3 +77,3 @@ 'use strict'; | ||
'lodash/chain-style': [2, 'as-needed'], | ||
'lodash/chaining': [2, 'always'], | ||
'lodash/chaining': [2, 'implicit'], | ||
'lodash/collection-method-value': 2, | ||
@@ -80,0 +80,0 @@ 'lodash/collection-return': 2, |
@@ -18,7 +18,12 @@ /** | ||
schema: [{ | ||
enum: ['always', 'never'] | ||
enum: ['always', 'never', 'implicit'] | ||
}, { | ||
type: 'integer', | ||
minimum: 2 | ||
}] | ||
}], | ||
messages: { | ||
single: 'Do not use chain syntax for single method', | ||
never: 'Prefer composition to Lodash chaining', | ||
always: 'Prefer chaining to composition' | ||
} | ||
}, | ||
@@ -33,4 +38,8 @@ | ||
isMethodCall = _require2.isMethodCall, | ||
isObjectOfMethodCall = _require2.isObjectOfMethodCall; | ||
isObjectOfMethodCall = _require2.isObjectOfMethodCall, | ||
getMethodName = _require2.getMethodName; | ||
var _require3 = require('../util/methodDataUtil'), | ||
isChainable = _require3.isChainable; | ||
var DEFAULT_LENGTH = 3; | ||
@@ -50,18 +59,32 @@ var lodashContext = getLodashContext(context); | ||
function isNestedNLevels(node, n) { | ||
function isNestedNLevelsInner(node, n, includeUnchainable) { | ||
if (n === 0) { | ||
return true; | ||
} else if (lodashContext.isLodashCall(node) || lodashContext.getImportedLodashMethod(node)) { | ||
return isNestedNLevels(node.arguments[0], n - 1); | ||
} | ||
if (lodashContext.isLodashCall(node) && (includeUnchainable || isChainable(version, getMethodName(node)))) { | ||
return isNestedNLevelsInner(node.arguments[0], n - 1); | ||
} | ||
var importedLodashMethod = lodashContext.getImportedLodashMethod(node); | ||
if (importedLodashMethod && (includeUnchainable || isChainable(version, importedLodashMethod))) { | ||
return isNestedNLevelsInner(node.arguments[0], n - 1); | ||
} | ||
} | ||
function isNestedNLevels(node, n, includeUnchainable) { | ||
if (includeUnchainable) { | ||
return isNestedNLevelsInner(node, n, includeUnchainable); | ||
} | ||
if (lodashContext.isLodashCall(node) || lodashContext.getImportedLodashMethod(node)) { | ||
return isNestedNLevelsInner(node.arguments[0], n - 1, false); | ||
} | ||
} | ||
var callExpressionVisitors = { | ||
always: function always(node) { | ||
if (isNestedNLevels(node, ruleDepth)) { | ||
context.report({ node: node, message: 'Prefer chaining to composition' }); | ||
if (isNestedNLevels(node, ruleDepth, true)) { | ||
context.report({ node: node, messageId: 'always' }); | ||
} else if (lodashContext.isLodashChainStart(node)) { | ||
var firstCall = node.parent.parent; | ||
if (isMethodCall(firstCall) && (isEndOfChain(firstCall) || isBeforeChainBreaker(firstCall))) { | ||
context.report({ node: firstCall, message: 'Do not use chain syntax for single method' }); | ||
context.report({ node: firstCall, messageId: 'single' }); | ||
} | ||
@@ -72,4 +95,14 @@ } | ||
if (lodashContext.isLodashChainStart(node)) { | ||
context.report({ node: node, message: 'Prefer composition to Lodash chaining' }); | ||
context.report({ node: node, messageId: 'never' }); | ||
} | ||
}, | ||
implicit: function implicit(node) { | ||
if (isNestedNLevels(node, ruleDepth, false)) { | ||
context.report({ node: node, messageId: 'always' }); | ||
} else if (lodashContext.isLodashChainStart(node)) { | ||
var firstCall = node.parent.parent; | ||
if (isMethodCall(firstCall) && (isEndOfChain(firstCall) || isBeforeChainBreaker(firstCall))) { | ||
context.report({ node: firstCall, messageId: 'single' }); | ||
} | ||
} | ||
} | ||
@@ -76,0 +109,0 @@ }; |
{ | ||
"name": "eslint-plugin-lodash", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"author": "Omer Ganim <ganimomer@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Lodash specific linting rules for ESLint", |
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
269040
7273