🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

eslint-plugin-sort-react-dependency-arrays

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-sort-react-dependency-arrays - npm Package Compare versions

Comparing version

to
0.3.0

34

lib/rules/sort.js

@@ -24,2 +24,21 @@ /**

create(context) {
function getSortableNameFromNode(node) {
if (!node) return '';
switch (node.type) {
case 'Identifier':
return node.name;
case 'MemberExpression':
// For chained expressions, e.g., `a.b.c`, we'll return `a.b.c`
return (
getSortableNameFromNode(node.object) +
'.' +
getSortableNameFromNode(node.property)
);
default:
// For any other types or for simplicity, you could just stringify the node.
return context.getSourceCode().getText(node);
}
}
return {

@@ -37,8 +56,15 @@ CallExpression(node) {

const currentNames = currentDependencies.map(
(item) => item.name
getSortableNameFromNode
);
const sortedDependencies = [
...dependencies.elements,
].sort((a, b) => (a.name < b.name ? -1 : 1));
const sortedDependencies = [...dependencies.elements]
.map((n) => ({
...n,
name: getSortableNameFromNode(n),
}))
.sort((a, b) =>
a.name
.toLowerCase()
.localeCompare(b.name.toLowerCase())
);
const sortedNames = sortedDependencies.map(

@@ -45,0 +71,0 @@ (item) => item.name

8

package.json
{
"name": "eslint-plugin-sort-react-dependency-arrays",
"description": "ESLint plugin to alphabetically sort React hook dependency arrays",
"version": "0.2.0",
"version": "0.3.0",
"author": "Steven Sacks <stevensacks@gmail.com>",

@@ -26,6 +26,6 @@ "keywords": [

"devDependencies": {
"eslint": "^8.21.0",
"eslint-plugin-eslint-plugin": "^5.0.2",
"eslint": "8.49.0",
"eslint-plugin-eslint-plugin": "5.1.1",
"eslint-plugin-node": "^11.1.0",
"mocha": "^10.0.0"
"mocha": "10.2.0"
},

@@ -32,0 +32,0 @@ "peerDependencies": {