From c19559f039a66b1c94a2dfe995c5f9f6b1688e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Mon, 19 Feb 2024 21:28:55 +0800 Subject: [PATCH] feat!: move the optional `sort-keys` plugin to `perfectionist` ref: https://github.com/antfu/eslint-config/commit/9fa74265d1a9bb1ba5ab125a6510e81cfc7a096d# --- eslint.config.js | 6 +-- package.json | 2 +- pnpm-lock.yaml | 44 +++++++++++++++---- src/configs/index.ts | 2 +- .../{sort-keys.ts => perfectionist.ts} | 4 +- src/plugins.ts | 8 +++- src/presets.ts | 4 +- 7 files changed, 50 insertions(+), 20 deletions(-) rename src/configs/{sort-keys.ts => perfectionist.ts} (62%) diff --git a/eslint.config.js b/eslint.config.js index ab84a55..369b2c0 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,17 +1,17 @@ import { createRequire } from 'node:module' +// import { sxzz } from './dist/index.js' + const require = createRequire(import.meta.url) require('sucrase/register') /** @type {typeof import('./src/index.ts')} */ const { sxzz } = require('./src/index.ts') -// import { sxzz } from './dist/index.js' - export default sxzz( [ { files: ['src/**/*.ts'], rules: { - 'sort-keys/sort-keys-fix': 'error', + 'perfectionist/sort-objects': 'error', }, }, { diff --git a/package.json b/package.json index 9581ebf..29e3847 100644 --- a/package.json +++ b/package.json @@ -47,8 +47,8 @@ "eslint-plugin-jsonc": "^2.13.0", "eslint-plugin-markdown": "^3.0.1", "eslint-plugin-n": "^16.6.2", + "eslint-plugin-perfectionist": "^2.5.0", "eslint-plugin-prettier": "^5.1.3", - "eslint-plugin-sort-keys": "^2.3.5", "eslint-plugin-unicorn": "^51.0.1", "eslint-plugin-unused-imports": "^3.1.0", "eslint-plugin-vue": "^9.21.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 56d21b4..5709887 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,12 +32,12 @@ dependencies: eslint-plugin-n: specifier: ^16.6.2 version: 16.6.2(eslint@8.56.0) + eslint-plugin-perfectionist: + specifier: ^2.5.0 + version: 2.5.0(eslint@8.56.0)(typescript@5.3.3)(vue-eslint-parser@9.4.2) eslint-plugin-prettier: specifier: ^5.1.3 version: 5.1.3(eslint-config-prettier@9.1.0)(eslint@8.56.0)(prettier@3.2.5) - eslint-plugin-sort-keys: - specifier: ^2.3.5 - version: 2.3.5 eslint-plugin-unicorn: specifier: ^51.0.1 version: 51.0.1(eslint@8.56.0) @@ -1388,6 +1388,34 @@ packages: semver: 7.5.4 dev: false + /eslint-plugin-perfectionist@2.5.0(eslint@8.56.0)(typescript@5.3.3)(vue-eslint-parser@9.4.2): + resolution: {integrity: sha512-F6XXcq4mKKUe/SREoMGQqzgw6cgCgf3pFzkFfQVIGtqD1yXVpQjnhTepzhBeZfxZwgMzR9HO4yH4CUhIQ2WBcQ==} + peerDependencies: + astro-eslint-parser: ^0.16.0 + eslint: '>=8.0.0' + svelte: '>=3.0.0' + svelte-eslint-parser: ^0.33.0 + vue-eslint-parser: '>=9.0.0' + peerDependenciesMeta: + astro-eslint-parser: + optional: true + svelte: + optional: true + svelte-eslint-parser: + optional: true + vue-eslint-parser: + optional: true + dependencies: + '@typescript-eslint/utils': 6.21.0(eslint@8.56.0)(typescript@5.3.3) + eslint: 8.56.0 + minimatch: 9.0.3 + natural-compare-lite: 1.4.0 + vue-eslint-parser: 9.4.2(eslint@8.56.0) + transitivePeerDependencies: + - supports-color + - typescript + dev: false + /eslint-plugin-prettier@5.1.3(eslint-config-prettier@9.1.0)(eslint@8.56.0)(prettier@3.2.5): resolution: {integrity: sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==} engines: {node: ^14.18.0 || >=16.0.0} @@ -1409,12 +1437,6 @@ packages: synckit: 0.8.8 dev: false - /eslint-plugin-sort-keys@2.3.5: - resolution: {integrity: sha512-2j/XKQ9sNJwK8kIp/U0EvuF6stS6/8aIc53/NskE4C5NRNh4dt3xzbZyOdrVC11cTH6Zo59/pdzA0Kb+2fQGWg==} - dependencies: - natural-compare: 1.4.0 - dev: false - /eslint-plugin-unicorn@51.0.1(eslint@8.56.0): resolution: {integrity: sha512-MuR/+9VuB0fydoI0nIn2RDA5WISRn4AsJyNSaNKLVwie9/ONvQhxOBbkfSICBPnzKrB77Fh6CZZXjgTt/4Latw==} engines: {node: '>=16'} @@ -2198,6 +2220,10 @@ packages: thenify-all: 1.6.0 dev: true + /natural-compare-lite@1.4.0: + resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} + dev: false + /natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} diff --git a/src/configs/index.ts b/src/configs/index.ts index 071af7a..74a8f24 100644 --- a/src/configs/index.ts +++ b/src/configs/index.ts @@ -5,8 +5,8 @@ export * from './javascript' export * from './jsonc' export * from './markdown' export * from './node' +export * from './perfectionist' export * from './prettier' -export * from './sort-keys' export * from './sort' export * from './typescript' export * from './unicorn' diff --git a/src/configs/sort-keys.ts b/src/configs/perfectionist.ts similarity index 62% rename from src/configs/sort-keys.ts rename to src/configs/perfectionist.ts index ce9180d..0c59556 100644 --- a/src/configs/sort-keys.ts +++ b/src/configs/perfectionist.ts @@ -1,10 +1,10 @@ -import { pluginSortKeys } from '../plugins' +import { pluginPerfectionist } from '../plugins' import type { FlatESLintConfigItem } from 'eslint-define-config' export const sortKeys: FlatESLintConfigItem[] = [ { plugins: { - 'sort-keys': pluginSortKeys, + perfectionist: pluginPerfectionist, }, }, ] diff --git a/src/plugins.ts b/src/plugins.ts index 1a5c4f5..ddfa986 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -27,6 +27,12 @@ export const pluginUnicorn = interopDefault(_pluginUnicorn) import * as _pluginVue from 'eslint-plugin-vue' export const pluginVue = interopDefault(_pluginVue) +import * as _pluginNode from 'eslint-plugin-n' +export const pluginNode = interopDefault(_pluginNode) + +import * as _pluginPerfectionist from 'eslint-plugin-perfectionist' +export const pluginPerfectionist = interopDefault(_pluginPerfectionist) + import * as _pluginUnocss from '@unocss/eslint-plugin' export const pluginUnocss: typeof import('@unocss/eslint-plugin').default = interopDefault(_pluginUnocss) @@ -41,8 +47,6 @@ export * as pluginImport from 'eslint-plugin-i' export * as pluginJsonc from 'eslint-plugin-jsonc' export * as pluginUnusedImports from 'eslint-plugin-unused-imports' export * as pluginYml from 'eslint-plugin-yml' -export * as pluginSortKeys from 'eslint-plugin-sort-keys' -export * as pluginNode from 'eslint-plugin-n' export * as parserVue from 'vue-eslint-parser' export * as parserYml from 'yaml-eslint-parser' diff --git a/src/presets.ts b/src/presets.ts index 73f0dec..c9e099e 100644 --- a/src/presets.ts +++ b/src/presets.ts @@ -60,10 +60,10 @@ export { presetBasic as basic, presetAll as all } export function sxzz( config: FlatESLintConfigItem | FlatESLintConfigItem[] = [], { - vue: enableVue = hasVue, - prettier: enablePrettier = true, markdown: enableMarkdown = true, + prettier: enablePrettier = true, unocss: enableUnocss = hasUnocss, + vue: enableVue = hasVue, }: Partial<{ /** Vue support. Auto-enable. */ vue: boolean