Skip to content

chore: enable eslint-plugin-perfectionist on ast-spec package #9842

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
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,13 @@ export default tseslint.config(
{
extends: [perfectionistPlugin.configs['recommended-alphabetical']],
files: [
'packages/ast-spec/{src,tests,typings}/**/*.ts',
'packages/utils/src/**/*.ts',
'packages/visitor-keys/src/**/*.ts',
'packages/website*/src/**/*.ts',
],
rules: {
'@typescript-eslint/sort-type-constituents': 'off',
'perfectionist/sort-classes': [
'error',
{
Expand All @@ -584,6 +586,14 @@ export default tseslint.config(
type: 'natural',
},
],
'perfectionist/sort-enums': [
'error',
{
order: 'asc',
partitionByComment: true,
type: 'natural',
},
],
'perfectionist/sort-objects': [
'error',
{
Expand Down
5 changes: 2 additions & 3 deletions packages/ast-spec/src/ast-node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export enum AST_NODE_TYPES {
YieldExpression = 'YieldExpression',

// TS_prefixed nodes

TSAbstractAccessorProperty = 'TSAbstractAccessorProperty',
TSAbstractKeyword = 'TSAbstractKeyword',
TSAbstractMethodDefinition = 'TSAbstractMethodDefinition',
Expand All @@ -109,19 +108,19 @@ export enum AST_NODE_TYPES {
TSDeclareFunction = 'TSDeclareFunction',
TSDeclareKeyword = 'TSDeclareKeyword',
TSEmptyBodyFunctionExpression = 'TSEmptyBodyFunctionExpression',
TSEnumDeclaration = 'TSEnumDeclaration',
TSEnumBody = 'TSEnumBody',
TSEnumDeclaration = 'TSEnumDeclaration',
TSEnumMember = 'TSEnumMember',
TSExportAssignment = 'TSExportAssignment',
TSExportKeyword = 'TSExportKeyword',
TSExternalModuleReference = 'TSExternalModuleReference',
TSFunctionType = 'TSFunctionType',
TSInstantiationExpression = 'TSInstantiationExpression',
TSImportEqualsDeclaration = 'TSImportEqualsDeclaration',
TSImportType = 'TSImportType',
TSIndexedAccessType = 'TSIndexedAccessType',
TSIndexSignature = 'TSIndexSignature',
TSInferType = 'TSInferType',
TSInstantiationExpression = 'TSInstantiationExpression',
TSInterfaceBody = 'TSInterfaceBody',
TSInterfaceDeclaration = 'TSInterfaceDeclaration',
TSInterfaceHeritage = 'TSInterfaceHeritage',
Expand Down
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 {
type: AST_NODE_TYPES.Literal;
raw: string;
type: AST_NODE_TYPES.Literal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love it if we could force type to be first, always.
I'm not going to block on it as alpha sorting is king.

But for ast-spec specifically always defining type first is really nice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agreed. I can mess around with https://perfectionist.dev/rules/sort-imports#groups ...

value: RegExp | bigint | boolean | number | string | null;
}
16 changes: 8 additions & 8 deletions packages/ast-spec/src/base/MethodDefinitionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ import type { BaseNode } from './BaseNode';

/** this should not be directly used - instead use MethodDefinitionComputedNameBase or MethodDefinitionNonComputedNameBase */
interface MethodDefinitionBase extends BaseNode {
key: PropertyName;
value: FunctionExpression | TSEmptyBodyFunctionExpression;
accessibility: Accessibility | undefined;
computed: boolean;
static: boolean;
decorators: Decorator[];
key: PropertyName;
kind: 'constructor' | 'get' | 'method' | 'set';
optional: boolean;
decorators: Decorator[];
accessibility: Accessibility | undefined;
override: boolean;
static: boolean;
value: FunctionExpression | TSEmptyBodyFunctionExpression;
}

export interface MethodDefinitionComputedNameBase extends MethodDefinitionBase {
key: PropertyNameComputed;
computed: true;
key: PropertyNameComputed;
}

export interface MethodDefinitionNonComputedNameBase
extends MethodDefinitionBase {
key: PropertyNameNonComputed;
computed: false;
key: PropertyNameNonComputed;
}

export interface ClassMethodDefinitionNonComputedNameBase
extends MethodDefinitionBase {
key: ClassPropertyNameNonComputed;
computed: false;
key: ClassPropertyNameNonComputed;
}
9 changes: 3 additions & 6 deletions packages/ast-spec/src/base/OptionalRangeAndLoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import type { Range } from './Range';
import type { SourceLocation } from './SourceLocation';

// TODO - breaking change move this into `typescript-estree`
export type OptionalRangeAndLoc<T> = Pick<
T,
Exclude<keyof T, 'loc' | 'range'>
> & {
range?: Range;
export type OptionalRangeAndLoc<T> = {
loc?: SourceLocation;
};
range?: Range;
} & Pick<T, Exclude<keyof T, 'loc' | 'range'>>;
8 changes: 4 additions & 4 deletions packages/ast-spec/src/base/Position.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export interface Position {
/**
* Line number (1-indexed)
*/
line: number;
/**
* Column number on the line (0-indexed)
*/
column: number;
/**
* Line number (1-indexed)
*/
line: number;
}
20 changes: 10 additions & 10 deletions packages/ast-spec/src/base/PropertyDefinitionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ import type { Accessibility } from './Accessibility';
import type { BaseNode } from './BaseNode';

interface PropertyDefinitionBase extends BaseNode {
key: PropertyName;
value: Expression | null;
accessibility: Accessibility | undefined;
computed: boolean;
static: boolean;
declare: boolean;
readonly: boolean;
decorators: Decorator[];
accessibility: Accessibility | undefined;
optional: boolean;
definite: boolean;
typeAnnotation: TSTypeAnnotation | undefined;
key: PropertyName;
optional: boolean;
override: boolean;
readonly: boolean;
static: boolean;
typeAnnotation: TSTypeAnnotation | undefined;
value: Expression | null;
}

export interface PropertyDefinitionComputedNameBase
extends PropertyDefinitionBase {
key: PropertyNameComputed;
computed: true;
key: PropertyNameComputed;
}

export interface PropertyDefinitionNonComputedNameBase
extends PropertyDefinitionBase {
key: PropertyNameNonComputed;
computed: false;
key: PropertyNameNonComputed;
}

export interface ClassPropertyDefinitionNonComputedNameBase
extends PropertyDefinitionBase {
key: ClassPropertyNameNonComputed;
computed: false;
key: ClassPropertyNameNonComputed;
}
8 changes: 4 additions & 4 deletions packages/ast-spec/src/base/SourceLocation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Position } from './Position';

export interface SourceLocation {
/**
* The position of the first character of the parsed source region
*/
start: Position;
/**
* The position of the first character after the parsed source region
*/
end: Position;
/**
* The position of the first character of the parsed source region
*/
start: Position;
}
2 changes: 1 addition & 1 deletion packages/ast-spec/src/base/UnaryExpressionBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Expression } from '../unions/Expression';
import type { BaseNode } from './BaseNode';

export interface UnaryExpressionBase extends BaseNode {
argument: Expression;
operator: string;
prefix: boolean;
argument: Expression;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 @@ -36,4 +35,5 @@ 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,7 +3,6 @@ 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 @@ -12,4 +11,5 @@ 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,7 +7,6 @@ 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 @@ -53,6 +52,7 @@ 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,7 +6,6 @@ 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 @@ -44,4 +43,5 @@ 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,7 +2,6 @@ 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 @@ -12,6 +11,7 @@ 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,7 +5,6 @@ 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 @@ -35,4 +34,5 @@ export interface TSEnumDeclaration extends BaseNode {
* @deprecated Use {@link body} instead.
*/
members: TSEnumMember[];
type: AST_NODE_TYPES.TSEnumDeclaration;
}
28 changes: 14 additions & 14 deletions packages/ast-spec/src/declaration/TSImportEqualsDeclaration/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ 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.
*/
id: Identifier;
/**
* The kind of the import. Always `'value'` unless `moduleReference` is a
* `TSExternalModuleReference`.
*/
importKind: ImportKind;
/**
* The value being aliased.
* @example
Expand All @@ -21,15 +25,15 @@ interface TSImportEqualsDeclarationBase extends BaseNode {
* ```
*/
moduleReference: Identifier | TSExternalModuleReference | TSQualifiedName;
/**
* The kind of the import. Always `'value'` unless `moduleReference` is a
* `TSExternalModuleReference`.
*/
importKind: ImportKind;
type: AST_NODE_TYPES.TSImportEqualsDeclaration;
}

export interface TSImportEqualsNamespaceDeclaration
extends TSImportEqualsDeclarationBase {
/**
* The kind of the import.
*/
importKind: 'value';
/**
* The value being aliased.
* ```
Expand All @@ -38,25 +42,21 @@ export interface TSImportEqualsNamespaceDeclaration
* ```
*/
moduleReference: Identifier | TSQualifiedName;
/**
* The kind of the import.
*/
importKind: 'value';
}

export interface TSImportEqualsRequireDeclaration
extends TSImportEqualsDeclarationBase {
/**
* The kind of the import.
*/
importKind: ImportKind;
/**
* The value being aliased.
* ```
* import F3 = require('mod');
* ```
*/
moduleReference: TSExternalModuleReference;
/**
* The kind of the import.
*/
importKind: ImportKind;
}

export type TSImportEqualsDeclaration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 @@ -23,6 +22,7 @@ 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
Loading
Loading