diff --git a/docs/content/rules/sort-array-includes.mdx b/docs/content/rules/sort-array-includes.mdx index 457a37a8..3a3e7735 100644 --- a/docs/content/rules/sort-array-includes.mdx +++ b/docs/content/rules/sort-array-includes.mdx @@ -147,6 +147,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### groupKind @@ -229,6 +239,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', groupKind: 'literals-first', partitionByNewLine: false, matcher: 'minimatch', @@ -255,6 +266,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', groupKind: 'literals-first', partitionByNewLine: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-astro-attributes.mdx b/docs/content/rules/sort-astro-attributes.mdx index 674fa140..b91697bf 100644 --- a/docs/content/rules/sort-astro-attributes.mdx +++ b/docs/content/rules/sort-astro-attributes.mdx @@ -136,6 +136,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### groups @@ -310,6 +320,7 @@ In order to start using this rule, you need to install additional dependency: type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, @@ -342,6 +353,7 @@ In order to start using this rule, you need to install additional dependency: type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, diff --git a/docs/content/rules/sort-classes.mdx b/docs/content/rules/sort-classes.mdx index ba1d4f2d..3a378b69 100644 --- a/docs/content/rules/sort-classes.mdx +++ b/docs/content/rules/sort-classes.mdx @@ -181,6 +181,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -604,6 +614,7 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, matcher: 'minimatch', groups: [ @@ -645,6 +656,7 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, matcher: 'minimatch', groups: [ diff --git a/docs/content/rules/sort-enums.mdx b/docs/content/rules/sort-enums.mdx index bae0b4c1..6d10f147 100644 --- a/docs/content/rules/sort-enums.mdx +++ b/docs/content/rules/sort-enums.mdx @@ -112,6 +112,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### sortByValue default: `false` @@ -196,6 +206,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, sortByValue: false, @@ -223,6 +234,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, sortByValue: false, diff --git a/docs/content/rules/sort-exports.mdx b/docs/content/rules/sort-exports.mdx index 6b326f5d..8ee5d93f 100644 --- a/docs/content/rules/sort-exports.mdx +++ b/docs/content/rules/sort-exports.mdx @@ -106,6 +106,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -176,6 +186,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, groupKind: 'mixed', @@ -203,6 +214,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, groupKind: 'mixed', diff --git a/docs/content/rules/sort-imports.mdx b/docs/content/rules/sort-imports.mdx index a2d4866c..064b6d9e 100644 --- a/docs/content/rules/sort-imports.mdx +++ b/docs/content/rules/sort-imports.mdx @@ -145,6 +145,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### internalPattern default: `['~/**']` for `minimatch` matcher, `['^~/.*']` for `regex` matcher @@ -349,6 +359,7 @@ Specifies which environment’s built-in modules should be recognized. If you ar type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', internalPattern: ['~/**'], newlinesBetween: 'always', @@ -389,6 +400,7 @@ Specifies which environment’s built-in modules should be recognized. If you ar type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', internalPattern: ['~/**'], newlinesBetween: 'always', diff --git a/docs/content/rules/sort-interfaces.mdx b/docs/content/rules/sort-interfaces.mdx index 892eef48..7dd8072f 100644 --- a/docs/content/rules/sort-interfaces.mdx +++ b/docs/content/rules/sort-interfaces.mdx @@ -161,6 +161,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### ignorePattern default: `[]` @@ -348,6 +358,7 @@ Determines the matcher used for patterns in the `partitionByComment`, `ignorePat type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', ignorePattern: [], partitionByNewLine: false, optionalityOrder: 'ignore', @@ -377,6 +388,7 @@ Determines the matcher used for patterns in the `partitionByComment`, `ignorePat type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', ignorePattern: [], partitionByNewLine: false, optionalityOrder: 'ignore', diff --git a/docs/content/rules/sort-intersection-types.mdx b/docs/content/rules/sort-intersection-types.mdx index 4194eedd..944a2ae2 100644 --- a/docs/content/rules/sort-intersection-types.mdx +++ b/docs/content/rules/sort-intersection-types.mdx @@ -102,6 +102,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -283,6 +293,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByNewLine: false, matcher: 'minimatch', @@ -310,6 +321,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-jsx-props.mdx b/docs/content/rules/sort-jsx-props.mdx index 19bb8400..de4670f9 100644 --- a/docs/content/rules/sort-jsx-props.mdx +++ b/docs/content/rules/sort-jsx-props.mdx @@ -162,6 +162,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### ignorePattern default: `[]` @@ -259,6 +269,7 @@ Determines the matcher used for patterns in the `ignorePattern` and `customGroup type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', ignorePattern: [], matcher: 'minimatch', groups: [], @@ -286,6 +297,7 @@ Determines the matcher used for patterns in the `ignorePattern` and `customGroup type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', ignorePattern: [], matcher: 'minimatch', groups: [], diff --git a/docs/content/rules/sort-maps.mdx b/docs/content/rules/sort-maps.mdx index e02d4205..52c04fe8 100644 --- a/docs/content/rules/sort-maps.mdx +++ b/docs/content/rules/sort-maps.mdx @@ -107,6 +107,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -177,6 +187,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', @@ -203,6 +214,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-named-exports.mdx b/docs/content/rules/sort-named-exports.mdx index f4f100d2..dd28f82b 100644 --- a/docs/content/rules/sort-named-exports.mdx +++ b/docs/content/rules/sort-named-exports.mdx @@ -125,6 +125,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### groupKind default: `'mixed'` @@ -204,6 +214,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', groupKind: 'mixed', matcher: 'minimatch', }, @@ -229,6 +240,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', groupKind: 'mixed', matcher: 'minimatch', }, diff --git a/docs/content/rules/sort-named-imports.mdx b/docs/content/rules/sort-named-imports.mdx index e5ab8560..b0422b7d 100644 --- a/docs/content/rules/sort-named-imports.mdx +++ b/docs/content/rules/sort-named-imports.mdx @@ -126,6 +126,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### ignoreAlias default: `false` @@ -205,6 +215,7 @@ import { order: 'asc', ignoreAlias: false, ignoreCase: true, + specialCharacters: 'keep', groupKind: 'mixed', partitionByNewLine: false, partitionByComment: false, @@ -233,6 +244,7 @@ import { order: 'asc', ignoreAlias: false, ignoreCase: true, + specialCharacters: 'keep', groupKind: 'mixed', partitionByNewLine: false, partitionByComment: false, diff --git a/docs/content/rules/sort-object-types.mdx b/docs/content/rules/sort-object-types.mdx index 6ee9f2b2..7a157eda 100644 --- a/docs/content/rules/sort-object-types.mdx +++ b/docs/content/rules/sort-object-types.mdx @@ -123,6 +123,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -305,6 +315,7 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, matcher: 'minimatch', @@ -333,6 +344,7 @@ Determines the matcher used for patterns in the `partitionByComment` and `custom type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-objects.mdx b/docs/content/rules/sort-objects.mdx index 265d1c78..3d0e6e59 100644 --- a/docs/content/rules/sort-objects.mdx +++ b/docs/content/rules/sort-objects.mdx @@ -181,6 +181,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -345,6 +355,7 @@ Determines the matcher used for patterns in the `partitionByComment`, `ignorePat type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, styledComponents: true, @@ -375,6 +386,7 @@ Determines the matcher used for patterns in the `partitionByComment`, `ignorePat type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByComment: false, partitionByNewLine: false, styledComponents: true, diff --git a/docs/content/rules/sort-sets.mdx b/docs/content/rules/sort-sets.mdx index 99de5662..4e46b135 100644 --- a/docs/content/rules/sort-sets.mdx +++ b/docs/content/rules/sort-sets.mdx @@ -153,6 +153,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### groupKind @@ -233,6 +243,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', groupKind: 'literals-first', partitionByNewLine: false, matcher: 'minimatch', @@ -259,6 +270,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', groupKind: 'literals-first', partitionByNewLine: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-svelte-attributes.mdx b/docs/content/rules/sort-svelte-attributes.mdx index ea0fe68d..462f04fb 100644 --- a/docs/content/rules/sort-svelte-attributes.mdx +++ b/docs/content/rules/sort-svelte-attributes.mdx @@ -131,6 +131,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### groups @@ -295,6 +305,7 @@ In order to start using this rule, you need to install additional dependency: type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, @@ -327,6 +338,7 @@ In order to start using this rule, you need to install additional dependency: type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, diff --git a/docs/content/rules/sort-switch-case.mdx b/docs/content/rules/sort-switch-case.mdx index f5ea6efe..62c64dda 100644 --- a/docs/content/rules/sort-switch-case.mdx +++ b/docs/content/rules/sort-switch-case.mdx @@ -174,6 +174,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ## Usage default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment default: `false` @@ -303,6 +313,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', @@ -330,6 +341,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-variable-declarations.mdx b/docs/content/rules/sort-variable-declarations.mdx index 1cace839..bedfcb04 100644 --- a/docs/content/rules/sort-variable-declarations.mdx +++ b/docs/content/rules/sort-variable-declarations.mdx @@ -106,6 +106,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### partitionByComment @@ -170,6 +180,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', @@ -196,6 +207,7 @@ Determines the matcher used for patterns in the `partitionByComment` option. type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, matcher: 'minimatch', diff --git a/docs/content/rules/sort-vue-attributes.mdx b/docs/content/rules/sort-vue-attributes.mdx index 97da6163..c9edfcaa 100644 --- a/docs/content/rules/sort-vue-attributes.mdx +++ b/docs/content/rules/sort-vue-attributes.mdx @@ -165,6 +165,16 @@ Controls whether sorting should be case-sensitive or not. - `true` — Ignore case when sorting alphabetically or naturally (e.g., “A” and “a” are the same). - `false` — Consider case when sorting (e.g., “A” comes before “a”). +### specialCharacters + +default: `keep` + +Controls whether special characters should be trimmed, removed or kept before sorting. + +- `'keep'` — Keep special characters when sorting (e.g., “_a” comes before “a”). +- `'trim'` — Trim special characters when sorting alphabetically or naturally (e.g., “_a” and “a” are the same). +- `'remove'` — Remove special characters when sorting (e.g., “/a/b” and “ab” are the same). + ### groups @@ -324,6 +334,7 @@ In order to start using this rule, you need to install additional dependency: type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, @@ -356,6 +367,7 @@ In order to start using this rule, you need to install additional dependency: type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, diff --git a/rules/sort-array-includes.ts b/rules/sort-array-includes.ts index 0e6d8f80..8e7e0238 100644 --- a/rules/sort-array-includes.ts +++ b/rules/sort-array-includes.ts @@ -27,6 +27,7 @@ export type Options = [ groupKind: 'literals-first' | 'spreads-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' @@ -57,6 +58,12 @@ export let jsonSchema: JSONSchema4 = { description: 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groupKind: { description: 'Specifies top-level groups.', enum: ['mixed', 'literals-first', 'spreads-first'], @@ -108,6 +115,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groupKind: 'literals-first', partitionByComment: false, @@ -144,6 +152,7 @@ export let sortArray = ( groupKind: 'literals-first', type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', order: 'asc', partitionByComment: false, diff --git a/rules/sort-astro-attributes.ts b/rules/sort-astro-attributes.ts index 2cbb0dda..1b7d20dd 100644 --- a/rules/sort-astro-attributes.ts +++ b/rules/sort-astro-attributes.ts @@ -32,6 +32,7 @@ type Options = [ Partial<{ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' order: 'desc' | 'asc' @@ -72,6 +73,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groups: { description: 'Specifies the order of the groups.', type: 'array', @@ -122,6 +129,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, @@ -143,6 +151,7 @@ export default createEslintRule, MESSAGE_ID>({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', customGroups: {}, order: 'asc', diff --git a/rules/sort-classes-utils.ts b/rules/sort-classes-utils.ts index 1623efb6..bccbadd4 100644 --- a/rules/sort-classes-utils.ts +++ b/rules/sort-classes-utils.ts @@ -234,6 +234,7 @@ export const getCompareOptions = ( customGroup && 'order' in customGroup && customGroup.order ? customGroup.order : options.order, + specialCharacters: options.specialCharacters, ignoreCase: options.ignoreCase, } } diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index 9da4a0c6..f6d21a98 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -75,6 +75,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, partitionByComment: { description: 'Allows to use comments to separate the class members into logical groups.', @@ -186,6 +192,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByComment: false, groups: [ @@ -231,6 +238,7 @@ export default createEslintRule({ partitionByComment: false, type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', customGroups: [], order: 'asc', } as const) diff --git a/rules/sort-classes.types.ts b/rules/sort-classes.types.ts index 0f3dea0d..9fa2996b 100644 --- a/rules/sort-classes.types.ts +++ b/rules/sort-classes.types.ts @@ -188,6 +188,7 @@ export type SortClassesOptions = [ customGroups: { [key: string]: string[] | string } | CustomGroup[] type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] order: 'desc' | 'asc' diff --git a/rules/sort-enums.ts b/rules/sort-enums.ts index 3d5a1f43..64a4ca39 100644 --- a/rules/sort-enums.ts +++ b/rules/sort-enums.ts @@ -26,6 +26,7 @@ export type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean forceNumericSort: boolean @@ -68,6 +69,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, sortByValue: { description: 'Compare enum values instead of names.', type: 'boolean', @@ -115,6 +122,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', sortByValue: false, partitionByComment: false, @@ -141,6 +149,7 @@ export default createEslintRule({ type: 'alphabetical', matcher: 'minimatch', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', sortByValue: false, forceNumericSort: false, @@ -249,6 +258,7 @@ export default createEslintRule({ : options.type, order: options.order, ignoreCase: options.ignoreCase, + specialCharacters: options.specialCharacters, // Get the enum value rather than the name if needed nodeValueGetter: options.sortByValue || (isNumericEnum && options.forceNumericSort) diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index 28cd316d..c53db697 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -21,6 +21,7 @@ type Options = [ groupKind: 'values-first' | 'types-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' @@ -65,6 +66,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, partitionByComment: { description: 'Allows you to use comments to separate the exports into logical groups.', @@ -106,6 +113,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, @@ -118,6 +126,7 @@ export default createEslintRule({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', matcher: 'minimatch', partitionByComment: false, diff --git a/rules/sort-imports.ts b/rules/sort-imports.ts index 446cc83a..2ffe7bf6 100644 --- a/rules/sort-imports.ts +++ b/rules/sort-imports.ts @@ -57,6 +57,7 @@ type Options = [ } type: 'alphabetical' | 'line-length' | 'natural' newlinesBetween: 'ignore' | 'always' | 'never' + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' environment: 'node' | 'bun' @@ -102,6 +103,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, internalPattern: { description: 'Specifies the pattern for internal modules.', items: { @@ -211,6 +218,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', internalPattern: ['~/**'], sortSideEffects: false, newlinesBetween: 'always', @@ -254,6 +262,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', environment: 'node', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', } as const) diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index 66837e2f..619c0ce1 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -30,6 +30,7 @@ type Options = [ customGroups: { [key: string]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' partitionByNewLine: boolean @@ -72,6 +73,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, ignorePattern: { description: 'Specifies names or patterns for nodes that should be ignored by rule.', @@ -158,6 +165,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', ignorePattern: [], partitionByComment: false, @@ -179,6 +187,7 @@ export default createEslintRule, MESSAGE_ID>({ matcher: 'minimatch', ignorePattern: [], ignoreCase: true, + specialCharacters: 'keep', customGroups: {}, order: 'asc', groups: [], diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index cef6e811..30402044 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -39,6 +39,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] partitionByNewLine: boolean @@ -80,6 +81,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groups: { description: 'Specifies the order of the groups.', type: 'array', @@ -136,6 +143,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, @@ -149,6 +157,7 @@ export default createEslintRule({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', matcher: 'minimatch', partitionByComment: false, diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index a7cc68d9..558089e1 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -27,6 +27,7 @@ type Options = [ Partial<{ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' ignorePattern: string[] @@ -68,6 +69,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, ignorePattern: { description: 'Specifies names or patterns for nodes that should be ignored by rule.', @@ -126,6 +133,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', ignorePattern: [], groups: [], @@ -141,6 +149,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', ignorePattern: [], ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', customGroups: {}, order: 'asc', diff --git a/rules/sort-maps.ts b/rules/sort-maps.ts index c5d08690..1885defd 100644 --- a/rules/sort-maps.ts +++ b/rules/sort-maps.ts @@ -23,6 +23,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' @@ -63,6 +64,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, partitionByComment: { description: 'Allows you to use comments to separate the maps members into logical groups.', @@ -100,6 +107,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, @@ -121,6 +129,7 @@ export default createEslintRule({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', matcher: 'minimatch', partitionByComment: false, diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index 62f33634..648292e5 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -22,6 +22,7 @@ type Options = [ groupKind: 'values-first' | 'types-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' @@ -62,6 +63,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groupKind: { description: 'Specifies top-level groups.', enum: ['mixed', 'values-first', 'types-first'], @@ -104,6 +111,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, @@ -119,6 +127,7 @@ export default createEslintRule({ type: 'alphabetical', groupKind: 'mixed', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 721f0bb9..bd854cd7 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -22,6 +22,7 @@ type Options = [ groupKind: 'values-first' | 'types-first' | 'mixed' type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' @@ -63,6 +64,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, ignoreAlias: { description: 'Controls whether to ignore alias names.', type: 'boolean', @@ -110,6 +117,7 @@ export default createEslintRule({ order: 'asc', ignoreAlias: false, ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, partitionByComment: false, groupKind: 'mixed', @@ -129,6 +137,7 @@ export default createEslintRule({ ignoreAlias: false, groupKind: 'mixed', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index f8cd3e3a..03176274 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -30,6 +30,7 @@ type Options = [ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' partitionByNewLine: boolean @@ -73,6 +74,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, partitionByComment: { description: 'Allows you to use comments to separate the type members into logical groups.', @@ -151,6 +158,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, @@ -171,6 +179,7 @@ export default createEslintRule, MESSAGE_ID>({ groupKind: 'mixed', matcher: 'minimatch', ignoreCase: true, + specialCharacters: 'keep', customGroups: {}, order: 'asc', groups: [], diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index ffe67618..321b41a5 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -45,6 +45,7 @@ type Options = [ customGroups: { [key: string]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] partitionByNewLine: boolean @@ -89,6 +90,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, partitionByComment: { description: 'Allows you to use comments to separate the keys of objects into logical groups.', @@ -179,6 +186,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, @@ -204,6 +212,7 @@ export default createEslintRule({ ignorePattern: [], matcher: 'minimatch', ignoreCase: true, + specialCharacters: 'keep', customGroups: {}, order: 'asc', groups: [], diff --git a/rules/sort-sets.ts b/rules/sort-sets.ts index 7390a2d7..72b0b8af 100644 --- a/rules/sort-sets.ts +++ b/rules/sort-sets.ts @@ -23,6 +23,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groupKind: 'literals-first', }, diff --git a/rules/sort-svelte-attributes.ts b/rules/sort-svelte-attributes.ts index 85abb2bb..41d4d0e3 100644 --- a/rules/sort-svelte-attributes.ts +++ b/rules/sort-svelte-attributes.ts @@ -32,6 +32,7 @@ type Options = [ Partial<{ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' order: 'desc' | 'asc' @@ -72,6 +73,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groups: { description: 'Specifies the order of the groups.', type: 'array', @@ -122,6 +129,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, @@ -140,6 +148,7 @@ export default createEslintRule, MESSAGE_ID>({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', customGroups: {}, matcher: 'minimatch', order: 'asc', diff --git a/rules/sort-switch-case.ts b/rules/sort-switch-case.ts index 7cab1e7b..412336cf 100644 --- a/rules/sort-switch-case.ts +++ b/rules/sort-switch-case.ts @@ -19,6 +19,7 @@ type MESSAGE_ID = 'unexpectedSwitchCaseOrder' type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' + specialCharacters: 'remove' | 'trim' | 'keep' order: 'desc' | 'asc' ignoreCase: boolean }>, @@ -56,6 +57,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, }, additionalProperties: false, }, @@ -70,6 +77,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', }, ], create: context => ({ @@ -79,6 +87,7 @@ export default createEslintRule({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', } as const) diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index ea8eaf9d..053f98e1 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -37,6 +37,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' groups: (Group[] | Group)[] partitionByNewLine: boolean @@ -78,6 +79,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groups: { description: 'Specifies the order of the groups.', type: 'array', @@ -134,6 +141,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByNewLine: false, partitionByComment: false, @@ -147,6 +155,7 @@ export default createEslintRule({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', order: 'asc', groups: [], matcher: 'minimatch', diff --git a/rules/sort-variable-declarations.ts b/rules/sort-variable-declarations.ts index fdb303a2..40a75188 100644 --- a/rules/sort-variable-declarations.ts +++ b/rules/sort-variable-declarations.ts @@ -27,6 +27,7 @@ type Options = [ Partial<{ type: 'alphabetical' | 'line-length' | 'natural' partitionByComment: string[] | boolean | string + specialCharacters: 'remove' | 'trim' | 'keep' matcher: 'minimatch' | 'regex' partitionByNewLine: boolean order: 'desc' | 'asc' @@ -67,6 +68,12 @@ export default createEslintRule({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, partitionByComment: { description: 'Allows you to use comments to separate the variable declarations into logical groups.', @@ -106,6 +113,7 @@ export default createEslintRule({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', partitionByComment: false, partitionByNewLine: false, @@ -119,6 +127,7 @@ export default createEslintRule({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', partitionByNewLine: false, matcher: 'minimatch', partitionByComment: false, diff --git a/rules/sort-vue-attributes.ts b/rules/sort-vue-attributes.ts index 6be7f158..8c05337e 100644 --- a/rules/sort-vue-attributes.ts +++ b/rules/sort-vue-attributes.ts @@ -30,6 +30,7 @@ type Options = [ Partial<{ customGroups: { [key in T[number]]: string[] | string } type: 'alphabetical' | 'line-length' | 'natural' + specialCharacters: 'remove' | 'trim' | 'keep' groups: (Group[] | Group)[] matcher: 'minimatch' | 'regex' order: 'desc' | 'asc' @@ -70,6 +71,12 @@ export default createEslintRule, MESSAGE_ID>({ 'Controls whether sorting should be case-sensitive or not.', type: 'boolean', }, + specialCharacters: { + description: + 'Controls how special characters should be handled before sorting.', + type: 'string', + enum: ['remove', 'trim', 'keep'], + }, groups: { description: 'Specifies the order of the groups.', type: 'array', @@ -120,6 +127,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'alphabetical', order: 'asc', ignoreCase: true, + specialCharacters: 'keep', matcher: 'minimatch', groups: [], customGroups: {}, @@ -152,6 +160,7 @@ export default createEslintRule, MESSAGE_ID>({ let options = complete(context.options.at(0), settings, { type: 'alphabetical', ignoreCase: true, + specialCharacters: 'keep', customGroups: {}, matcher: 'minimatch', order: 'asc', diff --git a/test/sort-array-includes.test.ts b/test/sort-array-includes.test.ts index 888973f1..836344c1 100644 --- a/test/sort-array-includes.test.ts +++ b/test/sort-array-includes.test.ts @@ -640,6 +640,55 @@ describe(ruleName, () => { ], invalid: [], }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + [ + '$a', + 'b', + '$c', + ].includes(value) + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + [ + 'ab', + 'a$c', + ].includes(value) + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-astro-attributes.test.ts b/test/sort-astro-attributes.test.ts index eb49052b..fa01c776 100644 --- a/test/sort-astro-attributes.test.ts +++ b/test/sort-astro-attributes.test.ts @@ -499,6 +499,63 @@ describe(ruleName, () => { invalid: [], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + filename: 'file.astro', + code: dedent` + --- + import Component from '~/file.astro' + --- + + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + filename: 'file.astro', + code: dedent` + --- + import Component from '~/file.astro' + --- + + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-classes.test.ts b/test/sort-classes.test.ts index dc6aa52e..e9f083cc 100644 --- a/test/sort-classes.test.ts +++ b/test/sort-classes.test.ts @@ -3998,6 +3998,55 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + class Class { + _a + b + _c + } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + class Class { + ab + a_c + } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-enums.test.ts b/test/sort-enums.test.ts index 7b725641..10ffcf83 100644 --- a/test/sort-enums.test.ts +++ b/test/sort-enums.test.ts @@ -535,6 +535,55 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + enum Enum { + _A = 'A', + B = 'B', + _C = 'C', + } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + enum Enum { + AB = 'AB', + A_C = 'AC', + } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-exports.test.ts b/test/sort-exports.test.ts index 1b3b4a57..7093e12d 100644 --- a/test/sort-exports.test.ts +++ b/test/sort-exports.test.ts @@ -471,6 +471,51 @@ describe(ruleName, () => { }, ], }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + export { a } from '_a' + export { b } from 'b' + export { c } from '_c' + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + export { ab } from 'ab' + export { ac } from 'a_c' + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-imports.test.ts b/test/sort-imports.test.ts index ed8fe2d9..4346f5df 100644 --- a/test/sort-imports.test.ts +++ b/test/sort-imports.test.ts @@ -1553,6 +1553,51 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + import '_a' + import 'b' + import '_c' + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + import 'ab' + import 'a_c' + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-interfaces.test.ts b/test/sort-interfaces.test.ts index ec28a032..fe0d3ff2 100644 --- a/test/sort-interfaces.test.ts +++ b/test/sort-interfaces.test.ts @@ -976,6 +976,55 @@ describe(ruleName, () => { invalid: [], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + interface MyInterface { + _a: string + b: string + _c: string + } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + interface MyInterface { + ab: string + a_c: string + } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-intersection-types.test.ts b/test/sort-intersection-types.test.ts index 05bc654f..afe34f43 100644 --- a/test/sort-intersection-types.test.ts +++ b/test/sort-intersection-types.test.ts @@ -638,6 +638,53 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + type T = + _A & + B & + _C + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + type T = + AB & + A_C + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-jsx-props.test.ts b/test/sort-jsx-props.test.ts index 7a92059b..119ce6af 100644 --- a/test/sort-jsx-props.test.ts +++ b/test/sort-jsx-props.test.ts @@ -523,6 +523,55 @@ describe(ruleName, () => { invalid: [], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-maps.test.ts b/test/sort-maps.test.ts index 5908359c..5ccacd73 100644 --- a/test/sort-maps.test.ts +++ b/test/sort-maps.test.ts @@ -468,6 +468,55 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + new Map([ + [_a, 'a'], + [b, 'b'], + [_c, 'c'], + ]) + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + new Map([ + [ab, 'ab'], + [a_c, 'ac'], + ]) + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-named-exports.test.ts b/test/sort-named-exports.test.ts index bc4eb591..a641d930 100644 --- a/test/sort-named-exports.test.ts +++ b/test/sort-named-exports.test.ts @@ -383,6 +383,48 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + export { _a, b, _c } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + export { ab, a_c } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-named-imports.test.ts b/test/sort-named-imports.test.ts index 2fe505af..07ca18e1 100644 --- a/test/sort-named-imports.test.ts +++ b/test/sort-named-imports.test.ts @@ -604,6 +604,48 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + import { _a, b, _c } from 'module' + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + import { ab, a_c } from 'module' + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-object-types.test.ts b/test/sort-object-types.test.ts index 0f90c36e..7639581d 100644 --- a/test/sort-object-types.test.ts +++ b/test/sort-object-types.test.ts @@ -818,6 +818,55 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + type Type = { + _a: string + b: string + _c: string + } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + type Type = { + ab: string + a_c: string + } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-objects.test.ts b/test/sort-objects.test.ts index 685c1723..50251f08 100644 --- a/test/sort-objects.test.ts +++ b/test/sort-objects.test.ts @@ -1568,6 +1568,55 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + let obj = { + _a = 'a', + b = 'b', + _c = 'c', + } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + let obj = { + ab = 'ab', + a_c = 'ac', + } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-sets.test.ts b/test/sort-sets.test.ts index 0bf0dd74..e6bfdef6 100644 --- a/test/sort-sets.test.ts +++ b/test/sort-sets.test.ts @@ -591,6 +591,55 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + new Set([ + '$a', + 'b', + '$c', + ]) + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + new Set([ + 'ab', + 'a$c', + ]) + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-svelte-attributes.test.ts b/test/sort-svelte-attributes.test.ts index f1a3286f..cfd06125 100644 --- a/test/sort-svelte-attributes.test.ts +++ b/test/sort-svelte-attributes.test.ts @@ -506,6 +506,64 @@ describe(ruleName, () => { invalid: [], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + filename: 'file.svelte', + code: dedent` + + + + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + filename: 'file.svelte', + code: dedent` + + + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-switch-case.test.ts b/test/sort-switch-case.test.ts index ad2c98e9..98296e0c 100644 --- a/test/sort-switch-case.test.ts +++ b/test/sort-switch-case.test.ts @@ -531,6 +531,57 @@ describe(ruleName, () => { ], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + switch (x) { + case '_a': + case 'b': + case '_c': + break; + } + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + switch (x) { + case 'ab': + case 'a_c': + break; + } + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-union-types.test.ts b/test/sort-union-types.test.ts index df7e55df..08f34976 100644 --- a/test/sort-union-types.test.ts +++ b/test/sort-union-types.test.ts @@ -641,6 +641,53 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + type T = + _A | + B | + _C + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + type T = + AB | + A_C + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-variable-declarations.test.ts b/test/sort-variable-declarations.test.ts index c6e9148a..81962bb5 100644 --- a/test/sort-variable-declarations.test.ts +++ b/test/sort-variable-declarations.test.ts @@ -872,6 +872,53 @@ describe(ruleName, () => { }, ) }) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + code: dedent` + const + _a = 'a', + b = 'b', + _c = 'c' + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + code: dedent` + const + ab = 'ab', + a_c = 'ac' + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/test/sort-vue-attributes.test.ts b/test/sort-vue-attributes.test.ts index 738967c3..eac60e8d 100644 --- a/test/sort-vue-attributes.test.ts +++ b/test/sort-vue-attributes.test.ts @@ -341,6 +341,74 @@ describe(ruleName, () => { invalid: [], }, ) + + ruleTester.run( + `${ruleName}(${type}): allows to trim special characters`, + rule, + { + valid: [ + { + filename: 'file.vue', + code: dedent` + + + + `, + options: [ + { + ...options, + specialCharacters: 'trim', + }, + ], + }, + ], + invalid: [], + }, + ) + + ruleTester.run( + `${ruleName}(${type}): allows to remove special characters`, + rule, + { + valid: [ + { + filename: 'file.vue', + code: dedent` + + + + `, + options: [ + { + ...options, + specialCharacters: 'remove', + }, + ], + }, + ], + invalid: [], + }, + ) }) describe(`${ruleName}: sorting by natural order`, () => { diff --git a/utils/compare.ts b/utils/compare.ts index fd00f164..84909a68 100644 --- a/utils/compare.ts +++ b/utils/compare.ts @@ -11,8 +11,9 @@ interface BaseCompareOptions { } interface AlphabeticalCompareOptions extends BaseCompareOptions { + specialCharacters: 'remove' | 'trim' | 'keep' type: 'alphabetical' - ignoreCase?: boolean + ignoreCase: boolean } interface LineLengthCompareOptions extends BaseCompareOptions { @@ -21,7 +22,8 @@ interface LineLengthCompareOptions extends BaseCompareOptions { } interface NaturalCompareOptions extends BaseCompareOptions { - ignoreCase?: boolean + specialCharacters: 'remove' | 'trim' | 'keep' + ignoreCase: boolean type: 'natural' } @@ -41,7 +43,10 @@ export let compare = ( options.nodeValueGetter ?? ((node: SortingNode) => node.name) if (options.type === 'alphabetical') { - let formatString = getFormatStringFunc(!!options.ignoreCase) + let formatString = getFormatStringFunc( + options.ignoreCase, + options.specialCharacters, + ) sortingFunction = (aNode, bNode) => formatString(nodeValueGetter(aNode)).localeCompare( formatString(nodeValueGetter(bNode)), @@ -55,7 +60,10 @@ export let compare = ( return string } sortingFunction = (aNode, bNode) => { - let formatString = getFormatStringFunc(!!options.ignoreCase) + let formatString = getFormatStringFunc( + options.ignoreCase, + options.specialCharacters, + ) return naturalCompare( prepareNumeric(formatString(nodeValueGetter(aNode))), prepareNumeric(formatString(nodeValueGetter(bNode))), @@ -88,10 +96,20 @@ export let compare = ( return orderCoefficient * sortingFunction(a, b) } -let getFormatStringFunc = (ignoreCase: boolean) => (value: string) => { - let valueToCompare = value - if (ignoreCase) { - valueToCompare = valueToCompare.toLowerCase() +let getFormatStringFunc = + (ignoreCase: boolean, specialCharacters: 'remove' | 'trim' | 'keep') => + (value: string) => { + let valueToCompare = value + if (ignoreCase) { + valueToCompare = valueToCompare.toLowerCase() + } + switch (specialCharacters) { + case 'remove': + valueToCompare = valueToCompare.replaceAll(/[^A-Za-zÀ-ž]+/g, '') + break + case 'trim': + valueToCompare = valueToCompare.replaceAll(/^[^A-Za-zÀ-ž]+/g, '') + break + } + return valueToCompare.replaceAll(/\s/g, '') } - return valueToCompare.replaceAll(/\s/g, '') -}