Skip to content

Commit 3f02687

Browse files
chore: enable eslint-plugin-perfectionist on eslint-plugin package, with ordering tweaks (typescript-eslint#9843)
* chore: enable eslint-plugin-perfectionist on eslint-plugin package * Assorted cleanups * type, meta, defaultOptions, create ordering * re-order rules * re-order rules, correctly this time * re-order rules, correctly this time this time * Preferences around reports and valid/invalid * Preferences around line and column, and remove enums * Preferences around start and end * Preferences around end and start, not line and column * ignore eslint-plugin/src/configs * fix: TSModuleDeclaration/spec.ts global comment * fix: ajv is order-dependent
1 parent f898248 commit 3f02687

File tree

437 files changed

+23803
-23559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

437 files changed

+23803
-23559
lines changed

eslint.config.mjs

+52-13
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,13 @@ export default tseslint.config(
596596
},
597597
{
598598
extends: [perfectionistPlugin.configs['recommended-alphabetical']],
599-
ignores: ['packages/typescript-eslint/src/configs/*'],
599+
ignores: [
600+
'packages/eslint-plugin/src/configs/*',
601+
'packages/typescript-eslint/src/configs/*',
602+
],
600603
files: [
601604
'packages/ast-spec/{src,tests,typings}/**/*.ts',
605+
'packages/eslint-plugin/{src,tests,tools,typings}/**/*.ts',
602606
'packages/integration-tests/{tests,tools,typing}/**/*.ts',
603607
'packages/parser/{src,tests}/**/*.ts',
604608
'packages/rule-schema-to-typescript-types/src/**/*.ts',
@@ -611,32 +615,67 @@ export default tseslint.config(
611615
],
612616
rules: {
613617
'@typescript-eslint/sort-type-constituents': 'off',
614-
'perfectionist/sort-classes': [
618+
'perfectionist/sort-classes': 'error',
619+
'perfectionist/sort-enums': 'off',
620+
'perfectionist/sort-objects': 'error',
621+
'perfectionist/sort-union-types': [
615622
'error',
616623
{
617-
order: 'asc',
618-
partitionByComment: true,
624+
groups: ['unknown', 'keyword', 'nullish'],
619625
type: 'natural',
620626
},
621627
],
622-
'perfectionist/sort-enums': 'off',
628+
'simple-import-sort/imports': 'off',
629+
},
630+
settings: {
631+
perfectionist: {
632+
partitionByComment: true,
633+
order: 'asc',
634+
type: 'natural',
635+
},
636+
},
637+
},
638+
{
639+
files: ['packages/ast-spec/src/**/*.ts'],
640+
rules: {
641+
'perfectionist/sort-interfaces': [
642+
'error',
643+
{
644+
customGroups: {
645+
first: ['type'],
646+
},
647+
groups: ['first', 'unknown'],
648+
},
649+
],
650+
},
651+
},
652+
{
653+
files: ['packages/eslint-plugin/src/rules/*.ts'],
654+
rules: {
623655
'perfectionist/sort-objects': [
624656
'error',
625657
{
626-
order: 'asc',
627-
partitionByComment: true,
628-
type: 'natural',
658+
customGroups: {
659+
first: ['loc', 'name', 'node', 'type'],
660+
second: ['meta', 'messageId', 'start'],
661+
third: ['defaultOptions', 'data', 'end'],
662+
fourth: ['fix'],
663+
},
664+
groups: ['first', 'second', 'third', 'fourth', 'unknown'],
629665
},
630666
],
631-
'perfectionist/sort-union-types': [
667+
},
668+
},
669+
{
670+
files: ['packages/eslint-plugin/tests/rules/*.test.ts'],
671+
rules: {
672+
'perfectionist/sort-objects': [
632673
'error',
633674
{
634-
order: 'asc',
635-
groups: ['unknown', 'keyword', 'nullish'],
636-
type: 'natural',
675+
customGroups: { top: ['valid'] },
676+
groups: ['top', 'unknown'],
637677
},
638678
],
639-
'simple-import-sort/imports': 'off',
640679
},
641680
},
642681
);

packages/ast-spec/src/base/LiteralBase.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AST_NODE_TYPES } from '../ast-node-types';
22
import type { BaseNode } from './BaseNode';
33

44
export interface LiteralBase extends BaseNode {
5-
raw: string;
65
type: AST_NODE_TYPES.Literal;
6+
raw: string;
77
value: RegExp | bigint | boolean | number | string | null;
88
}

packages/ast-spec/src/base/NodeOrTokenData.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import type { Range } from './Range';
22
import type { SourceLocation } from './SourceLocation';
33

44
export interface NodeOrTokenData {
5+
type: string;
6+
57
/**
68
* The source location information of the node.
79
*
@@ -10,6 +12,4 @@ export interface NodeOrTokenData {
1012
loc: SourceLocation;
1113

1214
range: Range;
13-
14-
type: string;
1515
}

packages/ast-spec/src/declaration/ExportAllDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { ImportAttribute } from '../../special/ImportAttribute/spec';
66
import type { ExportKind } from '../ExportAndImportKind';
77

88
export interface ExportAllDeclaration extends BaseNode {
9+
type: AST_NODE_TYPES.ExportAllDeclaration;
910
/**
1011
* The assertions declared for the export.
1112
* @example
@@ -35,5 +36,4 @@ export interface ExportAllDeclaration extends BaseNode {
3536
* The source module being exported from.
3637
*/
3738
source: StringLiteral;
38-
type: AST_NODE_TYPES.ExportAllDeclaration;
3939
}

packages/ast-spec/src/declaration/ExportDefaultDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { BaseNode } from '../../base/BaseNode';
33
import type { DefaultExportDeclarations } from '../../unions/ExportDeclaration';
44

55
export interface ExportDefaultDeclaration extends BaseNode {
6+
type: AST_NODE_TYPES.ExportDefaultDeclaration;
67
/**
78
* The declaration being exported.
89
*/
@@ -11,5 +12,4 @@ export interface ExportDefaultDeclaration extends BaseNode {
1112
* The kind of the export. Always `value` for default exports.
1213
*/
1314
exportKind: 'value';
14-
type: AST_NODE_TYPES.ExportDefaultDeclaration;
1515
}

packages/ast-spec/src/declaration/ExportNamedDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { NamedExportDeclarations } from '../../unions/ExportDeclaration';
77
import type { ExportKind } from '../ExportAndImportKind';
88

99
interface ExportNamedDeclarationBase extends BaseNode {
10+
type: AST_NODE_TYPES.ExportNamedDeclaration;
1011
/**
1112
* The assertions declared for the export.
1213
* @example
@@ -52,7 +53,6 @@ interface ExportNamedDeclarationBase extends BaseNode {
5253
* This will be an empty array if `declaration` is not `null`
5354
*/
5455
specifiers: ExportSpecifier[];
55-
type: AST_NODE_TYPES.ExportNamedDeclaration;
5656
}
5757

5858
/**

packages/ast-spec/src/declaration/FunctionDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import type { Identifier } from '../../expression/Identifier/spec';
44
import type { BlockStatement } from '../../statement/BlockStatement/spec';
55

66
interface FunctionDeclarationBase extends FunctionBase {
7+
type: AST_NODE_TYPES.FunctionDeclaration;
78
body: BlockStatement;
89
declare: false;
910
expression: false;
10-
type: AST_NODE_TYPES.FunctionDeclaration;
1111
}
1212

1313
/**

packages/ast-spec/src/declaration/ImportDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { ImportClause } from '../../unions/ImportClause';
66
import type { ImportKind } from '../ExportAndImportKind';
77

88
export interface ImportDeclaration extends BaseNode {
9+
type: AST_NODE_TYPES.ImportDeclaration;
910
/**
1011
* The assertions declared for the export.
1112
* @example
@@ -43,5 +44,4 @@ export interface ImportDeclaration extends BaseNode {
4344
* ```
4445
*/
4546
specifiers: ImportClause[];
46-
type: AST_NODE_TYPES.ImportDeclaration;
4747
}

packages/ast-spec/src/declaration/TSDeclareFunction/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types';
22
import type { FunctionBase } from '../../base/FunctionBase';
33

44
interface TSDeclareFunctionBase extends FunctionBase {
5+
type: AST_NODE_TYPES.TSDeclareFunction;
56
/**
67
* TS1183: An implementation cannot be declared in ambient contexts.
78
*/
@@ -11,7 +12,6 @@ interface TSDeclareFunctionBase extends FunctionBase {
1112
*/
1213
declare: boolean;
1314
expression: false;
14-
type: AST_NODE_TYPES.TSDeclareFunction;
1515
}
1616

1717
/**

packages/ast-spec/src/declaration/TSEnumDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Identifier } from '../../expression/Identifier/spec';
55
import type { TSEnumBody } from '../../special/TSEnumBody/spec';
66

77
export interface TSEnumDeclaration extends BaseNode {
8+
type: AST_NODE_TYPES.TSEnumDeclaration;
89
/**
910
* The body of the enum.
1011
*/
@@ -34,5 +35,4 @@ export interface TSEnumDeclaration extends BaseNode {
3435
* @deprecated Use {@link body} instead.
3536
*/
3637
members: TSEnumMember[];
37-
type: AST_NODE_TYPES.TSEnumDeclaration;
3838
}

packages/ast-spec/src/declaration/TSImportEqualsDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { TSQualifiedName } from '../../type/TSQualifiedName/spec';
66
import type { ImportKind } from '../ExportAndImportKind';
77

88
interface TSImportEqualsDeclarationBase extends BaseNode {
9+
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
910
/**
1011
* The locally imported name.
1112
*/
@@ -25,7 +26,6 @@ interface TSImportEqualsDeclarationBase extends BaseNode {
2526
* ```
2627
*/
2728
moduleReference: Identifier | TSExternalModuleReference | TSQualifiedName;
28-
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
2929
}
3030

3131
export interface TSImportEqualsNamespaceDeclaration

packages/ast-spec/src/declaration/TSInterfaceDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { TSInterfaceHeritage } from '../../special/TSInterfaceHeritage/spec
66
import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec';
77

88
export interface TSInterfaceDeclaration extends BaseNode {
9+
type: AST_NODE_TYPES.TSInterfaceDeclaration;
910
/**
1011
* The body of the interface
1112
*/
@@ -22,7 +23,6 @@ export interface TSInterfaceDeclaration extends BaseNode {
2223
* The name of this interface
2324
*/
2425
id: Identifier;
25-
type: AST_NODE_TYPES.TSInterfaceDeclaration;
2626
/**
2727
* The generic type parameters declared for the interface. Empty declaration
2828
* (`<>`) is different from no declaration.

packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { Literal } from '../../unions/Literal';
99
export type TSModuleDeclarationKind = 'global' | 'module' | 'namespace';
1010

1111
interface TSModuleDeclarationBase extends BaseNode {
12+
type: AST_NODE_TYPES.TSModuleDeclaration;
1213
/**
1314
* The body of the module.
1415
* This can only be `undefined` for the code `declare module 'mod';`
@@ -42,6 +43,7 @@ interface TSModuleDeclarationBase extends BaseNode {
4243
* ```
4344
*/
4445
id: Identifier | Literal | TSQualifiedName;
46+
4547
/**
4648
* The keyword used to define this module declaration
4749
* @example
@@ -57,8 +59,6 @@ interface TSModuleDeclarationBase extends BaseNode {
5759
* ```
5860
*/
5961
kind: TSModuleDeclarationKind;
60-
61-
type: AST_NODE_TYPES.TSModuleDeclaration;
6262
}
6363

6464
export interface TSModuleDeclarationNamespace extends TSModuleDeclarationBase {

packages/ast-spec/src/declaration/TSNamespaceExportDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type { Identifier } from '../../expression/Identifier/spec';
99
* ```
1010
*/
1111
export interface TSNamespaceExportDeclaration extends BaseNode {
12+
type: AST_NODE_TYPES.TSNamespaceExportDeclaration;
1213
/**
1314
* The name of the global variable that's exported as namespace
1415
*/
1516
id: Identifier;
16-
type: AST_NODE_TYPES.TSNamespaceExportDeclaration;
1717
}

packages/ast-spec/src/declaration/TSTypeAliasDeclaration/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDe
55
import type { TypeNode } from '../../unions/TypeNode';
66

77
export interface TSTypeAliasDeclaration extends BaseNode {
8+
type: AST_NODE_TYPES.TSTypeAliasDeclaration;
89
/**
910
* Whether the type was `declare`d.
1011
* @example
@@ -17,7 +18,6 @@ export interface TSTypeAliasDeclaration extends BaseNode {
1718
* The name of the type.
1819
*/
1920
id: Identifier;
20-
type: AST_NODE_TYPES.TSTypeAliasDeclaration;
2121
/**
2222
* The "value" (type) of the declaration
2323
*/

packages/ast-spec/src/declaration/VariableDeclaration/spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
} from '../../special/VariableDeclarator/spec';
1111

1212
interface LetOrConstOrVarDeclarationBase extends BaseNode {
13+
type: AST_NODE_TYPES.VariableDeclaration;
1314
/**
1415
* The variables declared by this declaration.
1516
* Always non-empty.
@@ -38,7 +39,6 @@ interface LetOrConstOrVarDeclarationBase extends BaseNode {
3839
* ```
3940
*/
4041
kind: 'const' | 'let' | 'var';
41-
type: AST_NODE_TYPES.VariableDeclaration;
4242
}
4343

4444
export interface LetOrVarDeclaredDeclaration
@@ -91,6 +91,7 @@ export type LetOrConstOrVarDeclaration =
9191
| LetOrVarNonDeclaredDeclaration;
9292

9393
interface UsingDeclarationBase extends BaseNode {
94+
type: AST_NODE_TYPES.VariableDeclaration;
9495
/**
9596
* This value will always be `false`
9697
* because 'declare' modifier cannot appear on a 'using' declaration.
@@ -105,7 +106,6 @@ interface UsingDeclarationBase extends BaseNode {
105106
* ```
106107
*/
107108
kind: 'await using' | 'using';
108-
type: AST_NODE_TYPES.VariableDeclaration;
109109
}
110110

111111
export interface UsingInNormalContextDeclaration extends UsingDeclarationBase {

packages/ast-spec/src/element/Property/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import type {
1111
} from '../../unions/PropertyName';
1212

1313
interface PropertyBase extends BaseNode {
14+
type: AST_NODE_TYPES.Property;
1415
computed: boolean;
1516
key: PropertyName;
1617
kind: 'get' | 'init' | 'set';
1718
method: boolean;
1819
optional: boolean;
1920
shorthand: boolean;
20-
type: AST_NODE_TYPES.Property;
2121
value:
2222
| AssignmentPattern
2323
| BindingName

packages/ast-spec/src/element/SpreadElement/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode';
33
import type { Expression } from '../../unions/Expression';
44

55
export interface SpreadElement extends BaseNode {
6-
argument: Expression;
76
type: AST_NODE_TYPES.SpreadElement;
7+
argument: Expression;
88
}

packages/ast-spec/src/element/StaticBlock/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode';
33
import type { Statement } from '../../unions/Statement';
44

55
export interface StaticBlock extends BaseNode {
6-
body: Statement[];
76
type: AST_NODE_TYPES.StaticBlock;
7+
body: Statement[];
88
}

packages/ast-spec/src/element/TSEnumMember/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import type {
77
} from '../../unions/PropertyName';
88

99
interface TSEnumMemberBase extends BaseNode {
10+
type: AST_NODE_TYPES.TSEnumMember;
1011
computed: boolean;
1112
id:
1213
| PropertyNameComputed // this should only happen in semantically invalid code (ts error 1164)
1314
| PropertyNameNonComputed;
1415
initializer: Expression | undefined;
15-
type: AST_NODE_TYPES.TSEnumMember;
1616
}
1717

1818
/**

packages/ast-spec/src/element/TSIndexSignature/spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec';
55
import type { Parameter } from '../../unions/Parameter';
66

77
export interface TSIndexSignature extends BaseNode {
8+
type: AST_NODE_TYPES.TSIndexSignature;
89
accessibility: Accessibility | undefined;
910
parameters: Parameter[];
1011
readonly: boolean;
1112
static: boolean;
12-
type: AST_NODE_TYPES.TSIndexSignature;
1313
typeAnnotation: TSTypeAnnotation | undefined;
1414
}

0 commit comments

Comments
 (0)