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.7.1 to 2.8.0

76

dist/index.js

@@ -34,3 +34,3 @@ // src/utils.ts

} else if (caseSensitive) {
return (a, b) => a.localeCompare(b);
return (a, b) => a < b ? -1 : a > b ? 1 : 0;
} else if (natural) {

@@ -671,2 +671,73 @@ return (a, b) => naturalCompare(a.toLowerCase(), b.toLowerCase());

// src/rules/string-unions.ts
import {
ESLintUtils as ESLintUtils2,
TSESTree as TSESTree3
} from "@typescript-eslint/experimental-utils";
function getSortValue4(node) {
return node.type === TSESTree3.AST_NODE_TYPES.TSLiteralType && node.literal.type === TSESTree3.AST_NODE_TYPES.Literal && typeof node.literal.value === "string" ? node.literal.value : null;
}
var string_unions_default = ESLintUtils2.RuleCreator.withoutDocs({
create(context) {
const source = context.getSourceCode();
const options = context.options[0];
const sorter = getSorter({
caseSensitive: options?.caseSensitive,
natural: options?.natural
});
return {
TSUnionType(node) {
const nodes = node.types;
if (nodes.length < 2)
return;
if (nodes.map(getSortValue4).some((value) => value === null))
return;
const sorted = nodes.slice().sort((a, b) => sorter(getSortValue4(a) ?? "", getSortValue4(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-unions"),
description: `Sorts TypeScript string unions alphabetically and case insensitive in ascending order.`
},
fixable: "code",
messages: {
unsorted: "String unions 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

@@ -715,3 +786,4 @@ var config = {

"object-properties": object_properties_default,
"type-properties": type_properties_default
"type-properties": type_properties_default,
"string-unions": string_unions_default
}

@@ -718,0 +790,0 @@ };

2

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

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

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

| | 🔧 | [sort/type-properties](docs/rules/type-properties.md) | Sorts TypeScript type properties |
| | 🔧 | [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