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

eslint-plugin-sort

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-sort - npm Package Compare versions

Comparing version 2.9.0 to 2.10.0

170

dist/index.js

@@ -77,2 +77,11 @@ // src/utils.ts

var pluralize = (word, count) => word + (count === 1 ? "" : "s");
function getImportOrExportKindWeight(typeOrder, kind) {
if (typeOrder === "first") {
return kind === "type" ? -1 : 1;
}
if (typeOrder === "last") {
return kind === "type" ? 1 : -1;
}
return 0;
}

@@ -144,2 +153,9 @@ // src/rules/destructuring-properties.ts

// src/rules/exports.ts
var sortGroupsTypes = [
"default",
"sourceless",
"dependency",
"type",
"other"
];
function getSortGroup(sortGroups, node) {

@@ -158,2 +174,8 @@ const source = getSortValue(node);

break;
case "type": {
const { exportKind } = node;
if (exportKind === "type")
return order;
break;
}
case "dependency":

@@ -172,2 +194,7 @@ if (isResolved(source))

}
function getExportKindWeight(options, node) {
const typeOrder = options?.typeOrder ?? "preserve";
const kind = node.exportKind;
return getImportOrExportKindWeight(typeOrder, kind);
}
function getSortValue(node) {

@@ -195,3 +222,4 @@ return node.type !== "ExportDefaultDeclaration" && node.source ? getName(node.source) : "";

getSortGroup(groups, a) - getSortGroup(groups, b) || // Then sort by export name
sorter(getSortValue(a), getSortValue(b))
sorter(getSortValue(a), getSortValue(b)) || // Finally sort by export kind
getExportKindWeight(options, a) - getExportKindWeight(options, b)
)

@@ -222,6 +250,10 @@ );

type: {
enum: ["default", "sourceless", "dependency", "other"]
enum: sortGroupsTypes
},
regex: { type: "string" },
order: { type: "number" }
regex: {
type: "string"
},
order: {
type: "number"
}
},

@@ -231,2 +263,14 @@ required: ["order"],

}
},
typeOrder: {
enum: ["preserve", "first", "last"],
default: "preserve"
},
caseSensitive: {
type: "boolean",
default: false
},
natural: {
type: "boolean",
default: true
}

@@ -284,2 +328,3 @@ }

// src/rules/imports.ts
var sortGroupsTypes2 = ["side-effect", "dependency", "type", "other"];
function getSortGroup2(sortGroups, node) {

@@ -293,2 +338,8 @@ const source = getName(node.source);

break;
case "type": {
const { importKind } = node;
if (importKind === "type")
return order;
break;
}
case "dependency":

@@ -307,2 +358,7 @@ if (isResolved(source))

}
function getImportKindWeight(options, node) {
const typeOrder = options?.typeOrder ?? "preserve";
const kind = node.importKind;
return getImportOrExportKindWeight(typeOrder, kind);
}
var getSortValue2 = (node) => getName(node.source);

@@ -327,3 +383,4 @@ var rawString = (str) => JSON.stringify(str).slice(1, -1).replace(/\\n/g, "\\n");

getSortGroup2(groups, a) - getSortGroup2(groups, b) || // Then sort by import name
sorter(getSortValue2(a), getSortValue2(b))
sorter(getSortValue2(a), getSortValue2(b)) || // Finally sort by import kind
getImportKindWeight(options, a) - getImportKindWeight(options, b)
)

@@ -413,6 +470,2 @@ );

properties: {
separator: {
type: "string",
default: ""
},
groups: {

@@ -423,5 +476,11 @@ type: "array",

properties: {
type: { enum: ["side-effect", "dependency", "other"] },
regex: { type: "string" },
order: { type: "number" }
type: {
enum: sortGroupsTypes2
},
regex: {
type: "string"
},
order: {
type: "number"
}
},

@@ -431,2 +490,18 @@ required: ["order"],

}
},
separator: {
type: "string",
default: ""
},
typeOrder: {
enum: ["preserve", "first", "last"],
default: "preserve"
},
caseSensitive: {
type: "boolean",
default: false
},
natural: {
type: "boolean",
default: true
}

@@ -740,2 +815,70 @@ }

// src/rules/string-enums.ts
import {
ESLintUtils as ESLintUtils3,
TSESTree as TSESTree4
} from "@typescript-eslint/experimental-utils";
function getSortValue5(node) {
return node.initializer?.type === TSESTree4.AST_NODE_TYPES.Literal && typeof node.initializer.value === "string" ? node.initializer.value : null;
}
var string_enums_default = ESLintUtils3.RuleCreator.withoutDocs({
create(context) {
const source = context.getSourceCode();
const options = context.options[0];
const sorter = getSorter(options);
return {
TSEnumDeclaration(node) {
const nodes = node.members;
if (nodes.length < 2)
return;
if (nodes.map(getSortValue5).some((value) => value === null))
return;
const sorted = nodes.slice().sort((a, b) => sorter(getSortValue5(a) ?? "", getSortValue5(b) ?? ""));
const firstUnsortedNode = isUnsorted(nodes, sorted);
if (firstUnsortedNode) {
context.report({
node: firstUnsortedNode,
messageId: "unsorted",
*fix(fixer) {
for (const [node2, complement] of enumerate(nodes, sorted)) {
yield fixer.replaceText(node2, getNodeText2(source, complement));
}
}
});
}
}
};
},
meta: {
docs: {
recommended: false,
url: docsURL("string-enums"),
description: `Sorts TypeScript string enums alphabetically and case insensitive in ascending order.`
},
fixable: "code",
messages: {
unsorted: "String enums should be sorted alphabetically."
},
schema: [
{
additionalProperties: false,
default: { caseSensitive: false, natural: true },
properties: {
caseSensitive: {
type: "boolean",
default: false
},
natural: {
type: "boolean",
default: true
}
},
type: "object"
}
],
type: "suggestion"
},
defaultOptions: [{}]
});
// src/index.ts

@@ -785,3 +928,4 @@ var config = {

"type-properties": type_properties_default,
"string-unions": string_unions_default
"string-unions": string_unions_default,
"string-enums": string_enums_default
}

@@ -788,0 +932,0 @@ };

2

package.json
{
"name": "eslint-plugin-sort",
"description": "Auto-fixable sort rules for ESLint.",
"version": "2.9.0",
"version": "2.10.0",
"author": "Mark Skelton",

@@ -6,0 +6,0 @@ "packageManager": "pnpm@7.29.1",

@@ -55,2 +55,3 @@ # eslint-plugin-sort

| | 🔧 | [sort/type-properties](docs/rules/type-properties.md) | Sorts TypeScript type properties |
| | 🔧 | [sort/string-enums](docs/rules/string-enums.md) | Sorts TypeScript string enums |
| | 🔧 | [sort/string-unions](docs/rules/string-unions.md) | Sorts TypeScript string unions |

Sorry, the diff of this file is not supported yet

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