Skip to content

chore: update eslint-plugin-perfectionist to v4 #11185

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 9 commits into from
May 16, 2025
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
53 changes: 43 additions & 10 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check

import eslintCommentsPlugin from '@eslint-community/eslint-plugin-eslint-comments/configs';
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import eslintCommentsPlugin from '@eslint-community/eslint-plugin-eslint-comments/configs';
import tseslintInternalPlugin from '@typescript-eslint/eslint-plugin-internal';
import vitestPlugin from '@vitest/eslint-plugin';
import eslintPluginPlugin from 'eslint-plugin-eslint-plugin';
Expand Down Expand Up @@ -594,10 +594,10 @@ export default tseslint.config(
rules: {
'@typescript-eslint/internal/prefer-ast-types-enum': 'off',
'import/no-default-export': 'off',
'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later
'react/jsx-no-target-blank': 'off',
'react/no-unescaped-entities': 'off',
'react/prop-types': 'off',
'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later
},
settings: {
react: {
Expand Down Expand Up @@ -632,7 +632,26 @@ export default tseslint.config(
name: 'all-files',
rules: {
'@typescript-eslint/sort-type-constituents': 'off',
'perfectionist/sort-classes': 'error',
'perfectionist/sort-classes': [
'error',
{
groups: [
'index-signature',
'static-property',
'static-block',
['protected-property', 'protected-accessor-property'],
['private-property', 'private-accessor-property'],
['property', 'accessor-property'],
'constructor',
'static-method',
'protected-method',
'private-method',
'method',
['get-method', 'set-method'],
'unknown',
],
},
],
'perfectionist/sort-enums': 'off',
'perfectionist/sort-objects': 'error',
'perfectionist/sort-union-types': [
Expand All @@ -644,6 +663,20 @@ export default tseslint.config(
],
},
},
{
files: ['packages/ast-spec/src/**/*.ts'],
rules: {
'perfectionist/sort-interfaces': [
'error',
{
customGroups: {
first: ['^type$'],
},
groups: ['first', 'unknown'],
},
],
},
},
{
files: [
'packages/eslint-plugin/src/rules/*.ts',
Expand All @@ -655,10 +688,10 @@ export default tseslint.config(
'error',
{
customGroups: {
first: ['loc', 'name', 'node', 'type'],
fourth: ['fix'],
second: ['meta', 'messageId', 'start'],
third: ['defaultOptions', 'data', 'end'],
first: ['^loc$', '^name$', '^node$', '^type$'],
fourth: ['^fix$'],
second: ['^meta$', '^messageId$', '^start$'],
third: ['^defaultOptions$', '^data$', '^end$'],
},
groups: ['first', 'second', 'third', 'fourth', 'unknown'],
},
Expand All @@ -672,7 +705,7 @@ export default tseslint.config(
'perfectionist/sort-objects': [
'error',
{
customGroups: { top: ['valid'] },
customGroups: { top: ['^valid$'] },
groups: ['top', 'unknown'],
},
],
Expand All @@ -686,8 +719,8 @@ export default tseslint.config(
'error',
{
customGroups: {
first: ['type'],
second: ['loc', 'range'],
first: ['^type$'],
second: ['^loc$', '^range$'],
},
groups: ['first', 'second'],
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jsdoc": "^50.5.0",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-perfectionist": "^3.9.1",
"eslint-plugin-perfectionist": "^4.12.3",
"eslint-plugin-react": "^7.37.3",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-regexp": "^2.7.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/ast-spec/src/expression/UnaryExpression/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import type { UnaryExpressionBase } from '../../base/UnaryExpressionBase';

export interface UnaryExpression extends UnaryExpressionBase {
type: AST_NODE_TYPES.UnaryExpression;
operator: '!' | '+' | '~' | '-' | 'delete' | 'typeof' | 'void';
operator: '!' | '+' | '-' | 'delete' | 'typeof' | 'void' | '~';
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/no-restricted-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function stringifyNode(
}

function getCustomMessage(
bannedType: string | { fixWith?: string; message?: string } | true | null,
bannedType: string | true | { fixWith?: string; message?: string } | null,
): string {
if (!bannedType || bannedType === true) {
return '';
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export type Options = [
ignoreIfStatements?: boolean;
ignoreMixedLogicalExpressions?: boolean;
ignorePrimitives?:
| true
| {
bigint?: boolean;
boolean?: boolean;
number?: boolean;
string?: boolean;
}
| true;
};
ignoreTernaryTests?: boolean;
},
];
Expand Down
2 changes: 0 additions & 2 deletions packages/eslint-plugin/src/util/collectUnusedVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ class UnusedVarsVisitor extends Visitor {
private markVariableAsUsed(
variableOrIdentifier: ScopeVariable | TSESTree.Identifier,
): void;

private markVariableAsUsed(name: string, parent: TSESTree.Node): void;

private markVariableAsUsed(
variableOrIdentifierOrName: string | ScopeVariable | TSESTree.Identifier,
parent?: TSESTree.Node,
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/tests/RuleTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export function batchedSingleLineTests<
Options extends readonly unknown[],
>(
options:
| ValidTestCase<Options>
| ({
output?: string | null;
} & Omit<InvalidTestCase<MessageIds, Options>, 'output'>)
| ValidTestCase<Options>,
} & Omit<InvalidTestCase<MessageIds, Options>, 'output'>),
): (InvalidTestCase<MessageIds, Options> | ValidTestCase<Options>)[] {
// -- eslint counts lines from 1
const lineOffset = options.code.startsWith('\n') ? 2 : 1;
Expand Down
12 changes: 6 additions & 6 deletions packages/eslint-plugin/typings/eslint-rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,11 @@ declare module 'eslint/lib/rules/prefer-destructuring' {
object?: boolean;
}
type Option0 =
| DestructuringTypeConfig
| {
AssignmentExpression?: DestructuringTypeConfig;
VariableDeclarator?: DestructuringTypeConfig;
}
| DestructuringTypeConfig;
};
export interface Option1 {
enforceForRenamedProperties?: boolean;
}
Expand Down Expand Up @@ -554,22 +554,22 @@ declare module 'eslint/lib/rules/no-restricted-imports' {
}
)[];
export type ArrayOfStringOrObjectPatterns =
| string[]
| {
// extended
allowTypeImports?: boolean;
caseSensitive?: boolean;
group?: string[];
regex?: string;
message?: string;
}[]
| string[];
}[];
export type RuleListener =
| Record<string, never>
| {
ExportAllDeclaration(node: TSESTree.ExportAllDeclaration): void;
ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void;
ImportDeclaration(node: TSESTree.ImportDeclaration): void;
}
| Record<string, never>;
};
}

export interface ObjectOfPathsAndPatterns {
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-tester/src/types/DependencyConstraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface SemverVersionConstraint {
readonly range: string;
}
export type AtLeastVersionConstraint =
| `${number}.${number}.${number}`
| `${number}.${number}.${number}-${string}`
| `${number}.${number}.${number}`
| `${number}.${number}`
| `${number}`;
export type VersionConstraint =
Expand Down
2 changes: 0 additions & 2 deletions packages/scope-manager/src/referencer/Referencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ export class Referencer extends Visitor {
}
}
public currentScope(): Scope;

public currentScope(throwOnNull: true): Scope | null;

public currentScope(dontThrowOnNull?: true): Scope | null {
if (!dontThrowOnNull) {
assert(this.scopeManager.currentScope, 'aaa');
Expand Down
4 changes: 2 additions & 2 deletions packages/type-utils/src/isUnsafeAssignment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function isUnsafeAssignment(
receiver: ts.Type,
checker: ts.TypeChecker,
senderNode: TSESTree.Node | null,
): { receiver: ts.Type; sender: ts.Type } | false {
): false | { receiver: ts.Type; sender: ts.Type } {
return isUnsafeAssignmentWorker(
type,
receiver,
Expand All @@ -37,7 +37,7 @@ function isUnsafeAssignmentWorker(
checker: ts.TypeChecker,
senderNode: TSESTree.Node | null,
visited: Map<ts.Type, Set<ts.Type>>,
): { receiver: ts.Type; sender: ts.Type } | false {
): false | { receiver: ts.Type; sender: ts.Type } {
if (isTypeAnyType(type)) {
// Allow assignment of any ==> unknown.
if (isTypeUnknownType(receiver)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/parser-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type DebugLevel =
export type CacheDurationSeconds = number | 'Infinity';

export type EcmaVersion =
| 'latest'
| 3
| 5
| 6
Expand All @@ -33,6 +32,7 @@ export type EcmaVersion =
| 2023
| 2024
| 2025
| 'latest'
| undefined;

export type SourceTypeClassic = 'module' | 'script';
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/ts-eslint/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,11 @@ export type AnyRuleModuleWithMetaDocs = RuleModuleWithMetaDocs<
*/
export type LooseRuleDefinition =
// TODO - remove RuleCreateFunction once we no longer support ESLint 8
| LooseRuleCreateFunction
| {
create: LooseRuleCreateFunction;
meta?: object | undefined;
}
| LooseRuleCreateFunction;
};
/*
eslint-disable-next-line @typescript-eslint/no-explicit-any --
intentionally using `any` to allow bi-directional assignment (unknown and
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/src/ts-eslint/SourceCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ namespace SourceCode {

export type CursorWithSkipOptions =
| number
| FilterPredicate
| {
/**
* The predicate function to choose tokens.
Expand All @@ -429,11 +430,11 @@ namespace SourceCode {
* The count of tokens the cursor skips.
*/
skip?: number;
}
| FilterPredicate;
};

export type CursorWithCountOptions =
| number
| FilterPredicate
| {
/**
* The maximum count of tokens the cursor iterates.
Expand All @@ -447,8 +448,7 @@ namespace SourceCode {
* The flag to iterate comments as well.
*/
includeComments?: boolean;
}
| FilterPredicate;
};
}

class SourceCode extends (ESLintSourceCode as typeof SourceCodeBase) {}
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/components/layout/EditorTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface EditorTabsProps<T extends boolean | string> {
readonly change: (name: T) => void;
readonly showModal?: (name: T) => void;
readonly showVisualEditor?: boolean;
readonly tabs: ({ label: string; value: T } | T)[];
readonly tabs: (T | { label: string; value: T })[];
}

function EditorTabs<T extends boolean | string>({
Expand Down
2 changes: 1 addition & 1 deletion packages/website/src/theme/MDXComponents/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Admonition from '@theme/Admonition';
import MDXComponents from '@theme-original/MDXComponents';
import Admonition from '@theme/Admonition';

import { BaseRuleReference } from './BaseRuleReference';
import { HiddenHeading } from './HiddenHeading';
Expand Down
4 changes: 2 additions & 2 deletions packages/website/webpack.plugin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
// eslint-disable-next-line @typescript-eslint/no-require-imports
const path = require('node:path');
// eslint-disable-next-line @typescript-eslint/no-require-imports
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');

module.exports = function (/*context, options*/) {
return {
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/generate-contributors.mts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function getData<T>(
async function* fetchUsers(page = 1): AsyncIterableIterator<Contributor[]> {
while (page <= MATCH_PAGE_NUMBER) {
console.log(`Fetching page ${page} of contributors...`);
const contributors = await getData<{ message: string } | Contributor[]>(
const contributors = await getData<Contributor[] | { message: string }>(
`${contributorsApiUrl}&page=${page}`,
);

Expand Down
Loading