From c739e3080a9d4893d813a6fac443107aa625f914 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 13 Dec 2024 01:40:39 +0100 Subject: [PATCH 1/7] refactor: extracts `sorting-node` into its own file --- typings/index.ts | 12 +----------- typings/sorting-node.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 typings/sorting-node.ts diff --git a/typings/index.ts b/typings/index.ts index 72d53c5eb..458b9dd06 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -1,11 +1 @@ -import type { TSESTree } from '@typescript-eslint/types' - -export interface SortingNode { - hasMultipleImportDeclarations?: boolean - addSafetySemicolonWhenInline?: boolean - isEslintDisabled: boolean - group?: string - name: string - size: number - node: Node -} +export type { SortingNode } from './sorting-node' diff --git a/typings/sorting-node.ts b/typings/sorting-node.ts new file mode 100644 index 000000000..72d53c5eb --- /dev/null +++ b/typings/sorting-node.ts @@ -0,0 +1,11 @@ +import type { TSESTree } from '@typescript-eslint/types' + +export interface SortingNode { + hasMultipleImportDeclarations?: boolean + addSafetySemicolonWhenInline?: boolean + isEslintDisabled: boolean + group?: string + name: string + size: number + node: Node +} From 86883c083fa32369e7cffc241d9d538cada1e271 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 13 Dec 2024 01:48:29 +0100 Subject: [PATCH 2/7] refactor: extracts `with-dash-or-empty` into its own file --- rules/sort-classes.types.ts | 4 ++-- rules/sort-modules.types.ts | 4 ++-- rules/sort-object-types.types.ts | 4 ++-- typings/index.ts | 1 + typings/with-dash-suffix-or-empty.ts | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 typings/with-dash-suffix-or-empty.ts diff --git a/rules/sort-classes.types.ts b/rules/sort-classes.types.ts index 8044df813..a02beea20 100644 --- a/rules/sort-classes.types.ts +++ b/rules/sort-classes.types.ts @@ -1,5 +1,7 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' +import type { WithDashSuffixOrEmpty, Join } from '../typings' + import { buildCustomGroupModifiersJsonSchema, buildCustomGroupSelectorJsonSchema, @@ -260,8 +262,6 @@ type StaticModifierPrefix = WithDashSuffixOrEmpty type AsyncModifierPrefix = WithDashSuffixOrEmpty -type WithDashSuffixOrEmpty = `${T}-` | '' - type FunctionPropertySelector = 'function-property' type AccessorPropertySelector = 'accessor-property' diff --git a/rules/sort-modules.types.ts b/rules/sort-modules.types.ts index cf73cc1aa..28acbec57 100644 --- a/rules/sort-modules.types.ts +++ b/rules/sort-modules.types.ts @@ -1,5 +1,7 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' +import type { WithDashSuffixOrEmpty } from '../typings' + import { buildCustomGroupModifiersJsonSchema, buildCustomGroupSelectorJsonSchema, @@ -139,8 +141,6 @@ type ExportModifierPrefix = WithDashSuffixOrEmpty type AsyncModifierPrefix = WithDashSuffixOrEmpty -type WithDashSuffixOrEmpty = `${T}-` | '' - type DecoratedModifier = 'decorated' type InterfaceSelector = 'interface' diff --git a/rules/sort-object-types.types.ts b/rules/sort-object-types.types.ts index e2414f1a3..4624903d5 100644 --- a/rules/sort-object-types.types.ts +++ b/rules/sort-object-types.types.ts @@ -1,5 +1,7 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' +import type { WithDashSuffixOrEmpty, Join } from '../typings' + import { buildCustomGroupModifiersJsonSchema, buildCustomGroupSelectorJsonSchema, @@ -115,8 +117,6 @@ type RequiredModifierPrefix = WithDashSuffixOrEmpty type OptionalModifierPrefix = WithDashSuffixOrEmpty -type WithDashSuffixOrEmpty = `${T}-` | '' - type IndexSignatureSelector = 'index-signature' /** diff --git a/typings/index.ts b/typings/index.ts index 458b9dd06..c18f48f0d 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -1 +1,2 @@ +export type { WithDashSuffixOrEmpty } from './with-dash-suffix-or-empty' export type { SortingNode } from './sorting-node' diff --git a/typings/with-dash-suffix-or-empty.ts b/typings/with-dash-suffix-or-empty.ts new file mode 100644 index 000000000..25cb75a62 --- /dev/null +++ b/typings/with-dash-suffix-or-empty.ts @@ -0,0 +1 @@ +export type WithDashSuffixOrEmpty = `${T}-` | '' From 8e835782e550ee7fd65b4022471753f574ca7083 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 13 Dec 2024 01:49:20 +0100 Subject: [PATCH 3/7] refactor: extracts `Join` into its own file --- rules/sort-classes.types.ts | 7 ------- typings/index.ts | 1 + typings/join.ts | 6 ++++++ 3 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 typings/join.ts diff --git a/rules/sort-classes.types.ts b/rules/sort-classes.types.ts index a02beea20..cdd4df435 100644 --- a/rules/sort-classes.types.ts +++ b/rules/sort-classes.types.ts @@ -221,13 +221,6 @@ type AdvancedSingleCustomGroup = { elementNamePattern?: string } & BaseSingleCustomGroup -type Join = T extends [ - infer First extends string, - ...infer Rest extends string[], -] - ? `${First}${Join}` - : '' - type PublicOrProtectedOrPrivateModifierPrefix = WithDashSuffixOrEmpty< ProtectedModifier | PrivateModifier | PublicModifier > diff --git a/typings/index.ts b/typings/index.ts index c18f48f0d..9b176e0cb 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -1,2 +1,3 @@ export type { WithDashSuffixOrEmpty } from './with-dash-suffix-or-empty' export type { SortingNode } from './sorting-node' +export type { Join } from './join' diff --git a/typings/join.ts b/typings/join.ts new file mode 100644 index 000000000..c53d9b9de --- /dev/null +++ b/typings/join.ts @@ -0,0 +1,6 @@ +export type Join = T extends [ + infer First extends string, + ...infer Rest extends string[], +] + ? `${First}${Join}` + : '' From 9a189f2a1b5ac891ff6adcf8a841d859fef860d1 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 13 Dec 2024 12:22:16 +0100 Subject: [PATCH 4/7] refactor: uses `Join` in other rules --- rules/sort-modules.types.ts | 61 ++++++++++++++++++++++---------- rules/sort-object-types.types.ts | 32 ++++++++++++----- 2 files changed, 66 insertions(+), 27 deletions(-) diff --git a/rules/sort-modules.types.ts b/rules/sort-modules.types.ts index 28acbec57..b3e719962 100644 --- a/rules/sort-modules.types.ts +++ b/rules/sort-modules.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { WithDashSuffixOrEmpty } from '../typings' +import type { WithDashSuffixOrEmpty, Join } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -94,34 +94,57 @@ type Group = | 'unknown' | string -type NonDefaultClassGroup = - `${ExportModifierPrefix}${DeclareModifierPrefix}${DecoratedModifierPrefix}${ClassSelector}` - -type DefaultFunctionGroup = - `${ExportModifierPrefix}${DefaultModifierPrefix}${AsyncModifierPrefix}${FunctionSelector}` - -type DefaultClassGroup = - `${ExportModifierPrefix}${DefaultModifierPrefix}${DecoratedModifierPrefix}${ClassSelector}` +type NonDefaultClassGroup = Join< + [ + ExportModifierPrefix, + DeclareModifierPrefix, + DecoratedModifierPrefix, + ClassSelector, + ] +> + +type DefaultFunctionGroup = Join< + [ + ExportModifierPrefix, + DefaultModifierPrefix, + AsyncModifierPrefix, + FunctionSelector, + ] +> + +type DefaultClassGroup = Join< + [ + ExportModifierPrefix, + DefaultModifierPrefix, + DecoratedModifierPrefix, + ClassSelector, + ] +> interface BaseSingleCustomGroup { modifiers?: AllowedModifiersPerSelector[T][] selector?: T } -type NonDefaultInterfaceGroup = - `${ExportModifierPrefix}${DeclareModifierPrefix}${InterfaceSelector}` +type NonDefaultInterfaceGroup = Join< + [ExportModifierPrefix, DeclareModifierPrefix, InterfaceSelector] +> -type NonDefaultFunctionGroup = - `${ExportModifierPrefix}${DeclareModifierPrefix}${FunctionSelector}` +type NonDefaultFunctionGroup = Join< + [ExportModifierPrefix, DeclareModifierPrefix, FunctionSelector] +> -type DefaultInterfaceGroup = - `${ExportModifierPrefix}${DefaultModifierPrefix}${InterfaceSelector}` +type DefaultInterfaceGroup = Join< + [ExportModifierPrefix, DefaultModifierPrefix, InterfaceSelector] +> -type TypeGroup = - `${ExportModifierPrefix}${DeclareModifierPrefix}${TypeSelector}` +type TypeGroup = Join< + [ExportModifierPrefix, DeclareModifierPrefix, TypeSelector] +> -type EnumGroup = - `${ExportModifierPrefix}${DeclareModifierPrefix}${EnumSelector}` +type EnumGroup = Join< + [ExportModifierPrefix, DeclareModifierPrefix, EnumSelector] +> interface DecoratorNamePatternFilterCustomGroup { decoratorNamePattern?: string diff --git a/rules/sort-object-types.types.ts b/rules/sort-object-types.types.ts index 4624903d5..c56b66064 100644 --- a/rules/sort-object-types.types.ts +++ b/rules/sort-object-types.types.ts @@ -75,6 +75,24 @@ type CustomGroup = ( groupName: string } +type MemberGroup = Join< + [ + OptionalModifierPrefix, + RequiredModifierPrefix, + MultilineModifierPrefix, + MemberSelector, + ] +> + +type MethodGroup = Join< + [ + OptionalModifierPrefix, + RequiredModifierPrefix, + MultilineModifierPrefix, + MethodSelector, + ] +> + type IndexSignatureGroup = `${OptionalModifierPrefix | RequiredModifierPrefix}${MultilineModifierPrefix}${IndexSignatureSelector}` @@ -98,14 +116,12 @@ interface BaseSingleCustomGroup { selector?: T } -type MemberGroup = - `${OptionalModifierPrefix | RequiredModifierPrefix}${MultilineModifierPrefix}${MemberSelector}` - -type MethodGroup = - `${OptionalModifierPrefix | RequiredModifierPrefix}${MultilineModifierPrefix}${MethodSelector}` - -type MultilineGroup = - `${OptionalModifierPrefix | RequiredModifierPrefix}${MultilineSelector}` +/** + * @deprecated For {@link `MultilineModifier`} + */ +type MultilineGroup = Join< + [OptionalModifierPrefix, RequiredModifierPrefix, MultilineSelector] +> interface ElementNamePatternFilterCustomGroup { elementNamePattern?: string From c510ce7471eb87073b3d579ed7ccae1b3e9b9aa9 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 13 Dec 2024 12:22:19 +0100 Subject: [PATCH 5/7] refactor: improves `Join` to handle `-` natively --- rules/sort-classes.types.ts | 132 ++++++++++++--------------- rules/sort-modules.types.ts | 57 +++--------- rules/sort-object-types.types.ts | 47 ++++------ typings/index.ts | 1 - typings/join.ts | 8 +- typings/with-dash-suffix-or-empty.ts | 1 - 6 files changed, 95 insertions(+), 151 deletions(-) delete mode 100644 typings/with-dash-suffix-or-empty.ts diff --git a/rules/sort-classes.types.ts b/rules/sort-classes.types.ts index cdd4df435..b84dffc4b 100644 --- a/rules/sort-classes.types.ts +++ b/rules/sort-classes.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { WithDashSuffixOrEmpty, Join } from '../typings' +import type { Join } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -36,42 +36,6 @@ export type SingleCustomGroup = | BaseSingleCustomGroup | AdvancedSingleCustomGroup -export type NonDeclarePropertyGroup = Join< - [ - PublicOrProtectedOrPrivateModifierPrefix, - StaticOrAbstractModifierPrefix, - OverrideModifierPrefix, - ReadonlyModifierPrefix, - DecoratedModifierPrefix, - OptionalModifierPrefix, - PropertySelector, - ] -> - -export type FunctionPropertyGroup = Join< - [ - PublicOrProtectedOrPrivateModifierPrefix, - StaticModifierPrefix, - OverrideModifierPrefix, - ReadonlyModifierPrefix, - DecoratedModifierPrefix, - AsyncModifierPrefix, - FunctionPropertySelector, - ] -> - -export type MethodGroup = Join< - [ - PublicOrProtectedOrPrivateModifierPrefix, - StaticOrAbstractModifierPrefix, - OverrideModifierPrefix, - DecoratedModifierPrefix, - AsyncModifierPrefix, - OptionalModifierPrefix, - MethodSelector, - ] -> - export type Selector = | AccessorPropertySelector | FunctionPropertySelector @@ -83,24 +47,27 @@ export type Selector = | PropertySelector | MethodSelector -export type DeclarePropertyGroup = Join< +export type NonDeclarePropertyGroup = Join< [ - DeclareModifierPrefix, - PublicOrProtectedOrPrivateModifierPrefix, - StaticOrAbstractModifierPrefix, - ReadonlyModifierPrefix, - OptionalModifierPrefix, + PublicOrProtectedOrPrivateModifier, + StaticOrAbstractModifier, + OverrideModifier, + ReadonlyModifier, + DecoratedModifier, + OptionalModifier, PropertySelector, ] > -export type GetMethodOrSetMethodGroup = Join< +export type FunctionPropertyGroup = Join< [ - PublicOrProtectedOrPrivateModifierPrefix, - StaticOrAbstractModifierPrefix, - OverrideModifierPrefix, - DecoratedModifierPrefix, - GetMethodOrSetMethodSelector, + PublicOrProtectedOrPrivateModifier, + StaticModifier, + OverrideModifier, + ReadonlyModifier, + DecoratedModifier, + AsyncModifier, + FunctionPropertySelector, ] > @@ -115,22 +82,55 @@ export type Modifier = | StaticModifier | AsyncModifier +export type MethodGroup = Join< + [ + PublicOrProtectedOrPrivateModifier, + StaticOrAbstractModifier, + OverrideModifier, + DecoratedModifier, + AsyncModifier, + OptionalModifier, + MethodSelector, + ] +> + +export type DeclarePropertyGroup = Join< + [ + DeclareModifier, + PublicOrProtectedOrPrivateModifier, + StaticOrAbstractModifier, + ReadonlyModifier, + OptionalModifier, + PropertySelector, + ] +> + +export type GetMethodOrSetMethodGroup = Join< + [ + PublicOrProtectedOrPrivateModifier, + StaticOrAbstractModifier, + OverrideModifier, + DecoratedModifier, + GetMethodOrSetMethodSelector, + ] +> + export type AccessorPropertyGroup = Join< [ - PublicOrProtectedOrPrivateModifierPrefix, - StaticOrAbstractModifierPrefix, - OverrideModifierPrefix, - DecoratedModifierPrefix, + PublicOrProtectedOrPrivateModifier, + StaticOrAbstractModifier, + OverrideModifier, + DecoratedModifier, AccessorPropertySelector, ] > export type IndexSignatureGroup = Join< - [StaticModifierPrefix, ReadonlyModifierPrefix, IndexSignatureSelector] + [StaticModifier, ReadonlyModifier, IndexSignatureSelector] > export type ConstructorGroup = Join< - [PublicOrProtectedOrPrivateModifierPrefix, ConstructorSelector] + [PublicOrProtectedOrPrivateModifier, ConstructorSelector] > export interface AnyOfCustomGroup { @@ -221,10 +221,6 @@ type AdvancedSingleCustomGroup = { elementNamePattern?: string } & BaseSingleCustomGroup -type PublicOrProtectedOrPrivateModifierPrefix = WithDashSuffixOrEmpty< - ProtectedModifier | PrivateModifier | PublicModifier -> - interface BaseSingleCustomGroup { modifiers?: AllowedModifiersPerSelector[T][] selector?: T @@ -235,25 +231,9 @@ type PublicOrProtectedOrPrivateModifier = | PrivateModifier | PublicModifier -type StaticOrAbstractModifierPrefix = WithDashSuffixOrEmpty< - AbstractModifier | StaticModifier -> - type GetMethodOrSetMethodSelector = GetMethodSelector | SetMethodSelector -type DecoratedModifierPrefix = WithDashSuffixOrEmpty - -type OverrideModifierPrefix = WithDashSuffixOrEmpty - -type OptionalModifierPrefix = WithDashSuffixOrEmpty - -type ReadonlyModifierPrefix = WithDashSuffixOrEmpty - -type DeclareModifierPrefix = WithDashSuffixOrEmpty - -type StaticModifierPrefix = WithDashSuffixOrEmpty - -type AsyncModifierPrefix = WithDashSuffixOrEmpty +type StaticOrAbstractModifier = AbstractModifier | StaticModifier type FunctionPropertySelector = 'function-property' diff --git a/rules/sort-modules.types.ts b/rules/sort-modules.types.ts index b3e719962..eebc526e6 100644 --- a/rules/sort-modules.types.ts +++ b/rules/sort-modules.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { WithDashSuffixOrEmpty, Join } from '../typings' +import type { Join } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -94,56 +94,33 @@ type Group = | 'unknown' | string +interface BaseSingleCustomGroup { + modifiers?: AllowedModifiersPerSelector[T][] + selector?: T +} + type NonDefaultClassGroup = Join< - [ - ExportModifierPrefix, - DeclareModifierPrefix, - DecoratedModifierPrefix, - ClassSelector, - ] + [ExportModifier, DeclareModifier, DecoratedModifier, ClassSelector] > type DefaultFunctionGroup = Join< - [ - ExportModifierPrefix, - DefaultModifierPrefix, - AsyncModifierPrefix, - FunctionSelector, - ] + [ExportModifier, DefaultModifier, AsyncModifier, FunctionSelector] > type DefaultClassGroup = Join< - [ - ExportModifierPrefix, - DefaultModifierPrefix, - DecoratedModifierPrefix, - ClassSelector, - ] + [ExportModifier, DefaultModifier, DecoratedModifier, ClassSelector] > -interface BaseSingleCustomGroup { - modifiers?: AllowedModifiersPerSelector[T][] - selector?: T -} - type NonDefaultInterfaceGroup = Join< - [ExportModifierPrefix, DeclareModifierPrefix, InterfaceSelector] + [ExportModifier, DeclareModifier, InterfaceSelector] > type NonDefaultFunctionGroup = Join< - [ExportModifierPrefix, DeclareModifierPrefix, FunctionSelector] + [ExportModifier, DeclareModifier, FunctionSelector] > type DefaultInterfaceGroup = Join< - [ExportModifierPrefix, DefaultModifierPrefix, InterfaceSelector] -> - -type TypeGroup = Join< - [ExportModifierPrefix, DeclareModifierPrefix, TypeSelector] -> - -type EnumGroup = Join< - [ExportModifierPrefix, DeclareModifierPrefix, EnumSelector] + [ExportModifier, DefaultModifier, InterfaceSelector] > interface DecoratorNamePatternFilterCustomGroup { @@ -154,15 +131,9 @@ interface ElementNamePatternFilterCustomGroup { elementNamePattern?: string } -type DecoratedModifierPrefix = WithDashSuffixOrEmpty - -type DeclareModifierPrefix = WithDashSuffixOrEmpty - -type DefaultModifierPrefix = WithDashSuffixOrEmpty - -type ExportModifierPrefix = WithDashSuffixOrEmpty +type TypeGroup = Join<[ExportModifier, DeclareModifier, TypeSelector]> -type AsyncModifierPrefix = WithDashSuffixOrEmpty +type EnumGroup = Join<[ExportModifier, DeclareModifier, EnumSelector]> type DecoratedModifier = 'decorated' diff --git a/rules/sort-object-types.types.ts b/rules/sort-object-types.types.ts index c56b66064..14d9d8681 100644 --- a/rules/sort-object-types.types.ts +++ b/rules/sort-object-types.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { WithDashSuffixOrEmpty, Join } from '../typings' +import type { Join } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -75,27 +75,15 @@ type CustomGroup = ( groupName: string } -type MemberGroup = Join< - [ - OptionalModifierPrefix, - RequiredModifierPrefix, - MultilineModifierPrefix, - MemberSelector, - ] -> - -type MethodGroup = Join< +type IndexSignatureGroup = Join< [ - OptionalModifierPrefix, - RequiredModifierPrefix, - MultilineModifierPrefix, - MethodSelector, + OptionalModifier, + RequiredModifier, + MultilineModifier, + IndexSignatureSelector, ] > -type IndexSignatureGroup = - `${OptionalModifierPrefix | RequiredModifierPrefix}${MultilineModifierPrefix}${IndexSignatureSelector}` - /** * Only used in code, so I don't know if it's worth maintaining this. */ @@ -108,31 +96,34 @@ type Group = | 'unknown' | string -type PropertyGroup = - `${OptionalModifierPrefix | RequiredModifierPrefix}${MultilineModifierPrefix}${PropertySelector}` - interface BaseSingleCustomGroup { modifiers?: AllowedModifiersPerSelector[T][] selector?: T } +type PropertyGroup = Join< + [OptionalModifier, RequiredModifier, MultilineModifier, PropertySelector] +> + +type MemberGroup = Join< + [OptionalModifier, RequiredModifier, MultilineModifier, MemberSelector] +> + +type MethodGroup = Join< + [OptionalModifier, RequiredModifier, MultilineModifier, MethodSelector] +> + /** * @deprecated For {@link `MultilineModifier`} */ type MultilineGroup = Join< - [OptionalModifierPrefix, RequiredModifierPrefix, MultilineSelector] + [OptionalModifier, RequiredModifier, MultilineSelector] > interface ElementNamePatternFilterCustomGroup { elementNamePattern?: string } -type MultilineModifierPrefix = WithDashSuffixOrEmpty - -type RequiredModifierPrefix = WithDashSuffixOrEmpty - -type OptionalModifierPrefix = WithDashSuffixOrEmpty - type IndexSignatureSelector = 'index-signature' /** diff --git a/typings/index.ts b/typings/index.ts index 9b176e0cb..a754e0285 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -1,3 +1,2 @@ -export type { WithDashSuffixOrEmpty } from './with-dash-suffix-or-empty' export type { SortingNode } from './sorting-node' export type { Join } from './join' diff --git a/typings/join.ts b/typings/join.ts index c53d9b9de..c901beebf 100644 --- a/typings/join.ts +++ b/typings/join.ts @@ -2,5 +2,9 @@ export type Join = T extends [ infer First extends string, ...infer Rest extends string[], ] - ? `${First}${Join}` - : '' + ? Rest extends [] + ? `${First}` + : `${WithDashSuffixOrEmpty}${Join}` + : never + +type WithDashSuffixOrEmpty = `${T}-` | '' diff --git a/typings/with-dash-suffix-or-empty.ts b/typings/with-dash-suffix-or-empty.ts deleted file mode 100644 index 25cb75a62..000000000 --- a/typings/with-dash-suffix-or-empty.ts +++ /dev/null @@ -1 +0,0 @@ -export type WithDashSuffixOrEmpty = `${T}-` | '' From e7046d26b1cde218e42f9034dd753143495afa87 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 13 Dec 2024 12:16:55 +0100 Subject: [PATCH 6/7] refactor: renames `Join` to `JoinWithDash` --- rules/sort-classes.types.ts | 52 +++++++++++++------------- rules/sort-modules.types.ts | 18 ++++----- rules/sort-object-types.types.ts | 12 +++--- typings/index.ts | 2 +- typings/{join.ts => join-with-dash.ts} | 4 +- 5 files changed, 44 insertions(+), 44 deletions(-) rename typings/{join.ts => join-with-dash.ts} (59%) diff --git a/rules/sort-classes.types.ts b/rules/sort-classes.types.ts index b84dffc4b..78839c14a 100644 --- a/rules/sort-classes.types.ts +++ b/rules/sort-classes.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { Join } from '../typings' +import type { JoinWithDash } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -36,6 +36,18 @@ export type SingleCustomGroup = | BaseSingleCustomGroup | AdvancedSingleCustomGroup +export type NonDeclarePropertyGroup = JoinWithDash< + [ + PublicOrProtectedOrPrivateModifier, + StaticOrAbstractModifier, + OverrideModifier, + ReadonlyModifier, + DecoratedModifier, + OptionalModifier, + PropertySelector, + ] +> + export type Selector = | AccessorPropertySelector | FunctionPropertySelector @@ -47,27 +59,27 @@ export type Selector = | PropertySelector | MethodSelector -export type NonDeclarePropertyGroup = Join< +export type FunctionPropertyGroup = JoinWithDash< [ PublicOrProtectedOrPrivateModifier, - StaticOrAbstractModifier, + StaticModifier, OverrideModifier, ReadonlyModifier, DecoratedModifier, - OptionalModifier, - PropertySelector, + AsyncModifier, + FunctionPropertySelector, ] > -export type FunctionPropertyGroup = Join< +export type MethodGroup = JoinWithDash< [ PublicOrProtectedOrPrivateModifier, - StaticModifier, + StaticOrAbstractModifier, OverrideModifier, - ReadonlyModifier, DecoratedModifier, AsyncModifier, - FunctionPropertySelector, + OptionalModifier, + MethodSelector, ] > @@ -82,19 +94,7 @@ export type Modifier = | StaticModifier | AsyncModifier -export type MethodGroup = Join< - [ - PublicOrProtectedOrPrivateModifier, - StaticOrAbstractModifier, - OverrideModifier, - DecoratedModifier, - AsyncModifier, - OptionalModifier, - MethodSelector, - ] -> - -export type DeclarePropertyGroup = Join< +export type DeclarePropertyGroup = JoinWithDash< [ DeclareModifier, PublicOrProtectedOrPrivateModifier, @@ -105,7 +105,7 @@ export type DeclarePropertyGroup = Join< ] > -export type GetMethodOrSetMethodGroup = Join< +export type GetMethodOrSetMethodGroup = JoinWithDash< [ PublicOrProtectedOrPrivateModifier, StaticOrAbstractModifier, @@ -115,7 +115,7 @@ export type GetMethodOrSetMethodGroup = Join< ] > -export type AccessorPropertyGroup = Join< +export type AccessorPropertyGroup = JoinWithDash< [ PublicOrProtectedOrPrivateModifier, StaticOrAbstractModifier, @@ -125,11 +125,11 @@ export type AccessorPropertyGroup = Join< ] > -export type IndexSignatureGroup = Join< +export type IndexSignatureGroup = JoinWithDash< [StaticModifier, ReadonlyModifier, IndexSignatureSelector] > -export type ConstructorGroup = Join< +export type ConstructorGroup = JoinWithDash< [PublicOrProtectedOrPrivateModifier, ConstructorSelector] > diff --git a/rules/sort-modules.types.ts b/rules/sort-modules.types.ts index eebc526e6..fa1af6bb5 100644 --- a/rules/sort-modules.types.ts +++ b/rules/sort-modules.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { Join } from '../typings' +import type { JoinWithDash } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -99,27 +99,27 @@ interface BaseSingleCustomGroup { selector?: T } -type NonDefaultClassGroup = Join< +type NonDefaultClassGroup = JoinWithDash< [ExportModifier, DeclareModifier, DecoratedModifier, ClassSelector] > -type DefaultFunctionGroup = Join< +type DefaultFunctionGroup = JoinWithDash< [ExportModifier, DefaultModifier, AsyncModifier, FunctionSelector] > -type DefaultClassGroup = Join< +type DefaultClassGroup = JoinWithDash< [ExportModifier, DefaultModifier, DecoratedModifier, ClassSelector] > -type NonDefaultInterfaceGroup = Join< +type NonDefaultInterfaceGroup = JoinWithDash< [ExportModifier, DeclareModifier, InterfaceSelector] > -type NonDefaultFunctionGroup = Join< +type NonDefaultFunctionGroup = JoinWithDash< [ExportModifier, DeclareModifier, FunctionSelector] > -type DefaultInterfaceGroup = Join< +type DefaultInterfaceGroup = JoinWithDash< [ExportModifier, DefaultModifier, InterfaceSelector] > @@ -131,9 +131,9 @@ interface ElementNamePatternFilterCustomGroup { elementNamePattern?: string } -type TypeGroup = Join<[ExportModifier, DeclareModifier, TypeSelector]> +type TypeGroup = JoinWithDash<[ExportModifier, DeclareModifier, TypeSelector]> -type EnumGroup = Join<[ExportModifier, DeclareModifier, EnumSelector]> +type EnumGroup = JoinWithDash<[ExportModifier, DeclareModifier, EnumSelector]> type DecoratedModifier = 'decorated' diff --git a/rules/sort-object-types.types.ts b/rules/sort-object-types.types.ts index 14d9d8681..5f26f6023 100644 --- a/rules/sort-object-types.types.ts +++ b/rules/sort-object-types.types.ts @@ -1,6 +1,6 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' -import type { Join } from '../typings' +import type { JoinWithDash } from '../typings' import { buildCustomGroupModifiersJsonSchema, @@ -75,7 +75,7 @@ type CustomGroup = ( groupName: string } -type IndexSignatureGroup = Join< +type IndexSignatureGroup = JoinWithDash< [ OptionalModifier, RequiredModifier, @@ -101,22 +101,22 @@ interface BaseSingleCustomGroup { selector?: T } -type PropertyGroup = Join< +type PropertyGroup = JoinWithDash< [OptionalModifier, RequiredModifier, MultilineModifier, PropertySelector] > -type MemberGroup = Join< +type MemberGroup = JoinWithDash< [OptionalModifier, RequiredModifier, MultilineModifier, MemberSelector] > -type MethodGroup = Join< +type MethodGroup = JoinWithDash< [OptionalModifier, RequiredModifier, MultilineModifier, MethodSelector] > /** * @deprecated For {@link `MultilineModifier`} */ -type MultilineGroup = Join< +type MultilineGroup = JoinWithDash< [OptionalModifier, RequiredModifier, MultilineSelector] > diff --git a/typings/index.ts b/typings/index.ts index a754e0285..6beb32cd7 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -1,2 +1,2 @@ +export type { JoinWithDash } from './join-with-dash' export type { SortingNode } from './sorting-node' -export type { Join } from './join' diff --git a/typings/join.ts b/typings/join-with-dash.ts similarity index 59% rename from typings/join.ts rename to typings/join-with-dash.ts index c901beebf..e7a73c247 100644 --- a/typings/join.ts +++ b/typings/join-with-dash.ts @@ -1,10 +1,10 @@ -export type Join = T extends [ +export type JoinWithDash = T extends [ infer First extends string, ...infer Rest extends string[], ] ? Rest extends [] ? `${First}` - : `${WithDashSuffixOrEmpty}${Join}` + : `${WithDashSuffixOrEmpty}${JoinWithDash}` : never type WithDashSuffixOrEmpty = `${T}-` | '' From a25540611d7d34ca64ff06c6bfbc472b201a33c2 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Sat, 14 Dec 2024 15:32:26 +0100 Subject: [PATCH 7/7] refactor: [FEEDBACK] adds parameter to `Join` --- typings/join-with-dash.ts | 11 ++--------- typings/join.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 typings/join.ts diff --git a/typings/join-with-dash.ts b/typings/join-with-dash.ts index e7a73c247..9fd41f182 100644 --- a/typings/join-with-dash.ts +++ b/typings/join-with-dash.ts @@ -1,10 +1,3 @@ -export type JoinWithDash = T extends [ - infer First extends string, - ...infer Rest extends string[], -] - ? Rest extends [] - ? `${First}` - : `${WithDashSuffixOrEmpty}${JoinWithDash}` - : never +import type { Join } from './join' -type WithDashSuffixOrEmpty = `${T}-` | '' +export type JoinWithDash = Join diff --git a/typings/join.ts b/typings/join.ts new file mode 100644 index 000000000..6256565cf --- /dev/null +++ b/typings/join.ts @@ -0,0 +1,12 @@ +export type Join = T extends [ + infer First extends string, + ...infer Rest extends string[], +] + ? Rest extends [] + ? `${First}` + : `${WithSeparatorOrEmpty}${Join}` + : never + +type WithSeparatorOrEmpty = + | `${T}${Separator}` + | ''