From e672b3605b430671681f664682773fe04d9bedd6 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Sat, 19 Oct 2024 22:03:55 +0200 Subject: [PATCH 1/6] refactor: regroups default options in a const --- rules/sort-array-includes.ts | 35 +++++-------- rules/sort-classes.ts | 81 +++++++++++++---------------- rules/sort-decorators.ts | 50 +++++++----------- rules/sort-enums.ts | 38 ++++++-------- rules/sort-exports.ts | 35 +++++-------- rules/sort-heritage-clauses.ts | 32 +++++------- rules/sort-interfaces.ts | 46 +++++++--------- rules/sort-intersection-types.ts | 37 ++++++------- rules/sort-jsx-props.ts | 35 +++++-------- rules/sort-maps.ts | 32 +++++------- rules/sort-named-exports.ts | 35 +++++-------- rules/sort-named-imports.ts | 37 ++++++------- rules/sort-object-types.ts | 44 ++++++---------- rules/sort-objects.ts | 49 +++++++---------- rules/sort-sets.ts | 13 +---- rules/sort-switch-case.ts | 23 ++++---- rules/sort-union-types.ts | 37 ++++++------- rules/sort-variable-declarations.ts | 32 +++++------- 18 files changed, 276 insertions(+), 415 deletions(-) diff --git a/rules/sort-array-includes.ts b/rules/sort-array-includes.ts index 8e7e0238..b0d06175 100644 --- a/rules/sort-array-includes.ts +++ b/rules/sort-array-includes.ts @@ -35,6 +35,17 @@ export type Options = [ }>, ] +export const defaultOptions: Required = { + groupKind: 'literals-first', + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + matcher: 'minimatch', + order: 'asc', + partitionByComment: false, + partitionByNewLine: false, +} + export let jsonSchema: JSONSchema4 = { type: 'object', properties: { @@ -110,18 +121,7 @@ export default createEslintRule({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - groupKind: 'literals-first', - partitionByComment: false, - partitionByNewLine: false, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ MemberExpression: node => { if ( @@ -149,15 +149,8 @@ export let sortArray = ( if (elements.length > 1) { let options = complete(context.options.at(0), settings, { - groupKind: 'literals-first', - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - order: 'asc', - partitionByComment: false, - partitionByNewLine: false, - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index 8d2ba26b..17d5c0b4 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -43,30 +43,39 @@ type MESSAGE_ID = | 'unexpectedClassesGroupOrder' | 'unexpectedClassesOrder' -const defaultGroups: SortClassesOptions[0]['groups'] = [ - 'index-signature', - ['static-property', 'static-accessor-property'], - ['static-get-method', 'static-set-method'], - ['protected-static-property', 'protected-static-accessor-property'], - ['protected-static-get-method', 'protected-static-set-method'], - ['private-static-property', 'private-static-accessor-property'], - ['private-static-get-method', 'private-static-set-method'], - 'static-block', - ['property', 'accessor-property'], - ['get-method', 'set-method'], - ['protected-property', 'protected-accessor-property'], - ['protected-get-method', 'protected-set-method'], - ['private-property', 'private-accessor-property'], - ['private-get-method', 'private-set-method'], - 'constructor', - ['static-method', 'static-function-property'], - ['protected-static-method', 'protected-static-function-property'], - ['private-static-method', 'private-static-function-property'], - ['method', 'function-property'], - ['protected-method', 'protected-function-property'], - ['private-method', 'private-function-property'], - 'unknown', -] +const defaultOptions: Required = { + groups: [ + 'index-signature', + ['static-property', 'static-accessor-property'], + ['static-get-method', 'static-set-method'], + ['protected-static-property', 'protected-static-accessor-property'], + ['protected-static-get-method', 'protected-static-set-method'], + ['private-static-property', 'private-static-accessor-property'], + ['private-static-get-method', 'private-static-set-method'], + 'static-block', + ['property', 'accessor-property'], + ['get-method', 'set-method'], + ['protected-property', 'protected-accessor-property'], + ['protected-get-method', 'protected-set-method'], + ['private-property', 'private-accessor-property'], + ['private-get-method', 'private-set-method'], + 'constructor', + ['static-method', 'static-function-property'], + ['protected-static-method', 'protected-static-function-property'], + ['private-static-method', 'private-static-function-property'], + ['method', 'function-property'], + ['protected-method', 'protected-function-property'], + ['private-method', 'private-function-property'], + 'unknown', + ], + matcher: 'minimatch', + partitionByComment: false, + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + customGroups: [], + order: 'asc', +} export default createEslintRule({ name: 'sort-classes', @@ -192,33 +201,15 @@ export default createEslintRule({ 'Expected dependency "{{right}}" to come before "{{nodeDependentOnRight}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByComment: false, - groups: defaultGroups, - customGroups: [], - }, - ], + defaultOptions: [defaultOptions], create: context => ({ ClassBody: node => { if (node.body.length > 1) { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - groups: defaultGroups, - matcher: 'minimatch', - partitionByComment: false, - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - customGroups: [], - order: 'asc', - } as const) + ...defaultOptions, + }) validateGroupsConfiguration(options.groups, options.customGroups) diff --git a/rules/sort-decorators.ts b/rules/sort-decorators.ts index 6b762aad..9ef64e72 100644 --- a/rules/sort-decorators.ts +++ b/rules/sort-decorators.ts @@ -43,6 +43,22 @@ export type Options = [ type SortDecoratorsSortingNode = SortingNode +const defaultOptions: Required[0]> = { + type: 'alphabetical', + matcher: 'minimatch', + ignoreCase: true, + specialCharacters: 'keep', + partitionByComment: false, + customGroups: {}, + order: 'asc', + groups: [], + sortOnClasses: true, + sortOnMethods: true, + sortOnAccessors: true, + sortOnProperties: true, + sortOnParameters: true, +} + export default createEslintRule, MESSAGE_ID>({ name: 'sort-decorators', meta: { @@ -170,41 +186,13 @@ export default createEslintRule, MESSAGE_ID>({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - partitionByComment: false, - matcher: 'minimatch', - groups: [], - customGroups: {}, - sortOnClasses: true, - sortOnMethods: true, - sortOnAccessors: true, - sortOnProperties: true, - sortOnParameters: true, - }, - ], + defaultOptions: [defaultOptions], create: context => { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - matcher: 'minimatch', - ignoreCase: true, - specialCharacters: 'keep', - partitionByComment: false, - customGroups: {}, - order: 'asc', - groups: [], - sortOnClasses: true, - sortOnMethods: true, - sortOnAccessors: true, - sortOnProperties: true, - sortOnParameters: true, - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-enums.ts b/rules/sort-enums.ts index 64a4ca39..2024ffb3 100644 --- a/rules/sort-enums.ts +++ b/rules/sort-enums.ts @@ -36,6 +36,18 @@ export type Options = [ }>, ] +const defaultOptions: Required = { + partitionByComment: false, + partitionByNewLine: false, + type: 'alphabetical', + matcher: 'minimatch', + ignoreCase: true, + specialCharacters: 'keep', + order: 'asc', + sortByValue: false, + forceNumericSort: false, +} + export default createEslintRule({ name: 'sort-enums', meta: { @@ -117,19 +129,7 @@ export default createEslintRule({ 'Expected dependency "{{right}}" to come before "{{nodeDependentOnRight}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - sortByValue: false, - partitionByComment: false, - partitionByNewLine: false, - forceNumericSort: false, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ TSEnumDeclaration: node => { let getMembers = (nodeValue: TSESTree.TSEnumDeclaration) => @@ -144,16 +144,8 @@ export default createEslintRule({ let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - partitionByComment: false, - partitionByNewLine: false, - type: 'alphabetical', - matcher: 'minimatch', - ignoreCase: true, - specialCharacters: 'keep', - order: 'asc', - sortByValue: false, - forceNumericSort: false, - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index c53db697..87e09c0f 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -33,6 +33,17 @@ type SortExportsSortingNode = SortingNode< TSESTree.ExportNamedDeclarationWithSource | TSESTree.ExportAllDeclaration > +const defaultOptions: Required = { + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + order: 'asc', + matcher: 'minimatch', + partitionByComment: false, + partitionByNewLine: false, + groupKind: 'mixed', +} + export default createEslintRule({ name: 'sort-exports', meta: { @@ -108,31 +119,13 @@ export default createEslintRule({ unexpectedExportsOrder: 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByComment: false, - partitionByNewLine: false, - groupKind: 'mixed', - }, - ], + defaultOptions: [defaultOptions], create: context => { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - order: 'asc', - matcher: 'minimatch', - partitionByComment: false, - partitionByNewLine: false, - groupKind: 'mixed', - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-heritage-clauses.ts b/rules/sort-heritage-clauses.ts index 4549b697..f6b6fc6d 100644 --- a/rules/sort-heritage-clauses.ts +++ b/rules/sort-heritage-clauses.ts @@ -34,6 +34,16 @@ export type Options = [ }>, ] +const defaultOptions: Required[0]> = { + type: 'alphabetical', + matcher: 'minimatch', + ignoreCase: true, + specialCharacters: 'keep', + customGroups: {}, + order: 'asc', + groups: [], +} + export default createEslintRule, MESSAGE_ID>({ name: 'sort-heritage-clauses', meta: { @@ -118,29 +128,13 @@ export default createEslintRule, MESSAGE_ID>({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - groups: [], - customGroups: {}, - }, - ], + defaultOptions: [defaultOptions], create: context => { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - matcher: 'minimatch', - ignoreCase: true, - specialCharacters: 'keep', - customGroups: {}, - order: 'asc', - groups: [], - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index 325da910..324abfa8 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -45,6 +45,21 @@ export type Options = [ }>, ] +const defaultOptions: Required[0]> = { + partitionByComment: false, + partitionByNewLine: false, + type: 'alphabetical', + groupKind: 'mixed', + matcher: 'minimatch', + newlinesBetween: 'ignore', + ignorePattern: [], + ignoreCase: true, + specialCharacters: 'keep', + customGroups: {}, + order: 'asc', + groups: [], +} + export default createEslintRule, MESSAGE_ID>({ name: 'sort-interfaces', meta: { @@ -175,39 +190,14 @@ export default createEslintRule, MESSAGE_ID>({ 'Extra spacing between "{{left}}" and "{{right}}" interfaces.', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - ignorePattern: [], - partitionByComment: false, - partitionByNewLine: false, - groupKind: 'mixed', - groups: [], - customGroups: {}, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ TSInterfaceDeclaration: node => { if (node.body.body.length > 1) { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - partitionByComment: false, - partitionByNewLine: false, - type: 'alphabetical', - groupKind: 'mixed', - matcher: 'minimatch', - ignorePattern: [], - ignoreCase: true, - newlinesBetween: 'ignore', - specialCharacters: 'keep', - customGroups: {}, - order: 'asc', - groups: [], - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index 566feb29..b0e7884f 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -54,6 +54,18 @@ type Options = [ }>, ] +const defaultOptions: Required = { + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + order: 'asc', + matcher: 'minimatch', + newlinesBetween: 'ignore', + partitionByComment: false, + partitionByNewLine: false, + groups: [], +} + export default createEslintRule({ name: 'sort-intersection-types', meta: { @@ -154,33 +166,14 @@ export default createEslintRule({ 'Extra spacing between "{{left}}" and "{{right}}" types.', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByNewLine: false, - partitionByComment: false, - groups: [], - }, - ], + defaultOptions: [defaultOptions], create: context => ({ TSIntersectionType: node => { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - order: 'asc', - matcher: 'minimatch', - newlinesBetween: 'ignore', - partitionByComment: false, - partitionByNewLine: false, - groups: [], - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index 558089e1..9b94138f 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -36,6 +36,17 @@ type Options = [ }>, ] +const defaultOptions: Required[0]> = { + type: 'alphabetical', + ignorePattern: [], + ignoreCase: true, + specialCharacters: 'keep', + matcher: 'minimatch', + customGroups: {}, + order: 'asc', + groups: [], +} + export default createEslintRule, MESSAGE_ID>({ name: 'sort-jsx-props', meta: { @@ -128,33 +139,15 @@ export default createEslintRule, MESSAGE_ID>({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - ignorePattern: [], - groups: [], - customGroups: {}, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ JSXElement: node => { if (node.openingElement.attributes.length > 1) { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignorePattern: [], - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - customGroups: {}, - order: 'asc', - groups: [], - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-maps.ts b/rules/sort-maps.ts index 1885defd..168e9f2f 100644 --- a/rules/sort-maps.ts +++ b/rules/sort-maps.ts @@ -31,6 +31,16 @@ type Options = [ }>, ] +const defaultOptions: Required = { + type: 'alphabetical', + order: 'asc', + ignoreCase: true, + specialCharacters: 'keep', + matcher: 'minimatch', + partitionByComment: false, + partitionByNewLine: false, +} + export default createEslintRule({ name: 'sort-maps', meta: { @@ -102,17 +112,7 @@ export default createEslintRule({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByComment: false, - partitionByNewLine: false, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ NewExpression: node => { if ( @@ -127,14 +127,8 @@ export default createEslintRule({ let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - order: 'asc', - matcher: 'minimatch', - partitionByComment: false, - partitionByNewLine: false, - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index b8fcb27c..4e26db72 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -30,6 +30,17 @@ type Options = [ }>, ] +const defaultOptions: Required = { + type: 'alphabetical', + order: 'asc', + ignoreCase: true, + specialCharacters: 'keep', + matcher: 'minimatch', + partitionByNewLine: false, + partitionByComment: false, + groupKind: 'mixed', +} + export default createEslintRule({ name: 'sort-named-exports', meta: { @@ -106,33 +117,15 @@ export default createEslintRule({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByNewLine: false, - partitionByComment: false, - groupKind: 'mixed', - }, - ], + defaultOptions: [defaultOptions], create: context => ({ ExportNamedDeclaration: node => { if (node.specifiers.length > 1) { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - groupKind: 'mixed', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByNewLine: false, - partitionByComment: false, - order: 'asc', - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 30e3088a..9188af5f 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -31,6 +31,18 @@ type Options = [ }>, ] +const defaultOptions: Required = { + type: 'alphabetical', + ignoreAlias: false, + groupKind: 'mixed', + ignoreCase: true, + specialCharacters: 'keep', + matcher: 'minimatch', + partitionByNewLine: false, + partitionByComment: false, + order: 'asc', +} + export default createEslintRule({ name: 'sort-named-imports', meta: { @@ -111,18 +123,7 @@ export default createEslintRule({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreAlias: false, - ignoreCase: true, - specialCharacters: 'keep', - partitionByNewLine: false, - partitionByComment: false, - groupKind: 'mixed', - }, - ], + defaultOptions: [defaultOptions], create: context => ({ ImportDeclaration: node => { let specifiers = node.specifiers.filter( @@ -133,16 +134,8 @@ export default createEslintRule({ let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreAlias: false, - groupKind: 'mixed', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByNewLine: false, - partitionByComment: false, - order: 'asc', - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index 22fd8150..1661973b 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -47,6 +47,20 @@ type Options = [ type SortObjectTypesSortingNode = SortingNode +const defaultOptions: Required[0]> = { + partitionByComment: false, + partitionByNewLine: false, + type: 'alphabetical', + groupKind: 'mixed', + matcher: 'minimatch', + newlinesBetween: 'ignore', + ignoreCase: true, + specialCharacters: 'keep', + customGroups: {}, + order: 'asc', + groups: [], +} + export default createEslintRule, MESSAGE_ID>({ name: 'sort-object-types', meta: { @@ -169,39 +183,15 @@ export default createEslintRule, MESSAGE_ID>({ 'Extra spacing between "{{left}}" and "{{right}}" types.', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - newlinesBetween: 'ignore', - partitionByComment: false, - partitionByNewLine: false, - groupKind: 'mixed', - groups: [], - customGroups: {}, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ TSTypeLiteral: node => { if (node.members.length > 1) { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - partitionByComment: false, - partitionByNewLine: false, - type: 'alphabetical', - groupKind: 'mixed', - matcher: 'minimatch', - ignoreCase: true, - newlinesBetween: 'ignore', - specialCharacters: 'keep', - customGroups: {}, - order: 'asc', - groups: [], - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index 5ea018cc..b4e2a32a 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -53,6 +53,22 @@ type Options = [ }>, ] +const defaultOptions: Required = { + partitionByNewLine: false, + partitionByComment: false, + styledComponents: true, + destructureOnly: false, + type: 'alphabetical', + ignorePattern: [], + matcher: 'minimatch', + newlinesBetween: 'ignore', + ignoreCase: true, + specialCharacters: 'keep', + customGroups: {}, + order: 'asc', + groups: [], +} + export default createEslintRule({ name: 'sort-objects', meta: { @@ -187,22 +203,7 @@ export default createEslintRule({ 'Extra spacing between "{{left}}" and "{{right}}" objects.', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByComment: false, - partitionByNewLine: false, - styledComponents: true, - destructureOnly: false, - ignorePattern: [], - groups: [], - customGroups: {}, - }, - ], + defaultOptions: [defaultOptions], create: context => { let sortObject = ( node: TSESTree.ObjectExpression | TSESTree.ObjectPattern, @@ -210,20 +211,8 @@ export default createEslintRule({ let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - partitionByNewLine: false, - partitionByComment: false, - styledComponents: true, - destructureOnly: false, - type: 'alphabetical', - ignorePattern: [], - matcher: 'minimatch', - ignoreCase: true, - newlinesBetween: 'ignore', - specialCharacters: 'keep', - customGroups: {}, - order: 'asc', - groups: [], - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-sets.ts b/rules/sort-sets.ts index 72b0b8af..a114f84a 100644 --- a/rules/sort-sets.ts +++ b/rules/sort-sets.ts @@ -1,7 +1,7 @@ import type { Options } from './sort-array-includes' +import { defaultOptions, jsonSchema, sortArray } from './sort-array-includes' import { createEslintRule } from '../utils/create-eslint-rule' -import { jsonSchema, sortArray } from './sort-array-includes' type MESSAGE_ID = 'unexpectedSetsOrder' @@ -18,16 +18,7 @@ export default createEslintRule({ unexpectedSetsOrder: 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - groupKind: 'literals-first', - }, - ], + defaultOptions: [defaultOptions], create: context => ({ NewExpression: node => { if ( diff --git a/rules/sort-switch-case.ts b/rules/sort-switch-case.ts index f54946d0..e5561364 100644 --- a/rules/sort-switch-case.ts +++ b/rules/sort-switch-case.ts @@ -29,6 +29,13 @@ interface SortSwitchCaseSortingNode extends SortingNode { isDefaultClause: boolean } +const defaultOptions: Required = { + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + order: 'asc', +} + export default createEslintRule({ name: 'sort-switch-case', meta: { @@ -72,24 +79,14 @@ export default createEslintRule({ 'Expected "{{right}}" to come before "{{left}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - }, - ], + defaultOptions: [defaultOptions], create: context => ({ SwitchStatement: node => { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - order: 'asc', - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index 6d41e429..5ea8336d 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -54,6 +54,18 @@ type Options = [ }>, ] +const defaultOptions: Required = { + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + order: 'asc', + groups: [], + matcher: 'minimatch', + newlinesBetween: 'ignore', + partitionByNewLine: false, + partitionByComment: false, +} + export default createEslintRule({ name: 'sort-union-types', meta: { @@ -154,33 +166,14 @@ export default createEslintRule({ 'Extra spacing between "{{left}}" and "{{right}}" types.', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByNewLine: false, - partitionByComment: false, - groups: [], - }, - ], + defaultOptions: [defaultOptions], create: context => ({ TSUnionType: node => { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - order: 'asc', - groups: [], - matcher: 'minimatch', - newlinesBetween: 'ignore', - partitionByNewLine: false, - partitionByComment: false, - } as const) + ...defaultOptions, + }) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-variable-declarations.ts b/rules/sort-variable-declarations.ts index 40a75188..399f6281 100644 --- a/rules/sort-variable-declarations.ts +++ b/rules/sort-variable-declarations.ts @@ -35,6 +35,16 @@ type Options = [ }>, ] +const defaultOptions: Required = { + type: 'alphabetical', + ignoreCase: true, + specialCharacters: 'keep', + partitionByNewLine: false, + matcher: 'minimatch', + partitionByComment: false, + order: 'asc', +} + export default createEslintRule({ name: 'sort-variable-declarations', meta: { @@ -108,31 +118,15 @@ export default createEslintRule({ 'Expected dependency "{{right}}" to come before "{{nodeDependentOnRight}}".', }, }, - defaultOptions: [ - { - type: 'alphabetical', - order: 'asc', - ignoreCase: true, - specialCharacters: 'keep', - matcher: 'minimatch', - partitionByComment: false, - partitionByNewLine: false, - }, - ], + defaultOptions: [defaultOptions], create: context => ({ VariableDeclaration: node => { if (node.declarations.length > 1) { let settings = getSettings(context.settings) let options = complete(context.options.at(0), settings, { - type: 'alphabetical', - ignoreCase: true, - specialCharacters: 'keep', - partitionByNewLine: false, - matcher: 'minimatch', - partitionByComment: false, - order: 'asc', - } as const) + ...defaultOptions, + }) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment From 04260b19d6ec42f135bb96260dbe69c0f585e4b0 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Sat, 19 Oct 2024 22:22:06 +0200 Subject: [PATCH 2/6] refactor: adds common JSON schemas --- rules/sort-array-includes.ts | 38 +++++++++------------------- rules/sort-classes.ts | 39 +++++++++-------------------- rules/sort-decorators.ts | 39 +++++++++-------------------- rules/sort-enums.ts | 39 +++++++++-------------------- rules/sort-exports.ts | 39 +++++++++-------------------- rules/sort-heritage-clauses.ts | 39 +++++++++-------------------- rules/sort-imports.ts | 39 +++++++++-------------------- rules/sort-interfaces.ts | 39 +++++++++-------------------- rules/sort-intersection-types.ts | 39 +++++++++-------------------- rules/sort-jsx-props.ts | 39 +++++++++-------------------- rules/sort-maps.ts | 39 +++++++++-------------------- rules/sort-named-exports.ts | 39 +++++++++-------------------- rules/sort-named-imports.ts | 39 +++++++++-------------------- rules/sort-object-types.ts | 39 +++++++++-------------------- rules/sort-objects.ts | 39 +++++++++-------------------- rules/sort-switch-case.ts | 32 ++++++++--------------- rules/sort-union-types.ts | 39 +++++++++-------------------- rules/sort-variable-declarations.ts | 39 +++++++++-------------------- utils/common-json-schemas.ts | 32 +++++++++++++++++++++++ 19 files changed, 246 insertions(+), 480 deletions(-) create mode 100644 utils/common-json-schemas.ts diff --git a/rules/sort-array-includes.ts b/rules/sort-array-includes.ts index b0d06175..9d3a908c 100644 --- a/rules/sort-array-includes.ts +++ b/rules/sort-array-includes.ts @@ -4,6 +4,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { hasPartitionComment } from '../utils/is-partition-comment' import { getCommentsBefore } from '../utils/get-comments-before' import { createEslintRule } from '../utils/create-eslint-rule' @@ -49,32 +56,11 @@ export const defaultOptions: Required = { export let jsonSchema: JSONSchema4 = { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, groupKind: { description: 'Specifies top-level groups.', enum: ['mixed', 'literals-first', 'spreads-first'], diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index 17d5c0b4..08e5b45f 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -15,6 +15,13 @@ import { customGroupMatches, getCompareOptions, } from './sort-classes-utils' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { singleCustomGroupJsonSchema, customGroupNameJsonSchema, @@ -89,33 +96,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, partitionByComment: { description: 'Allows to use comments to separate the class members into logical groups.', diff --git a/rules/sort-decorators.ts b/rules/sort-decorators.ts index 9ef64e72..9e3093fd 100644 --- a/rules/sort-decorators.ts +++ b/rules/sort-decorators.ts @@ -3,6 +3,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { hasPartitionComment } from '../utils/is-partition-comment' import { sortNodesByGroups } from '../utils/sort-nodes-by-groups' @@ -71,33 +78,11 @@ export default createEslintRule, MESSAGE_ID>({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, sortOnClasses: { description: 'Controls whether sorting should be enabled for class decorators.', diff --git a/rules/sort-enums.ts b/rules/sort-enums.ts index 2024ffb3..e1cbad30 100644 --- a/rules/sort-enums.ts +++ b/rules/sort-enums.ts @@ -3,6 +3,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' import type { CompareOptions } from '../utils/compare' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { getFirstUnorderedNodeDependentOn, sortNodesByDependencies, @@ -60,33 +67,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, sortByValue: { description: 'Compare enum values instead of names.', type: 'boolean', diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index 87e09c0f..9e4e2211 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -2,6 +2,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { hasPartitionComment } from '../utils/is-partition-comment' import { getCommentsBefore } from '../utils/get-comments-before' import { createEslintRule } from '../utils/create-eslint-rule' @@ -56,33 +63,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, partitionByComment: { description: 'Allows you to use comments to separate the exports into logical groups.', diff --git a/rules/sort-heritage-clauses.ts b/rules/sort-heritage-clauses.ts index f6b6fc6d..be18e7ca 100644 --- a/rules/sort-heritage-clauses.ts +++ b/rules/sort-heritage-clauses.ts @@ -3,6 +3,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { sortNodesByGroups } from '../utils/sort-nodes-by-groups' import { createEslintRule } from '../utils/create-eslint-rule' @@ -56,33 +63,11 @@ export default createEslintRule, MESSAGE_ID>({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, groups: { description: 'Specifies the order of the groups.', type: 'array', diff --git a/rules/sort-imports.ts b/rules/sort-imports.ts index 90ec0614..ed3096ed 100644 --- a/rules/sort-imports.ts +++ b/rules/sort-imports.ts @@ -4,6 +4,13 @@ import { builtinModules } from 'node:module' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { getOptionsWithCleanGroups } from '../utils/get-options-with-clean-groups' import { sortNodesByGroups } from '../utils/sort-nodes-by-groups' @@ -85,33 +92,11 @@ export default createEslintRule, MESSAGE_ID>({ id: 'sort-imports', type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, internalPattern: { description: 'Specifies the pattern for internal modules.', items: { diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index 324abfa8..e0bc29b8 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -1,5 +1,12 @@ import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { hasPartitionComment } from '../utils/is-partition-comment' @@ -72,33 +79,11 @@ export default createEslintRule, MESSAGE_ID>({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, ignorePattern: { description: 'Specifies names or patterns for nodes that should be ignored by rule.', diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index b0e7884f..c899f151 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -1,5 +1,12 @@ import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { hasPartitionComment } from '../utils/is-partition-comment' @@ -78,33 +85,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, groups: { description: 'Specifies the order of the groups.', type: 'array', diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index 9b94138f..64be9dd2 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -2,6 +2,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { sortNodesByGroups } from '../utils/sort-nodes-by-groups' import { createEslintRule } from '../utils/create-eslint-rule' @@ -59,33 +66,11 @@ export default createEslintRule, MESSAGE_ID>({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, ignorePattern: { description: 'Specifies names or patterns for nodes that should be ignored by rule.', diff --git a/rules/sort-maps.ts b/rules/sort-maps.ts index 168e9f2f..13d2372b 100644 --- a/rules/sort-maps.ts +++ b/rules/sort-maps.ts @@ -2,6 +2,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { hasPartitionComment } from '../utils/is-partition-comment' import { getCommentsBefore } from '../utils/get-comments-before' import { createEslintRule } from '../utils/create-eslint-rule' @@ -53,33 +60,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, partitionByComment: { description: 'Allows you to use comments to separate the maps members into logical groups.', diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index 4e26db72..1838b201 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -1,5 +1,12 @@ import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { hasPartitionComment } from '../utils/is-partition-comment' import { getCommentsBefore } from '../utils/get-comments-before' import { createEslintRule } from '../utils/create-eslint-rule' @@ -53,33 +60,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, groupKind: { description: 'Specifies top-level groups.', enum: ['mixed', 'values-first', 'types-first'], diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 9188af5f..77cc78d0 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -1,5 +1,12 @@ import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { hasPartitionComment } from '../utils/is-partition-comment' import { getCommentsBefore } from '../utils/get-comments-before' import { createEslintRule } from '../utils/create-eslint-rule' @@ -55,33 +62,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, ignoreAlias: { description: 'Controls whether to ignore alias names.', type: 'boolean', diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index 1661973b..5305ef85 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -2,6 +2,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { hasPartitionComment } from '../utils/is-partition-comment' @@ -73,33 +80,11 @@ export default createEslintRule, MESSAGE_ID>({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, partitionByComment: { description: 'Allows you to use comments to separate the type members into logical groups.', diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index b4e2a32a..fb267447 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -2,6 +2,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { getFirstUnorderedNodeDependentOn, sortNodesByDependencies, @@ -81,33 +88,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, partitionByComment: { description: 'Allows you to use comments to separate the keys of objects into logical groups.', diff --git a/rules/sort-switch-case.ts b/rules/sort-switch-case.ts index e5561364..0136bb31 100644 --- a/rules/sort-switch-case.ts +++ b/rules/sort-switch-case.ts @@ -3,6 +3,12 @@ import type { TSESLint } from '@typescript-eslint/utils' import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { createEslintRule } from '../utils/create-eslint-rule' import { getSourceCode } from '../utils/get-source-code' import { rangeToDiff } from '../utils/range-to-diff' @@ -48,28 +54,10 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, }, additionalProperties: false, }, diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index 5ea8336d..28f3e7bc 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -1,5 +1,12 @@ import type { SortingNode } from '../typings' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { validateNewlinesAndPartitionConfiguration } from '../utils/validate-newlines-and-partition-configuration' import { validateGroupsConfiguration } from '../utils/validate-groups-configuration' import { hasPartitionComment } from '../utils/is-partition-comment' @@ -78,33 +85,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, groups: { description: 'Specifies the order of the groups.', type: 'array', diff --git a/rules/sort-variable-declarations.ts b/rules/sort-variable-declarations.ts index 399f6281..b2d971da 100644 --- a/rules/sort-variable-declarations.ts +++ b/rules/sort-variable-declarations.ts @@ -2,6 +2,13 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' +import { + specialCharactersJsonSchema, + ignoreCaseJsonSchema, + matcherJsonSchema, + orderJsonSchema, + typeJsonSchema, +} from '../utils/common-json-schemas' import { getFirstUnorderedNodeDependentOn, sortNodesByDependencies, @@ -57,33 +64,11 @@ export default createEslintRule({ { type: 'object', properties: { - type: { - description: 'Specifies the sorting method.', - type: 'string', - enum: ['alphabetical', 'natural', 'line-length'], - }, - order: { - description: - 'Determines whether the sorted items should be in ascending or descending order.', - type: 'string', - enum: ['asc', 'desc'], - }, - matcher: { - description: 'Specifies the string matcher.', - type: 'string', - enum: ['minimatch', 'regex'], - }, - ignoreCase: { - 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'], - }, + type: typeJsonSchema, + order: orderJsonSchema, + matcher: matcherJsonSchema, + ignoreCase: ignoreCaseJsonSchema, + specialCharacters: specialCharactersJsonSchema, partitionByComment: { description: 'Allows you to use comments to separate the variable declarations into logical groups.', diff --git a/utils/common-json-schemas.ts b/utils/common-json-schemas.ts new file mode 100644 index 00000000..a8b5ecf6 --- /dev/null +++ b/utils/common-json-schemas.ts @@ -0,0 +1,32 @@ +import type { JSONSchema4 } from '@typescript-eslint/utils/json-schema' + +export let typeJsonSchema: JSONSchema4 = { + enum: ['alphabetical', 'natural', 'line-length'], + description: 'Specifies the sorting method.', + type: 'string', +} + +export let orderJsonSchema: JSONSchema4 = { + description: + 'Determines whether the sorted items should be in ascending or descending order.', + enum: ['asc', 'desc'], + type: 'string', +} + +export let matcherJsonSchema: JSONSchema4 = { + description: 'Specifies the string matcher.', + enum: ['minimatch', 'regex'], + type: 'string', +} + +export let ignoreCaseJsonSchema: JSONSchema4 = { + description: 'Controls whether sorting should be case-sensitive or not.', + type: 'boolean', +} + +export let specialCharactersJsonSchema: JSONSchema4 = { + description: + 'Controls how special characters should be handled before sorting.', + enum: ['remove', 'trim', 'keep'], + type: 'string', +} From 296c9be384b52c164730961b2bb42e515e4a1a57 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Sat, 19 Oct 2024 22:26:55 +0200 Subject: [PATCH 3/6] refactor: adds `partitionByComment` JSON schemas --- rules/sort-array-includes.ts | 16 ++------------- rules/sort-classes.ts | 30 +++++++++-------------------- rules/sort-decorators.ts | 16 ++------------- rules/sort-enums.ts | 16 ++------------- rules/sort-exports.ts | 16 ++------------- rules/sort-interfaces.ts | 16 ++------------- rules/sort-intersection-types.ts | 16 ++------------- rules/sort-maps.ts | 16 ++------------- rules/sort-named-exports.ts | 16 ++------------- rules/sort-named-imports.ts | 16 ++------------- rules/sort-object-types.ts | 16 ++------------- rules/sort-objects.ts | 16 ++------------- rules/sort-union-types.ts | 16 ++------------- rules/sort-variable-declarations.ts | 16 ++------------- utils/common-json-schemas.ts | 17 ++++++++++++++++ 15 files changed, 52 insertions(+), 203 deletions(-) diff --git a/rules/sort-array-includes.ts b/rules/sort-array-includes.ts index 9d3a908c..3a7f03bb 100644 --- a/rules/sort-array-includes.ts +++ b/rules/sort-array-includes.ts @@ -5,6 +5,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -67,22 +68,9 @@ export let jsonSchema: JSONSchema4 = { type: 'string', }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the array members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index 08e5b45f..4613b550 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -9,19 +9,20 @@ import type { import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' import { - validateGroupsConfiguration, - getOverloadSignatureGroups, - generateOfficialGroups, - customGroupMatches, - getCompareOptions, -} from './sort-classes-utils' -import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' +import { + validateGroupsConfiguration, + getOverloadSignatureGroups, + generateOfficialGroups, + customGroupMatches, + getCompareOptions, +} from './sort-classes-utils' import { singleCustomGroupJsonSchema, customGroupNameJsonSchema, @@ -102,22 +103,9 @@ export default createEslintRule({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows to use comments to separate the class members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, groups: { description: 'Specifies the order of the groups.', diff --git a/rules/sort-decorators.ts b/rules/sort-decorators.ts index 9e3093fd..8b489705 100644 --- a/rules/sort-decorators.ts +++ b/rules/sort-decorators.ts @@ -4,6 +4,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -109,22 +110,9 @@ export default createEslintRule, MESSAGE_ID>({ type: 'boolean', }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the decorators into logical groups.', - anyOf: [ - { - type: 'boolean', - }, - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], }, groups: { description: 'Specifies the order of the groups.', diff --git a/rules/sort-enums.ts b/rules/sort-enums.ts index e1cbad30..6b815701 100644 --- a/rules/sort-enums.ts +++ b/rules/sort-enums.ts @@ -4,6 +4,7 @@ import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-depende import type { CompareOptions } from '../utils/compare' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -82,22 +83,9 @@ export default createEslintRule({ type: 'boolean', }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the members of enums into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index 9e4e2211..52fe58a6 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -3,6 +3,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -69,22 +70,9 @@ export default createEslintRule({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the exports into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index e0bc29b8..d97e1ed0 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -1,6 +1,7 @@ import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -93,22 +94,9 @@ export default createEslintRule, MESSAGE_ID>({ type: 'array', }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the interface properties into logical groups.', - anyOf: [ - { - type: 'boolean', - }, - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index c899f151..f4642b8a 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -1,6 +1,7 @@ import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -108,22 +109,9 @@ export default createEslintRule({ }, }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the intersection types members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-maps.ts b/rules/sort-maps.ts index 13d2372b..5fe7a850 100644 --- a/rules/sort-maps.ts +++ b/rules/sort-maps.ts @@ -3,6 +3,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -66,22 +67,9 @@ export default createEslintRule({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the maps members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index 1838b201..fec90d71 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -1,6 +1,7 @@ import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -71,22 +72,9 @@ export default createEslintRule({ type: 'string', }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the named exports members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 77cc78d0..6ae3cbec 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -1,6 +1,7 @@ import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -77,22 +78,9 @@ export default createEslintRule({ type: 'string', }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the named imports members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index 5305ef85..770e2d5e 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -3,6 +3,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -86,22 +87,9 @@ export default createEslintRule, MESSAGE_ID>({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the type members into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index fb267447..9d01fb0b 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -3,6 +3,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -94,22 +95,9 @@ export default createEslintRule({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the keys of objects into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index 28f3e7bc..01cd09e7 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -1,6 +1,7 @@ import type { SortingNode } from '../typings' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -108,22 +109,9 @@ export default createEslintRule({ }, }, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the union types into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/rules/sort-variable-declarations.ts b/rules/sort-variable-declarations.ts index b2d971da..56400721 100644 --- a/rules/sort-variable-declarations.ts +++ b/rules/sort-variable-declarations.ts @@ -3,6 +3,7 @@ import type { TSESTree } from '@typescript-eslint/types' import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-dependencies' import { + partitionByCommentJsonSchema, specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, @@ -70,22 +71,9 @@ export default createEslintRule({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, partitionByComment: { + ...partitionByCommentJsonSchema, description: 'Allows you to use comments to separate the variable declarations into logical groups.', - anyOf: [ - { - type: 'array', - items: { - type: 'string', - }, - }, - { - type: 'boolean', - }, - { - type: 'string', - }, - ], }, partitionByNewLine: { description: diff --git a/utils/common-json-schemas.ts b/utils/common-json-schemas.ts index a8b5ecf6..3227639d 100644 --- a/utils/common-json-schemas.ts +++ b/utils/common-json-schemas.ts @@ -30,3 +30,20 @@ export let specialCharactersJsonSchema: JSONSchema4 = { enum: ['remove', 'trim', 'keep'], type: 'string', } + +export let partitionByCommentJsonSchema: JSONSchema4 = { + anyOf: [ + { + items: { + type: 'string', + }, + type: 'array', + }, + { + type: 'boolean', + }, + { + type: 'string', + }, + ], +} From e4cb1f9ea4842ca4e0e56416c0d137869ada901e Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Sat, 19 Oct 2024 22:33:34 +0200 Subject: [PATCH 4/6] refactor: adds `groups` JSON schemas --- rules/sort-classes.ts | 19 ++----------------- rules/sort-decorators.ts | 19 ++----------------- rules/sort-heritage-clauses.ts | 19 ++----------------- rules/sort-imports.ts | 19 ++----------------- rules/sort-interfaces.ts | 19 ++----------------- rules/sort-intersection-types.ts | 19 ++----------------- rules/sort-jsx-props.ts | 19 ++----------------- rules/sort-object-types.ts | 19 ++----------------- rules/sort-objects.ts | 19 ++----------------- rules/sort-union-types.ts | 19 ++----------------- utils/common-json-schemas.ts | 18 ++++++++++++++++++ 11 files changed, 38 insertions(+), 170 deletions(-) diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index 4613b550..f52cddc4 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -13,6 +13,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -107,23 +108,7 @@ export default createEslintRule({ description: 'Allows to use comments to separate the class members into logical groups.', }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'array', diff --git a/rules/sort-decorators.ts b/rules/sort-decorators.ts index 8b489705..67c2b2b5 100644 --- a/rules/sort-decorators.ts +++ b/rules/sort-decorators.ts @@ -8,6 +8,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -114,23 +115,7 @@ export default createEslintRule, MESSAGE_ID>({ description: 'Allows you to use comments to separate the decorators into logical groups.', }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-heritage-clauses.ts b/rules/sort-heritage-clauses.ts index be18e7ca..fec53b7b 100644 --- a/rules/sort-heritage-clauses.ts +++ b/rules/sort-heritage-clauses.ts @@ -7,6 +7,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -68,23 +69,7 @@ export default createEslintRule, MESSAGE_ID>({ matcher: matcherJsonSchema, ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-imports.ts b/rules/sort-imports.ts index ed3096ed..47c93b58 100644 --- a/rules/sort-imports.ts +++ b/rules/sort-imports.ts @@ -8,6 +8,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -121,23 +122,7 @@ export default createEslintRule, MESSAGE_ID>({ minimum: 0, exclusiveMinimum: true, }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index d97e1ed0..2d6a84f0 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -5,6 +5,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -114,23 +115,7 @@ export default createEslintRule, MESSAGE_ID>({ enum: ['mixed', 'optional-first', 'required-first'], type: 'string', }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index f4642b8a..4f63d692 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -5,6 +5,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -91,23 +92,7 @@ export default createEslintRule({ matcher: matcherJsonSchema, ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, partitionByComment: { ...partitionByCommentJsonSchema, description: diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index 64be9dd2..9408dc16 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -6,6 +6,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -79,23 +80,7 @@ export default createEslintRule, MESSAGE_ID>({ }, type: 'array', }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index 770e2d5e..29643955 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -7,6 +7,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -107,23 +108,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', enum: ['mixed', 'required-first', 'optional-first'], }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index 9d01fb0b..363fc87e 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -7,6 +7,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -126,23 +127,7 @@ export default createEslintRule({ }, type: 'array', }, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, customGroups: { description: 'Specifies custom groups.', type: 'object', diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index 01cd09e7..ce6ca8ba 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -5,6 +5,7 @@ import { specialCharactersJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, + groupsJsonSchema, orderJsonSchema, typeJsonSchema, } from '../utils/common-json-schemas' @@ -91,23 +92,7 @@ export default createEslintRule({ matcher: matcherJsonSchema, ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, - groups: { - description: 'Specifies the order of the groups.', - type: 'array', - items: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + groups: groupsJsonSchema, partitionByComment: { ...partitionByCommentJsonSchema, description: diff --git a/utils/common-json-schemas.ts b/utils/common-json-schemas.ts index 3227639d..31ffdad9 100644 --- a/utils/common-json-schemas.ts +++ b/utils/common-json-schemas.ts @@ -31,6 +31,24 @@ export let specialCharactersJsonSchema: JSONSchema4 = { type: 'string', } +export let groupsJsonSchema: JSONSchema4 = { + items: { + oneOf: [ + { + type: 'string', + }, + { + items: { + type: 'string', + }, + type: 'array', + }, + ], + }, + description: 'Specifies the order of the groups.', + type: 'array', +} + export let partitionByCommentJsonSchema: JSONSchema4 = { anyOf: [ { From 6f93ab18f76ffff033589e91cfa29e6d6dcd4cf0 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Sat, 19 Oct 2024 22:37:45 +0200 Subject: [PATCH 5/6] refactor: adds `customGroups` JSON schemas --- rules/sort-decorators.ts | 19 ++----------------- rules/sort-heritage-clauses.ts | 19 ++----------------- rules/sort-interfaces.ts | 19 ++----------------- rules/sort-jsx-props.ts | 19 ++----------------- rules/sort-object-types.ts | 19 ++----------------- rules/sort-objects.ts | 19 ++----------------- utils/common-json-schemas.ts | 18 ++++++++++++++++++ 7 files changed, 30 insertions(+), 102 deletions(-) diff --git a/rules/sort-decorators.ts b/rules/sort-decorators.ts index 67c2b2b5..679b86fb 100644 --- a/rules/sort-decorators.ts +++ b/rules/sort-decorators.ts @@ -6,6 +6,7 @@ import type { SortingNode } from '../typings' import { partitionByCommentJsonSchema, specialCharactersJsonSchema, + customGroupsJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, groupsJsonSchema, @@ -116,23 +117,7 @@ export default createEslintRule, MESSAGE_ID>({ 'Allows you to use comments to separate the decorators into logical groups.', }, groups: groupsJsonSchema, - customGroups: { - description: 'Specifies custom groups.', - type: 'object', - additionalProperties: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + customGroups: customGroupsJsonSchema, }, additionalProperties: false, }, diff --git a/rules/sort-heritage-clauses.ts b/rules/sort-heritage-clauses.ts index fec53b7b..8b4927d6 100644 --- a/rules/sort-heritage-clauses.ts +++ b/rules/sort-heritage-clauses.ts @@ -5,6 +5,7 @@ import type { SortingNode } from '../typings' import { specialCharactersJsonSchema, + customGroupsJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, groupsJsonSchema, @@ -70,23 +71,7 @@ export default createEslintRule, MESSAGE_ID>({ ignoreCase: ignoreCaseJsonSchema, specialCharacters: specialCharactersJsonSchema, groups: groupsJsonSchema, - customGroups: { - description: 'Specifies custom groups.', - type: 'object', - additionalProperties: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + customGroups: customGroupsJsonSchema, }, additionalProperties: false, }, diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index 2d6a84f0..8b84c7b5 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -3,6 +3,7 @@ import type { SortingNode } from '../typings' import { partitionByCommentJsonSchema, specialCharactersJsonSchema, + customGroupsJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, groupsJsonSchema, @@ -116,23 +117,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'string', }, groups: groupsJsonSchema, - customGroups: { - description: 'Specifies custom groups.', - type: 'object', - additionalProperties: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + customGroups: customGroupsJsonSchema, }, additionalProperties: false, }, diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index 9408dc16..f51d9a50 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -4,6 +4,7 @@ import type { SortingNode } from '../typings' import { specialCharactersJsonSchema, + customGroupsJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, groupsJsonSchema, @@ -81,23 +82,7 @@ export default createEslintRule, MESSAGE_ID>({ type: 'array', }, groups: groupsJsonSchema, - customGroups: { - description: 'Specifies custom groups.', - type: 'object', - additionalProperties: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + customGroups: customGroupsJsonSchema, }, additionalProperties: false, }, diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index 29643955..95ff79e7 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -5,6 +5,7 @@ import type { SortingNode } from '../typings' import { partitionByCommentJsonSchema, specialCharactersJsonSchema, + customGroupsJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, groupsJsonSchema, @@ -109,23 +110,7 @@ export default createEslintRule, MESSAGE_ID>({ enum: ['mixed', 'required-first', 'optional-first'], }, groups: groupsJsonSchema, - customGroups: { - description: 'Specifies custom groups.', - type: 'object', - additionalProperties: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + customGroups: customGroupsJsonSchema, }, additionalProperties: false, }, diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index 363fc87e..4f79c1d0 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -5,6 +5,7 @@ import type { SortingNodeWithDependencies } from '../utils/sort-nodes-by-depende import { partitionByCommentJsonSchema, specialCharactersJsonSchema, + customGroupsJsonSchema, ignoreCaseJsonSchema, matcherJsonSchema, groupsJsonSchema, @@ -128,23 +129,7 @@ export default createEslintRule({ type: 'array', }, groups: groupsJsonSchema, - customGroups: { - description: 'Specifies custom groups.', - type: 'object', - additionalProperties: { - oneOf: [ - { - type: 'string', - }, - { - type: 'array', - items: { - type: 'string', - }, - }, - ], - }, - }, + customGroups: customGroupsJsonSchema, }, additionalProperties: false, }, diff --git a/utils/common-json-schemas.ts b/utils/common-json-schemas.ts index 31ffdad9..007f6664 100644 --- a/utils/common-json-schemas.ts +++ b/utils/common-json-schemas.ts @@ -49,6 +49,24 @@ export let groupsJsonSchema: JSONSchema4 = { type: 'array', } +export let customGroupsJsonSchema: JSONSchema4 = { + additionalProperties: { + oneOf: [ + { + type: 'string', + }, + { + items: { + type: 'string', + }, + type: 'array', + }, + ], + }, + description: 'Specifies custom groups.', + type: 'object', +} + export let partitionByCommentJsonSchema: JSONSchema4 = { anyOf: [ { From d0a66e6e1361bf4c4db2302cf586c07a24f5d3d8 Mon Sep 17 00:00:00 2001 From: "hugo.prunaux" Date: Fri, 25 Oct 2024 11:51:08 +0200 Subject: [PATCH 6/6] refactor: makes `complete` return a new object * ...rather than use `Object.assign` --- rules/sort-array-includes.ts | 4 +--- rules/sort-classes.ts | 4 +--- rules/sort-decorators.ts | 4 +--- rules/sort-enums.ts | 4 +--- rules/sort-exports.ts | 4 +--- rules/sort-heritage-clauses.ts | 4 +--- rules/sort-interfaces.ts | 4 +--- rules/sort-intersection-types.ts | 4 +--- rules/sort-jsx-props.ts | 4 +--- rules/sort-maps.ts | 8 +++++--- rules/sort-named-exports.ts | 4 +--- rules/sort-named-imports.ts | 4 +--- rules/sort-object-types.ts | 4 +--- rules/sort-objects.ts | 4 +--- rules/sort-switch-case.ts | 4 +--- rules/sort-union-types.ts | 4 +--- rules/sort-variable-declarations.ts | 4 +--- utils/complete.ts | 2 +- 18 files changed, 22 insertions(+), 52 deletions(-) diff --git a/rules/sort-array-includes.ts b/rules/sort-array-includes.ts index 3a7f03bb..ebd4360c 100644 --- a/rules/sort-array-includes.ts +++ b/rules/sort-array-includes.ts @@ -122,9 +122,7 @@ export let sortArray = ( let settings = getSettings(context.settings) if (elements.length > 1) { - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-classes.ts b/rules/sort-classes.ts index f52cddc4..93d9adc7 100644 --- a/rules/sort-classes.ts +++ b/rules/sort-classes.ts @@ -165,9 +165,7 @@ export default createEslintRule({ if (node.body.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration(options.groups, options.customGroups) diff --git a/rules/sort-decorators.ts b/rules/sort-decorators.ts index 679b86fb..f84a0ce0 100644 --- a/rules/sort-decorators.ts +++ b/rules/sort-decorators.ts @@ -133,9 +133,7 @@ export default createEslintRule, MESSAGE_ID>({ create: context => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-enums.ts b/rules/sort-enums.ts index 6b815701..54d24ff8 100644 --- a/rules/sort-enums.ts +++ b/rules/sort-enums.ts @@ -116,9 +116,7 @@ export default createEslintRule({ ) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index 52fe58a6..0242e006 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -96,9 +96,7 @@ export default createEslintRule({ create: context => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-heritage-clauses.ts b/rules/sort-heritage-clauses.ts index 8b4927d6..221bb2c7 100644 --- a/rules/sort-heritage-clauses.ts +++ b/rules/sort-heritage-clauses.ts @@ -87,9 +87,7 @@ export default createEslintRule, MESSAGE_ID>({ create: context => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-interfaces.ts b/rules/sort-interfaces.ts index 8b84c7b5..eedc755e 100644 --- a/rules/sort-interfaces.ts +++ b/rules/sort-interfaces.ts @@ -138,9 +138,7 @@ export default createEslintRule, MESSAGE_ID>({ TSInterfaceDeclaration: node => { if (node.body.body.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-intersection-types.ts b/rules/sort-intersection-types.ts index 4f63d692..4db6740a 100644 --- a/rules/sort-intersection-types.ts +++ b/rules/sort-intersection-types.ts @@ -129,9 +129,7 @@ export default createEslintRule({ TSIntersectionType: node => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-jsx-props.ts b/rules/sort-jsx-props.ts index f51d9a50..95516665 100644 --- a/rules/sort-jsx-props.ts +++ b/rules/sort-jsx-props.ts @@ -100,9 +100,7 @@ export default createEslintRule, MESSAGE_ID>({ if (node.openingElement.attributes.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-maps.ts b/rules/sort-maps.ts index 5fe7a850..d6990a37 100644 --- a/rules/sort-maps.ts +++ b/rules/sort-maps.ts @@ -99,9 +99,11 @@ export default createEslintRule({ if (elements.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete( + context.options.at(0), + settings, + defaultOptions, + ) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index fec90d71..e1d05008 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -96,9 +96,7 @@ export default createEslintRule({ if (node.specifiers.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 6ae3cbec..9b493b33 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -106,9 +106,7 @@ export default createEslintRule({ if (specifiers.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/rules/sort-object-types.ts b/rules/sort-object-types.ts index 95ff79e7..9f2434f2 100644 --- a/rules/sort-object-types.ts +++ b/rules/sort-object-types.ts @@ -132,9 +132,7 @@ export default createEslintRule, MESSAGE_ID>({ if (node.members.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-objects.ts b/rules/sort-objects.ts index 4f79c1d0..66c2ab80 100644 --- a/rules/sort-objects.ts +++ b/rules/sort-objects.ts @@ -153,9 +153,7 @@ export default createEslintRule({ ) => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-switch-case.ts b/rules/sort-switch-case.ts index 0136bb31..f76ddbb9 100644 --- a/rules/sort-switch-case.ts +++ b/rules/sort-switch-case.ts @@ -72,9 +72,7 @@ export default createEslintRule({ SwitchStatement: node => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) diff --git a/rules/sort-union-types.ts b/rules/sort-union-types.ts index ce6ca8ba..222669c5 100644 --- a/rules/sort-union-types.ts +++ b/rules/sort-union-types.ts @@ -129,9 +129,7 @@ export default createEslintRule({ TSUnionType: node => { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) validateGroupsConfiguration( options.groups, diff --git a/rules/sort-variable-declarations.ts b/rules/sort-variable-declarations.ts index 56400721..cfa694b6 100644 --- a/rules/sort-variable-declarations.ts +++ b/rules/sort-variable-declarations.ts @@ -97,9 +97,7 @@ export default createEslintRule({ if (node.declarations.length > 1) { let settings = getSettings(context.settings) - let options = complete(context.options.at(0), settings, { - ...defaultOptions, - }) + let options = complete(context.options.at(0), settings, defaultOptions) let sourceCode = getSourceCode(context) let partitionComment = options.partitionByComment diff --git a/utils/complete.ts b/utils/complete.ts index 089ef55f..b7f54d42 100644 --- a/utils/complete.ts +++ b/utils/complete.ts @@ -4,4 +4,4 @@ export let complete = ( options: Partial = {}, settings: Settings = {}, defaults: T, -): T => Object.assign(defaults, settings, options) +): T => ({ ...defaults, ...settings, ...options })