eslint-plugin-lodash
Advanced tools
Comparing version 2.4.5 to 2.5.0
@@ -11,4 +11,13 @@ # Change Log | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v2.4.4...HEAD | ||
[unreleased]: https://github.com/wix/eslint-plugin-lodash/compare/v2.5.0...HEAD | ||
## [2.5.0] - 2017-10-20 | ||
### Added | ||
- Added support for single-method packages ([`3037b9f`][3037b9f]) | ||
- Added option to enforce single-method packages import in `import-scope` ([`e4555c3`](e4555c3)) | ||
[3037b9f]: https://github.com/wix/eslint-plugin-lodash/commit/3037b9f8d858ab0e263f1e1f06bac9459c0aa8c8 | ||
[e4555c3]: https://github.com/wix/eslint-plugin-lodash/commit/e4555c3c2475813a07dc42031acb1daa52d251a0 | ||
[2.5.0]: https://github.com/wix/eslint-plugin-lodash/compare/v2.5.0...v2.4.4 | ||
## [2.4.4] - 2017-07-12 | ||
@@ -15,0 +24,0 @@ ### Fixed |
@@ -22,5 +22,6 @@ /** | ||
var messages = { | ||
method: 'Do not import from the full Lodash module.', | ||
method: 'Import individual methods from the Lodash module.', | ||
member: 'Import members from the full Lodash module.', | ||
full: 'Use the full Lodash module.' | ||
full: 'Use the full Lodash module.', | ||
'method-package': 'Import Lodash methods only from method packages (e.g. lodash.map)' | ||
}; | ||
@@ -30,2 +31,3 @@ | ||
method: ['ImportDefaultSpecifier'], | ||
'method-package': ['ImportDefaultSpecifier'], | ||
member: ['ImportSpecifier'], | ||
@@ -36,4 +38,7 @@ full: ['ImportDefaultSpecifier', 'ImportNamespaceSpecifier'] | ||
var isMethodImport = function isMethodImport(name) { | ||
return Boolean(getMethodImportFromName(name)); | ||
return getMethodImportFromName(name) && !includes(name, '.'); | ||
}; | ||
var isMethodPackageImport = function isMethodPackageImport(name) { | ||
return getMethodImportFromName(name) && includes(name, '.'); | ||
}; | ||
var allImportsAreOfType = function allImportsAreOfType(node, types) { | ||
@@ -48,3 +53,3 @@ return every(node.specifiers, function (specifier) { | ||
schema: [{ | ||
enum: ['method', 'member', 'full'] | ||
enum: ['method', 'member', 'full', 'method-package'] | ||
}] | ||
@@ -58,4 +63,4 @@ }, | ||
if (isFullLodashImport(node.source.value)) { | ||
if (importType === 'method') { | ||
context.report({ node: node, message: messages.method }); | ||
if (importType === 'method' || importType === 'method-package') { | ||
context.report({ node: node, message: messages[importType] }); | ||
} else { | ||
@@ -66,3 +71,3 @@ if (!allImportsAreOfType(node, importNodeTypes[importType])) { | ||
} | ||
} else if (isMethodImport(node.source.value) && importType !== 'method') { | ||
} else if (isMethodImport(node.source.value) && importType !== 'method' || isMethodPackageImport(node.source.value) && importType !== 'method-package') { | ||
context.report({ node: node, message: messages[importType] }); | ||
@@ -74,4 +79,4 @@ } | ||
if (isFullLodashImport(name)) { | ||
if (importType === 'method') { | ||
context.report({ node: node, message: messages.method }); | ||
if (importType === 'method' || importType === 'method-package') { | ||
context.report({ node: node, message: messages[importType] }); | ||
} else { | ||
@@ -84,3 +89,3 @@ var isObjectPattern = node.id.type === 'ObjectPattern'; | ||
} | ||
} else if (isMethodImport(name) && importType !== 'method') { | ||
} else if (isMethodImport(name) && importType !== 'method' || isMethodPackageImport(name) && importType !== 'method-package') { | ||
context.report({ node: node, message: messages[importType] }); | ||
@@ -87,0 +92,0 @@ } |
@@ -16,3 +16,3 @@ 'use strict'; | ||
var getMethodImportFromName = function getMethodImportFromName(str) { | ||
var match = /^lodash(-es)?\/(?!fp)(\w+)$/.exec(str); | ||
var match = /^lodash(-es\/|[./])(?!fp)(\w+)$/.exec(str); | ||
return match && match[2]; | ||
@@ -19,0 +19,0 @@ }; |
@@ -20,3 +20,3 @@ 'use strict'; | ||
/** | ||
* Returns whehter the node is a chain breaker method in the specified version | ||
* Returns whether the node is a chain breaker method in the specified version | ||
* @param {Object} node | ||
@@ -23,0 +23,0 @@ * @param {number} version |
{ | ||
"name": "eslint-plugin-lodash", | ||
"version": "2.4.5", | ||
"version": "2.5.0", | ||
"author": "Omer Ganim <ganimomer@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Lodash specific linting rules for ESLint", |
@@ -15,7 +15,7 @@ ESLint-Plugin-Lodash | ||
$ npm install eslint | ||
$ npm install eslint --save-dev | ||
If you installed `ESLint` globally, you have to install the Lodash plugin globally too. Otherwise, install it locally. | ||
$ npm install eslint-plugin-lodash | ||
$ npm install eslint-plugin-lodash --save-dev | ||
@@ -22,0 +22,0 @@ # Configuration |
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
249172
6977