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.0 to 1.0.1

2

lib/index.js
module.exports.rules = {
'sort-destructure-keys': require('rules/sort-destructure-keys')
'sort-destructure-keys': require('./rules/sort-destructure-keys')
};
const naturalCompare = require('natural-compare-lite');
function isRestProperty({type}) {
return type === 'RestElement' ||
type === 'RestProperty' ||
type === 'ExperimentalRestProperty';
}
/**
* Returns whether or not a `Property` is safe
* Returns whether or not a node is safe
* to be sorted.
*/
function shouldCheck({value}) {
return value.type === 'Identifier' ||
function shouldCheck(node) {
const {value} = node;
return isRestProperty(node) ||
value.type === 'Identifier' ||
value.type === 'ObjectPattern' ||

@@ -21,2 +30,5 @@ value.type === 'AssignmentPattern' &&

},
messages: {
sort: `Expected object keys to be in sorted order. Expected {{first}} to be before {{second}}.`
},
schema: []

@@ -41,2 +53,3 @@ },

if (prevNode &&
!isRestProperty(nextNode) &&
naturalCompare(prevNode.key.name, nextNode.key.name) > 0

@@ -46,3 +59,7 @@ ) {

node: nextNode,
message: `Expected object keys to be in sorted order. Expected ${nextNode.key.name} to be before ${prevNode.key.name}.`
messageId: 'sort',
data: {
first: nextNode.key.name,
second: prevNode.key.name
}
});

@@ -49,0 +66,0 @@

{
"name": "eslint-plugin-sort-destructure-keys",
"version": "1.0.0",
"version": "1.0.1",
"description": "require object destructure key to be sorted",

@@ -5,0 +5,0 @@ "keywords": [

const rule = require('../../../lib/rules/sort-destructure-keys');
const RuleTester = require('eslint').RuleTester;
function msg(before, after) {
return `Expected object keys to be in sorted order. Expected ${after} to be before ${before}.`;
function msg(second, first) {
return {
messageId: 'sort',
data: {first, second}
};
}

@@ -14,3 +17,3 @@

parserOptions: {
ecmaVersion: 2015
ecmaVersion: 2018
}

@@ -21,4 +24,10 @@ });

valid: [
'const {owner, ...userRoleNames} = FaroConstants.userRoleNames;',
'const {a, b} = someObj;',
'const {b, a = b} = someObj;'
'const {a: foo, b} = someObj;',
'const {b, a = b} = someObj;',
'const {a = {}, b = {}} = someObj;',
'const {a, b, ...other} = someObj;',
'const {...other} = someObj;',
'const func = ({a, b}) => a + b;'
],

@@ -31,2 +40,6 @@ invalid: [

{
code: 'const func = ({b, a}) => a + b;',
errors: just('b', 'a')
},
{
code: 'const {a, c, b} = someObj;',

@@ -33,0 +46,0 @@ errors: just('c', 'b')

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