eslint-plugin-sort-destructure-keys
Advanced tools
Comparing version 1.0.1 to 1.0.2
const naturalCompare = require('natural-compare-lite'); | ||
/** | ||
* Get's the "name" of the node, which could be an Identifier, | ||
* StringLiteral, or NumberLiteral. | ||
*/ | ||
function getNodeName(node) { | ||
return typeof node.name === 'undefined' | ||
? node.value.toString() | ||
: node.name; | ||
} | ||
/** | ||
* Determines if the node is a RestElement, accounting for different | ||
* parsers. | ||
*/ | ||
function isRestProperty({type}) { | ||
@@ -51,16 +65,18 @@ return type === 'RestElement' || | ||
for (const nextNode of node.properties) { | ||
if (prevNode && | ||
!isRestProperty(nextNode) && | ||
naturalCompare(prevNode.key.name, nextNode.key.name) > 0 | ||
) { | ||
context.report({ | ||
node: nextNode, | ||
messageId: 'sort', | ||
data: { | ||
first: nextNode.key.name, | ||
second: prevNode.key.name | ||
} | ||
}); | ||
if (prevNode && !isRestProperty(nextNode)) { | ||
const prevName = getNodeName(prevNode.key); | ||
const nextName = getNodeName(nextNode.key); | ||
break; | ||
if (naturalCompare(prevName.toLowerCase(), nextName.toLowerCase()) > 0) { | ||
context.report({ | ||
node: nextNode, | ||
messageId: 'sort', | ||
data: { | ||
first: nextName, | ||
second: prevName | ||
} | ||
}); | ||
break; | ||
} | ||
} | ||
@@ -67,0 +83,0 @@ |
{ | ||
"name": "eslint-plugin-sort-destructure-keys", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "require object destructure key to be sorted", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -25,2 +25,4 @@ const rule = require('../../../lib/rules/sort-destructure-keys'); | ||
'const {a, b} = someObj;', | ||
'const {aBc, abd} = someObj;', | ||
'const {1: a, 2: b} = someObj;', | ||
'const {a: foo, b} = someObj;', | ||
@@ -31,3 +33,4 @@ 'const {b, a = b} = someObj;', | ||
'const {...other} = someObj;', | ||
'const func = ({a, b}) => a + b;' | ||
'const func = ({a, b}) => a + b;', | ||
'const {a: {b, c}, d: {e, f: {g}}} = someObj;', | ||
], | ||
@@ -34,0 +37,0 @@ invalid: [ |
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
7168
145