Skip to content

Commit 3b97b55

Browse files
chore: enable eslint-plugin-perfectionist on the rest of the repo (typescript-eslint#10189)
* chore: enable eslint-plugin-perfectionist on the rest of the repo * one more round of fixing
1 parent c1fe3ea commit 3b97b55

File tree

116 files changed

+1296
-1287
lines changed

Some content is hidden

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

116 files changed

+1296
-1287
lines changed

.github/actions/breaking-pr-check/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ async function getPullRequest() {
2525

2626
const { data } = await client.rest.pulls.get({
2727
owner,
28-
repo,
2928
pull_number: pr.number,
29+
repo,
3030
});
3131

3232
return data;

eslint.config.mjs

Lines changed: 63 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// @ts-check
22

3-
import url from 'node:url';
4-
53
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
64
import { FlatCompat } from '@eslint/eslintrc';
75
import eslint from '@eslint/js';
@@ -16,10 +14,10 @@ import perfectionistPlugin from 'eslint-plugin-perfectionist';
1614
import reactPlugin from 'eslint-plugin-react';
1715
import reactHooksPlugin from 'eslint-plugin-react-hooks';
1816
import regexpPlugin from 'eslint-plugin-regexp';
19-
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
2017
import sonarjsPlugin from 'eslint-plugin-sonarjs';
2118
import unicornPlugin from 'eslint-plugin-unicorn';
2219
import globals from 'globals';
20+
import url from 'node:url';
2321
import tseslint from 'typescript-eslint';
2422

2523
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
@@ -40,16 +38,23 @@ export default tseslint.config(
4038
['jest']: jestPlugin,
4139
['jsdoc']: jsdocPlugin,
4240
['jsx-a11y']: jsxA11yPlugin,
41+
['perfectionist']: perfectionistPlugin,
4342
// https://github.com/facebook/react/issues/28313
4443
['react-hooks']: fixupPluginRules(reactHooksPlugin),
4544
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
4645
['react']: fixupPluginRules(reactPlugin),
4746
['regexp']: regexpPlugin,
48-
['simple-import-sort']: simpleImportSortPlugin,
4947
['sonarjs']: sonarjsPlugin,
5048
['unicorn']: unicornPlugin,
5149
},
5250
/* eslint-enable no-useless-computed-key */
51+
settings: {
52+
perfectionist: {
53+
order: 'asc',
54+
partitionByComment: true,
55+
type: 'natural',
56+
},
57+
},
5358
},
5459
{
5560
// config with just ignores is the replacement for `.eslintignore`
@@ -67,6 +72,7 @@ export default tseslint.config(
6772
'.nx/*',
6873
'.yarn/*',
6974
// Files generated by TypeDoc
75+
'docs/packages/*/generated',
7076
'packages/*/generated',
7177
'docs/packages/*/generated',
7278
// Files copied as part of the build
@@ -109,11 +115,11 @@ export default tseslint.config(
109115
'@typescript-eslint/ban-ts-comment': [
110116
'error',
111117
{
118+
minimumDescriptionLength: 5,
119+
'ts-check': false,
112120
'ts-expect-error': 'allow-with-description',
113121
'ts-ignore': true,
114122
'ts-nocheck': true,
115-
'ts-check': false,
116-
minimumDescriptionLength: 5,
117123
},
118124
],
119125
// TODO: enable it once we drop support for TS<5.0
@@ -124,62 +130,62 @@ export default tseslint.config(
124130
],
125131
'@typescript-eslint/consistent-type-imports': [
126132
'error',
127-
{ prefer: 'type-imports', disallowTypeAnnotations: true },
133+
{ disallowTypeAnnotations: true, prefer: 'type-imports' },
128134
],
129135
'@typescript-eslint/explicit-module-boundary-types': 'error',
130136
'@typescript-eslint/no-explicit-any': 'error',
131-
'no-constant-condition': 'off',
137+
'@typescript-eslint/no-require-imports': [
138+
'error',
139+
{
140+
allow: ['/package\\.json$'],
141+
},
142+
],
132143
'@typescript-eslint/no-unnecessary-condition': [
133144
'error',
134145
{ allowConstantLoopConditions: true, checkTypePredicates: true },
135146
],
136147
'@typescript-eslint/no-unnecessary-type-parameters': 'error',
137148
'@typescript-eslint/no-unused-expressions': 'error',
149+
'@typescript-eslint/no-unused-vars': [
150+
'error',
151+
{
152+
argsIgnorePattern: '^_',
153+
caughtErrors: 'all',
154+
varsIgnorePattern: '^_',
155+
},
156+
],
138157
'@typescript-eslint/no-var-requires': 'off',
139158
'@typescript-eslint/prefer-literal-enum-member': [
140159
'error',
141160
{
142161
allowBitwiseExpressions: true,
143162
},
144163
],
164+
'@typescript-eslint/prefer-nullish-coalescing': [
165+
'error',
166+
{
167+
ignoreConditionalTests: true,
168+
ignorePrimitives: true,
169+
},
170+
],
145171
'@typescript-eslint/prefer-string-starts-ends-with': [
146172
'error',
147173
{
148174
allowSingleElementEquality: 'always',
149175
},
150176
],
151-
'@typescript-eslint/unbound-method': 'off',
152177
'@typescript-eslint/restrict-template-expressions': [
153178
'error',
154179
{
155-
allowNumber: true,
156-
allowBoolean: true,
157180
allowAny: true,
181+
allowBoolean: true,
158182
allowNullish: true,
183+
allowNumber: true,
159184
allowRegExp: true,
160185
},
161186
],
162-
'@typescript-eslint/no-unused-vars': [
163-
'error',
164-
{
165-
caughtErrors: 'all',
166-
varsIgnorePattern: '^_',
167-
argsIgnorePattern: '^_',
168-
},
169-
],
170-
'@typescript-eslint/prefer-nullish-coalescing': [
171-
'error',
172-
{
173-
ignoreConditionalTests: true,
174-
ignorePrimitives: true,
175-
},
176-
],
177-
'@typescript-eslint/no-require-imports': [
178-
'error',
179-
{
180-
allow: ['/package\\.json$'],
181-
},
182-
],
187+
'@typescript-eslint/unbound-method': 'off',
188+
'no-constant-condition': 'off',
183189

184190
//
185191
// Internal repo rules
@@ -204,16 +210,16 @@ export default tseslint.config(
204210
},
205211
],
206212
'logical-assignment-operators': 'error',
207-
'no-else-return': 'error',
208-
'no-mixed-operators': 'error',
209213
'no-console': 'error',
210-
'no-process-exit': 'error',
214+
'no-else-return': 'error',
211215
'no-fallthrough': [
212216
'error',
213217
{ commentPattern: '.*intentional fallthrough.*' },
214218
],
215219
'no-implicit-coercion': ['error', { boolean: false }],
216220
'no-lonely-if': 'error',
221+
'no-mixed-operators': 'error',
222+
'no-process-exit': 'error',
217223
'no-unreachable-loop': 'error',
218224
'no-useless-call': 'error',
219225
'no-useless-computed-key': 'error',
@@ -288,8 +294,8 @@ export default tseslint.config(
288294
'error',
289295
{
290296
devDependencies: true,
291-
peerDependencies: true,
292297
optionalDependencies: false,
298+
peerDependencies: true,
293299
},
294300
],
295301
// Forbid mutable exports
@@ -304,7 +310,7 @@ export default tseslint.config(
304310
'import/prefer-default-export': 'off', // we want everything to be named
305311

306312
// enforce a sort order across the codebase
307-
'simple-import-sort/imports': 'error',
313+
'perfectionist/sort-imports': 'error',
308314

309315
//
310316
// eslint-plugin-jsdoc
@@ -339,8 +345,8 @@ export default tseslint.config(
339345

340346
'unicorn/no-length-as-slice-end': 'error',
341347
'unicorn/no-lonely-if': 'error',
342-
'unicorn/no-typeof-undefined': 'error',
343348
'unicorn/no-single-promise-in-promise-methods': 'error',
349+
'unicorn/no-typeof-undefined': 'error',
344350
'unicorn/no-useless-spread': 'error',
345351
'unicorn/prefer-array-some': 'error',
346352
'unicorn/prefer-export-from': 'error',
@@ -352,8 +358,8 @@ export default tseslint.config(
352358
},
353359
},
354360
{
355-
files: ['**/*.js'],
356361
extends: [tseslint.configs.disableTypeChecked],
362+
files: ['**/*.js'],
357363
rules: {
358364
// turn off other type-aware rules
359365
'@typescript-eslint/internal/no-poorly-typed-ts-props': 'off',
@@ -395,20 +401,20 @@ export default tseslint.config(
395401
'@typescript-eslint/no-unsafe-call': 'off',
396402
'@typescript-eslint/no-unsafe-member-access': 'off',
397403
'@typescript-eslint/no-unsafe-return': 'off',
404+
'jest/no-alias-methods': 'error',
405+
'jest/no-deprecated-functions': 'error',
398406
'jest/no-disabled-tests': 'error',
407+
'jest/no-done-callback': 'error',
399408
'jest/no-focused-tests': 'error',
400-
'jest/no-alias-methods': 'error',
401409
'jest/no-identical-title': 'error',
402410
'jest/no-jasmine-globals': 'error',
403411
'jest/no-test-prefixes': 'error',
404-
'jest/no-done-callback': 'error',
405412
'jest/no-test-return-statement': 'error',
413+
'jest/prefer-spy-on': 'error',
406414
'jest/prefer-to-be': 'error',
407415
'jest/prefer-to-contain': 'error',
408416
'jest/prefer-to-have-length': 'error',
409-
'jest/prefer-spy-on': 'error',
410417
'jest/valid-expect': 'error',
411-
'jest/no-deprecated-functions': 'error',
412418
},
413419
},
414420
// plugin rule tests
@@ -451,16 +457,16 @@ export default tseslint.config(
451457
//
452458

453459
{
460+
extends: [...compat.config(eslintPluginPlugin.configs.recommended)],
454461
files: [
455462
'packages/eslint-plugin-internal/**/*.{ts,tsx,cts,mts}',
456463
'packages/eslint-plugin-tslint/**/*.{ts,tsx,cts,mts}',
457464
'packages/eslint-plugin/**/*.{ts,tsx,cts,mts}',
458465
],
466+
459467
rules: {
460468
'@typescript-eslint/internal/no-typescript-estree-import': 'error',
461469
},
462-
463-
extends: [...compat.config(eslintPluginPlugin.configs.recommended)],
464470
},
465471
{
466472
files: [
@@ -491,10 +497,10 @@ export default tseslint.config(
491497
'no-restricted-syntax': [
492498
'error',
493499
{
494-
selector:
495-
'ExportDefaultDeclaration Property[key.name="create"] MemberExpression[object.name="context"][property.name="options"]',
496500
message:
497501
"Retrieve options from create's second parameter so that defaultOptions are applied.",
502+
selector:
503+
'ExportDefaultDeclaration Property[key.name="create"] MemberExpression[object.name="context"][property.name="options"]',
498504
},
499505
],
500506
},
@@ -503,8 +509,8 @@ export default tseslint.config(
503509
files: ['packages/eslint-plugin/src/rules/index.ts'],
504510
rules: {
505511
// enforce alphabetical ordering
506-
'sort-keys': 'error',
507512
'import/order': ['error', { alphabetize: { order: 'asc' } }],
513+
'sort-keys': 'error',
508514
},
509515
},
510516

@@ -543,9 +549,9 @@ export default tseslint.config(
543549
'no-restricted-imports': [
544550
'error',
545551
{
546-
name: '@typescript-eslint/typescript-estree',
547552
message:
548553
'To prevent nx build errors, all `typescript-estree` imports should be done via `packages/ast-spec/tests/util/parsers/typescript-estree-import.ts`.',
554+
name: '@typescript-eslint/typescript-estree',
549555
},
550556
],
551557
},
@@ -556,19 +562,19 @@ export default tseslint.config(
556562
//
557563

558564
{
559-
files: ['packages/website/**/*.{ts,tsx,mts,cts,js,jsx}'],
560565
extends: [
561566
...compat.config(jsxA11yPlugin.configs.recommended),
562567
...fixupConfigRules(compat.config(reactPlugin.configs.recommended)),
563568
...fixupConfigRules(compat.config(reactHooksPlugin.configs.recommended)),
564569
],
570+
files: ['packages/website/**/*.{ts,tsx,mts,cts,js,jsx}'],
565571
rules: {
566572
'@typescript-eslint/internal/prefer-ast-types-enum': 'off',
567573
'import/no-default-export': 'off',
568574
'react/jsx-no-target-blank': 'off',
569575
'react/no-unescaped-entities': 'off',
570-
'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later
571576
'react/prop-types': 'off',
577+
'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later
572578
},
573579
settings: {
574580
react: {
@@ -595,28 +601,12 @@ export default tseslint.config(
595601
},
596602
},
597603
{
598-
extends: [perfectionistPlugin.configs['recommended-alphabetical']],
604+
files: ['**/*'],
599605
ignores: [
600606
'packages/eslint-plugin/src/configs/*',
601607
'packages/scope-manager/src/configs/*',
602608
'packages/typescript-eslint/src/configs/*',
603609
],
604-
files: [
605-
'packages/ast-spec/{src,tests,typings}/**/*.ts',
606-
'packages/eslint-plugin/{src,tests,tools,typings}/**/*.ts',
607-
'packages/integration-tests/{tests,tools,typing}/**/*.ts',
608-
'packages/parser/{src,tests}/**/*.ts',
609-
'packages/rule-schema-to-typescript-types/src/**/*.ts',
610-
'packages/rule-tester/{src,tests,typings}/**/*.ts',
611-
'packages/scope-manager/{src,tests}/**/*.ts',
612-
'packages/type-utils/{src,tests,typings}/**/*.ts',
613-
'packages/types/{src,tools}/**/*.ts',
614-
'packages/typescript-eslint/{src,tests}/**/*.ts',
615-
'packages/typescript-estree/{src,tests,typings}/**/*.ts',
616-
'packages/utils/src/**/*.ts',
617-
'packages/visitor-keys/src/**/*.ts',
618-
'packages/website*/src/**/*.ts',
619-
],
620610
rules: {
621611
'@typescript-eslint/sort-type-constituents': 'off',
622612
'perfectionist/sort-classes': 'error',
@@ -629,14 +619,6 @@ export default tseslint.config(
629619
type: 'natural',
630620
},
631621
],
632-
'simple-import-sort/imports': 'off',
633-
},
634-
settings: {
635-
perfectionist: {
636-
partitionByComment: true,
637-
order: 'asc',
638-
type: 'natural',
639-
},
640622
},
641623
},
642624
{
@@ -654,16 +636,19 @@ export default tseslint.config(
654636
},
655637
},
656638
{
657-
files: ['packages/eslint-plugin/src/rules/*.ts'],
639+
files: [
640+
'packages/eslint-plugin/src/rules/*.ts',
641+
'packages/eslint-plugin-internal/src/rules/*.ts',
642+
],
658643
rules: {
659644
'perfectionist/sort-objects': [
660645
'error',
661646
{
662647
customGroups: {
663648
first: ['loc', 'name', 'node', 'type'],
649+
fourth: ['fix'],
664650
second: ['meta', 'messageId', 'start'],
665651
third: ['defaultOptions', 'data', 'end'],
666-
fourth: ['fix'],
667652
},
668653
groups: ['first', 'second', 'third', 'fourth', 'unknown'],
669654
},

0 commit comments

Comments
 (0)