From 05293e91adc73d409ad30a668ce9c6324ee81a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:04:41 +0800 Subject: [PATCH] fix(eslint-config): update perfectionist --- packages/eslint-config/package.json | 3 +- .../src/configs/perfectionist.ts | 59 +++---------------- pnpm-lock.yaml | 5 +- 3 files changed, 14 insertions(+), 53 deletions(-) diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index a8ce536..05051ea 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -36,7 +36,8 @@ "dependencies": { "defu": "^6.1.4", "eslint-flat-config-utils": "^0.4.0", - "eslint-plugin-functional": "^7.2.0" + "eslint-plugin-functional": "^7.2.0", + "eslint-plugin-perfectionist": "^4.4.0" }, "devDependencies": { "@antfu/eslint-config": "^3.12.1", diff --git a/packages/eslint-config/src/configs/perfectionist.ts b/packages/eslint-config/src/configs/perfectionist.ts index d540a30..37abee1 100644 --- a/packages/eslint-config/src/configs/perfectionist.ts +++ b/packages/eslint-config/src/configs/perfectionist.ts @@ -2,54 +2,11 @@ import type { Linter } from 'eslint' import type { Options } from '../options' -type Option = Exclude - -/** @see {@link https://github.com/azat-io/eslint-plugin-perfectionist/blob/bf730c4343275878814b7f48757c06f4adc69ca5/index.ts#L26C1-L29C2} */ -interface PerfectionistOptions { - order: 'asc' | 'desc' - type: 'alphabetical' | 'line-length' | 'natural' -} - -/** @see {@link https://github.com/azat-io/eslint-plugin-perfectionist/blob/bf730c4343275878814b7f48757c06f4adc69ca5/index.ts#L38-L58} */ -const rules = [ - 'sort-variable-declarations', - 'sort-intersection-types', - 'sort-svelte-attributes', - 'sort-astro-attributes', - 'sort-vue-attributes', - 'sort-array-includes', - 'sort-named-imports', - 'sort-named-exports', - 'sort-object-types', - 'sort-union-types', - 'sort-switch-case', - 'sort-interfaces', - 'sort-jsx-props', - 'sort-classes', - 'sort-imports', - 'sort-exports', - 'sort-objects', - 'sort-enums', - 'sort-maps', -] as const - -/** @see {@link https://github.com/azat-io/eslint-plugin-perfectionist/blob/bf730c4343275878814b7f48757c06f4adc69ca5/index.ts#L62-L68} */ -const getRules = (options: PerfectionistOptions): Linter.RulesRecord => - Object.fromEntries( - rules.map(rule => [ - `perfectionist/${rule}`, - ['error', options], - ]), - ) - -export const perfectionist = (type: Option): Linter.FlatConfig => ({ - name: 'importantimport/perfectionist/rules', - rules: { - 'import/order': 'off', - 'sort-imports': 'off', - ...getRules({ - order: type === 'line-length' ? 'desc' : 'asc', - type, - }), - }, -}) +import perfectionistPlugin from 'eslint-plugin-perfectionist' + +export const perfectionist = (option: Exclude): Linter.Config[] => [ + { + name: 'importantimport/perfectionist/rules', + rules: perfectionistPlugin.configs[`recommended-${option}`].rules, + } +] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 100d125..cc4a058 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -67,6 +67,9 @@ importers: eslint-plugin-functional: specifier: ^7.2.0 version: 7.2.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.4.4) + eslint-plugin-perfectionist: + specifier: ^4.4.0 + version: 4.4.0(eslint@9.17.0(jiti@2.4.2))(typescript@5.4.4) devDependencies: '@antfu/eslint-config': specifier: ^3.12.1 @@ -4728,7 +4731,7 @@ snapshots: postcss@8.4.40: dependencies: nanoid: 3.3.7 - picocolors: 1.1.0 + picocolors: 1.1.1 source-map-js: 1.2.0 prelude-ls@1.2.1: {}