Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-sort-destructure-keys

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-sort-destructure-keys - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

42

lib/rules/sort-destructure-keys.js
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: [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc