Skip to content

chore: enable eslint-plugin-perfectionist on eslint-plugin package, with ordering tweaks #9843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
65 changes: 52 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,13 @@ export default tseslint.config(
},
{
extends: [perfectionistPlugin.configs['recommended-alphabetical']],
ignores: ['packages/typescript-eslint/src/configs/*'],
ignores: [
'packages/eslint-plugin/src/configs/*',
'packages/typescript-eslint/src/configs/*',
],
files: [
'packages/ast-spec/{src,tests,typings}/**/*.ts',
'packages/eslint-plugin/{src,tests,tools,typings}/**/*.ts',
'packages/integration-tests/{tests,tools,typing}/**/*.ts',
'packages/parser/{src,tests}/**/*.ts',
'packages/rule-schema-to-typescript-types/src/**/*.ts',
Expand All @@ -611,32 +615,67 @@ export default tseslint.config(
],
rules: {
'@typescript-eslint/sort-type-constituents': 'off',
'perfectionist/sort-classes': [
'perfectionist/sort-classes': 'error',
'perfectionist/sort-enums': 'off',
'perfectionist/sort-objects': 'error',
'perfectionist/sort-union-types': [
'error',
{
order: 'asc',
partitionByComment: true,
groups: ['unknown', 'keyword', 'nullish'],
type: 'natural',
},
],
'perfectionist/sort-enums': 'off',
'simple-import-sort/imports': 'off',
},
settings: {
perfectionist: {
partitionByComment: true,
order: 'asc',
type: 'natural',
},
},
},
{
files: ['packages/ast-spec/src/**/*.ts'],
rules: {
'perfectionist/sort-interfaces': [
'error',
{
customGroups: {
first: ['type'],
},
groups: ['first', 'unknown'],
},
],
},
},
{
files: ['packages/eslint-plugin/src/rules/*.ts'],
rules: {
'perfectionist/sort-objects': [
'error',
{
order: 'asc',
partitionByComment: true,
type: 'natural',
customGroups: {
first: ['loc', 'name', 'node', 'type'],
second: ['meta', 'messageId', 'start'],
third: ['defaultOptions', 'data', 'end'],
fourth: ['fix'],
},
groups: ['first', 'second', 'third', 'fourth', 'unknown'],
},
],
'perfectionist/sort-union-types': [
},
},
{
files: ['packages/eslint-plugin/tests/rules/*.test.ts'],
rules: {
'perfectionist/sort-objects': [
'error',
{
order: 'asc',
groups: ['unknown', 'keyword', 'nullish'],
type: 'natural',
customGroups: { top: ['valid'] },
groups: ['top', 'unknown'],
},
],
'simple-import-sort/imports': 'off',
},
},
);
2 changes: 1 addition & 1 deletion packages/ast-spec/src/base/LiteralBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AST_NODE_TYPES } from '../ast-node-types';
import type { BaseNode } from './BaseNode';

export interface LiteralBase extends BaseNode {
raw: string;
type: AST_NODE_TYPES.Literal;
raw: string;
value: RegExp | bigint | boolean | number | string | null;
}
4 changes: 2 additions & 2 deletions packages/ast-spec/src/base/NodeOrTokenData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { Range } from './Range';
import type { SourceLocation } from './SourceLocation';

export interface NodeOrTokenData {
type: string;

/**
* The source location information of the node.
*
Expand All @@ -10,6 +12,4 @@ export interface NodeOrTokenData {
loc: SourceLocation;

range: Range;

type: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ImportAttribute } from '../../special/ImportAttribute/spec';
import type { ExportKind } from '../ExportAndImportKind';

export interface ExportAllDeclaration extends BaseNode {
type: AST_NODE_TYPES.ExportAllDeclaration;
/**
* The assertions declared for the export.
* @example
Expand Down Expand Up @@ -35,5 +36,4 @@ export interface ExportAllDeclaration extends BaseNode {
* The source module being exported from.
*/
source: StringLiteral;
type: AST_NODE_TYPES.ExportAllDeclaration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { BaseNode } from '../../base/BaseNode';
import type { DefaultExportDeclarations } from '../../unions/ExportDeclaration';

export interface ExportDefaultDeclaration extends BaseNode {
type: AST_NODE_TYPES.ExportDefaultDeclaration;
/**
* The declaration being exported.
*/
Expand All @@ -11,5 +12,4 @@ export interface ExportDefaultDeclaration extends BaseNode {
* The kind of the export. Always `value` for default exports.
*/
exportKind: 'value';
type: AST_NODE_TYPES.ExportDefaultDeclaration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { NamedExportDeclarations } from '../../unions/ExportDeclaration';
import type { ExportKind } from '../ExportAndImportKind';

interface ExportNamedDeclarationBase extends BaseNode {
type: AST_NODE_TYPES.ExportNamedDeclaration;
/**
* The assertions declared for the export.
* @example
Expand Down Expand Up @@ -52,7 +53,6 @@ interface ExportNamedDeclarationBase extends BaseNode {
* This will be an empty array if `declaration` is not `null`
*/
specifiers: ExportSpecifier[];
type: AST_NODE_TYPES.ExportNamedDeclaration;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import type { Identifier } from '../../expression/Identifier/spec';
import type { BlockStatement } from '../../statement/BlockStatement/spec';

interface FunctionDeclarationBase extends FunctionBase {
type: AST_NODE_TYPES.FunctionDeclaration;
body: BlockStatement;
declare: false;
expression: false;
type: AST_NODE_TYPES.FunctionDeclaration;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { ImportClause } from '../../unions/ImportClause';
import type { ImportKind } from '../ExportAndImportKind';

export interface ImportDeclaration extends BaseNode {
type: AST_NODE_TYPES.ImportDeclaration;
/**
* The assertions declared for the export.
* @example
Expand Down Expand Up @@ -43,5 +44,4 @@ export interface ImportDeclaration extends BaseNode {
* ```
*/
specifiers: ImportClause[];
type: AST_NODE_TYPES.ImportDeclaration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types';
import type { FunctionBase } from '../../base/FunctionBase';

interface TSDeclareFunctionBase extends FunctionBase {
type: AST_NODE_TYPES.TSDeclareFunction;
/**
* TS1183: An implementation cannot be declared in ambient contexts.
*/
Expand All @@ -11,7 +12,6 @@ interface TSDeclareFunctionBase extends FunctionBase {
*/
declare: boolean;
expression: false;
type: AST_NODE_TYPES.TSDeclareFunction;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Identifier } from '../../expression/Identifier/spec';
import type { TSEnumBody } from '../../special/TSEnumBody/spec';

export interface TSEnumDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSEnumDeclaration;
/**
* The body of the enum.
*/
Expand Down Expand Up @@ -34,5 +35,4 @@ export interface TSEnumDeclaration extends BaseNode {
* @deprecated Use {@link body} instead.
*/
members: TSEnumMember[];
type: AST_NODE_TYPES.TSEnumDeclaration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { TSQualifiedName } from '../../type/TSQualifiedName/spec';
import type { ImportKind } from '../ExportAndImportKind';

interface TSImportEqualsDeclarationBase extends BaseNode {
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
/**
* The locally imported name.
*/
Expand All @@ -25,7 +26,6 @@ interface TSImportEqualsDeclarationBase extends BaseNode {
* ```
*/
moduleReference: Identifier | TSExternalModuleReference | TSQualifiedName;
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
}

export interface TSImportEqualsNamespaceDeclaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { TSInterfaceHeritage } from '../../special/TSInterfaceHeritage/spec
import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDeclaration/spec';

export interface TSInterfaceDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSInterfaceDeclaration;
/**
* The body of the interface
*/
Expand All @@ -22,7 +23,6 @@ export interface TSInterfaceDeclaration extends BaseNode {
* The name of this interface
*/
id: Identifier;
type: AST_NODE_TYPES.TSInterfaceDeclaration;
/**
* The generic type parameters declared for the interface. Empty declaration
* (`<>`) is different from no declaration.
Expand Down
4 changes: 2 additions & 2 deletions packages/ast-spec/src/declaration/TSModuleDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Literal } from '../../unions/Literal';
export type TSModuleDeclarationKind = 'global' | 'module' | 'namespace';

interface TSModuleDeclarationBase extends BaseNode {
type: AST_NODE_TYPES.TSModuleDeclaration;
/**
* The body of the module.
* This can only be `undefined` for the code `declare module 'mod';`
Expand Down Expand Up @@ -42,6 +43,7 @@ interface TSModuleDeclarationBase extends BaseNode {
* ```
*/
id: Identifier | Literal | TSQualifiedName;

/**
* The keyword used to define this module declaration
* @example
Expand All @@ -57,8 +59,6 @@ interface TSModuleDeclarationBase extends BaseNode {
* ```
*/
kind: TSModuleDeclarationKind;

type: AST_NODE_TYPES.TSModuleDeclaration;
}

export interface TSModuleDeclarationNamespace extends TSModuleDeclarationBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import type { Identifier } from '../../expression/Identifier/spec';
* ```
*/
export interface TSNamespaceExportDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSNamespaceExportDeclaration;
/**
* The name of the global variable that's exported as namespace
*/
id: Identifier;
type: AST_NODE_TYPES.TSNamespaceExportDeclaration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { TSTypeParameterDeclaration } from '../../special/TSTypeParameterDe
import type { TypeNode } from '../../unions/TypeNode';

export interface TSTypeAliasDeclaration extends BaseNode {
type: AST_NODE_TYPES.TSTypeAliasDeclaration;
/**
* Whether the type was `declare`d.
* @example
Expand All @@ -17,7 +18,6 @@ export interface TSTypeAliasDeclaration extends BaseNode {
* The name of the type.
*/
id: Identifier;
type: AST_NODE_TYPES.TSTypeAliasDeclaration;
/**
* The "value" (type) of the declaration
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/ast-spec/src/declaration/VariableDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
} from '../../special/VariableDeclarator/spec';

interface LetOrConstOrVarDeclarationBase extends BaseNode {
type: AST_NODE_TYPES.VariableDeclaration;
/**
* The variables declared by this declaration.
* Always non-empty.
Expand Down Expand Up @@ -38,7 +39,6 @@ interface LetOrConstOrVarDeclarationBase extends BaseNode {
* ```
*/
kind: 'const' | 'let' | 'var';
type: AST_NODE_TYPES.VariableDeclaration;
}

export interface LetOrVarDeclaredDeclaration
Expand Down Expand Up @@ -91,6 +91,7 @@ export type LetOrConstOrVarDeclaration =
| LetOrVarNonDeclaredDeclaration;

interface UsingDeclarationBase extends BaseNode {
type: AST_NODE_TYPES.VariableDeclaration;
/**
* This value will always be `false`
* because 'declare' modifier cannot appear on a 'using' declaration.
Expand All @@ -105,7 +106,6 @@ interface UsingDeclarationBase extends BaseNode {
* ```
*/
kind: 'await using' | 'using';
type: AST_NODE_TYPES.VariableDeclaration;
}

export interface UsingInNormalContextDeclaration extends UsingDeclarationBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-spec/src/element/Property/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import type {
} from '../../unions/PropertyName';

interface PropertyBase extends BaseNode {
type: AST_NODE_TYPES.Property;
computed: boolean;
key: PropertyName;
kind: 'get' | 'init' | 'set';
method: boolean;
optional: boolean;
shorthand: boolean;
type: AST_NODE_TYPES.Property;
value:
| AssignmentPattern
| BindingName
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-spec/src/element/SpreadElement/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode';
import type { Expression } from '../../unions/Expression';

export interface SpreadElement extends BaseNode {
argument: Expression;
type: AST_NODE_TYPES.SpreadElement;
argument: Expression;
}
2 changes: 1 addition & 1 deletion packages/ast-spec/src/element/StaticBlock/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import type { BaseNode } from '../../base/BaseNode';
import type { Statement } from '../../unions/Statement';

export interface StaticBlock extends BaseNode {
body: Statement[];
type: AST_NODE_TYPES.StaticBlock;
body: Statement[];
}
2 changes: 1 addition & 1 deletion packages/ast-spec/src/element/TSEnumMember/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import type {
} from '../../unions/PropertyName';

interface TSEnumMemberBase extends BaseNode {
type: AST_NODE_TYPES.TSEnumMember;
computed: boolean;
id:
| PropertyNameComputed // this should only happen in semantically invalid code (ts error 1164)
| PropertyNameNonComputed;
initializer: Expression | undefined;
type: AST_NODE_TYPES.TSEnumMember;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-spec/src/element/TSIndexSignature/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { TSTypeAnnotation } from '../../special/TSTypeAnnotation/spec';
import type { Parameter } from '../../unions/Parameter';

export interface TSIndexSignature extends BaseNode {
type: AST_NODE_TYPES.TSIndexSignature;
accessibility: Accessibility | undefined;
parameters: Parameter[];
readonly: boolean;
static: boolean;
type: AST_NODE_TYPES.TSIndexSignature;
typeAnnotation: TSTypeAnnotation | undefined;
}
Loading
Loading