From 1f38b71beeb434925c04d77620184510e5df7ec7 Mon Sep 17 00:00:00 2001 From: nirtamir2 Date: Tue, 25 Feb 2025 01:03:38 +0200 Subject: [PATCH] Add eslint-plugin-sort-destructure-keys-typescript and eslint-plugin-default-import-name (#3) --- package.json | 1 + pnpm-lock.yaml | 18 ++++++++++ src/configs/astro.ts | 4 +-- src/configs/default-import-name.ts | 6 ++++ src/configs/formatters.ts | 57 ++++++++++++++++-------------- src/configs/ignores.ts | 2 +- src/configs/react.ts | 14 ++++---- src/configs/tsdoc.ts | 8 +++-- src/configs/typescript.ts | 5 +-- src/configs/vue.ts | 2 +- src/factory.ts | 2 ++ src/plugins.ts | 1 - src/types.ts | 6 ++-- 13 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 src/configs/default-import-name.ts diff --git a/package.json b/package.json index c46c37558d..d6d811f878 100644 --- a/package.json +++ b/package.json @@ -149,6 +149,7 @@ "eslint-plugin-array-func": "^5.0.2", "eslint-plugin-clsx": "^0.0.10", "eslint-plugin-command": "^3.1.0", + "eslint-plugin-default-import-name": "^0.2.0", "eslint-plugin-eslint-comments": "^3.2.0", "eslint-plugin-expect-type": "^0.6.2", "eslint-plugin-github": "^5.1.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ce12946d9..2b7f7d50bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -74,6 +74,9 @@ importers: eslint-plugin-command: specifier: ^3.1.0 version: 3.1.0(eslint@9.21.0(jiti@2.4.2)) + eslint-plugin-default-import-name: + specifier: ^0.2.0 + version: 0.2.0(eslint@9.21.0(jiti@2.4.2)) eslint-plugin-eslint-comments: specifier: ^3.2.0 version: 3.2.0(eslint@9.21.0(jiti@2.4.2)) @@ -1964,6 +1967,11 @@ packages: peerDependencies: eslint: ^9.13.0 + eslint-plugin-default-import-name@0.2.0: + resolution: {integrity: sha512-oL9rXT3MLsjY6x2dZ51/u7mDi0vsDELzIkS3jvlk2IemMmEKKfLU6Z5HXX7XFMifFQ6kuKK4F+uqN1r1HxZ1Mw==} + peerDependencies: + eslint: ^9.13.0 + eslint-plugin-es-x@7.8.0: resolution: {integrity: sha512-7Ds8+wAAoV3T+LAKeu39Y5BzXCrGKrcISfgKEqTS4BDN8SFEDQd0S43jiQ8vIa3wUKD07qitZdfzlenSi8/0qQ==} engines: {node: ^14.18.0 || >=16.0.0} @@ -3859,6 +3867,9 @@ packages: resolution: {integrity: sha512-3A6sD0WYP7+QrjbfNA2FN3FsOaGGFoekCVgTyypy53gPxhbkCIjtO6YWgdrfM+n/8sI8JeXZOIxsHjMTNxQ4nQ==} engines: {node: ^14.0.0 || >=16.0.0} + scule@1.3.0: + resolution: {integrity: sha512-6FtHJEvt+pVMIB9IBY+IcCJ6Z5f1iQnytgyfKMhDKgmzYG+TeH/wx1y3l27rshSbLiSanrR9ffZDrEsmjlQF2g==} + semver@6.3.1: resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==} hasBin: true @@ -6219,6 +6230,11 @@ snapshots: '@es-joy/jsdoccomment': 0.50.0 eslint: 9.21.0(jiti@2.4.2) + eslint-plugin-default-import-name@0.2.0(eslint@9.21.0(jiti@2.4.2)): + dependencies: + eslint: 9.21.0(jiti@2.4.2) + scule: 1.3.0 + eslint-plugin-es-x@7.8.0(eslint@9.21.0(jiti@2.4.2)): dependencies: '@eslint-community/eslint-utils': 4.4.1(eslint@9.21.0(jiti@2.4.2)) @@ -8525,6 +8541,8 @@ snapshots: refa: 0.12.1 regexp-ast-analysis: 0.7.1 + scule@1.3.0: {} + semver@6.3.1: {} semver@7.7.1: {} diff --git a/src/configs/astro.ts b/src/configs/astro.ts index 4b22f4376a..5e3c9d9de6 100644 --- a/src/configs/astro.ts +++ b/src/configs/astro.ts @@ -5,7 +5,7 @@ import type { OptionsStylistic, TypedFlatConfigItem, } from "../types"; -import {ensurePackages, interopDefault} from "../utils"; +import { ensurePackages, interopDefault } from "../utils"; export async function astro( options: OptionsOverrides & OptionsStylistic & OptionsFiles = {}, @@ -17,7 +17,7 @@ export async function astro( stylistic = false, } = options; - await ensurePackages(["eslint-plugin-astro"]) + await ensurePackages(["eslint-plugin-astro"]); const [pluginAstro, parserAstro, parserTs] = await Promise.all([ interopDefault(import("eslint-plugin-astro")), diff --git a/src/configs/default-import-name.ts b/src/configs/default-import-name.ts new file mode 100644 index 0000000000..b656e2b7af --- /dev/null +++ b/src/configs/default-import-name.ts @@ -0,0 +1,6 @@ +import defaultImportNameConfig from "eslint-plugin-default-import-name/config"; +import type { TypedFlatConfigItem } from "../types"; + +export async function defaultImportName(): Promise> { + return [defaultImportNameConfig()]; +} diff --git a/src/configs/formatters.ts b/src/configs/formatters.ts index 1468689c02..08de5e9163 100644 --- a/src/configs/formatters.ts +++ b/src/configs/formatters.ts @@ -251,35 +251,38 @@ export async function formatters( } if (options.astro) { - configs.push({ - files: [GLOB_ASTRO], - languageOptions: { - parser: parserPlain, - }, - name: "antfu/formatter/astro", - rules: { - "format/prettier": [ - "error", - { - ...prettierOptions, - parser: "astro", - plugins: ["prettier-plugin-astro"], - }, - ], + configs.push( + { + files: [GLOB_ASTRO], + languageOptions: { + parser: parserPlain, + }, + name: "antfu/formatter/astro", + rules: { + "format/prettier": [ + "error", + { + ...prettierOptions, + parser: "astro", + plugins: ["prettier-plugin-astro"], + }, + ], + }, }, - }, { - files: [GLOB_ASTRO, GLOB_ASTRO_TS], - name: "antfu/formatter/astro/disables", - rules: { - "@stylistic/arrow-parens": "off", - "@stylistic/block-spacing": "off", - "@stylistic/comma-dangle": "off", - "@stylistic/indent": "off", - "@stylistic/no-multi-spaces": "off", - "@stylistic/quotes": "off", - "@stylistic/semi": "off", + { + files: [GLOB_ASTRO, GLOB_ASTRO_TS], + name: "antfu/formatter/astro/disables", + rules: { + "@stylistic/arrow-parens": "off", + "@stylistic/block-spacing": "off", + "@stylistic/comma-dangle": "off", + "@stylistic/indent": "off", + "@stylistic/no-multi-spaces": "off", + "@stylistic/quotes": "off", + "@stylistic/semi": "off", + }, }, - }); + ); } if (options.graphql) { diff --git a/src/configs/ignores.ts b/src/configs/ignores.ts index 59f65cca78..c74bb59618 100644 --- a/src/configs/ignores.ts +++ b/src/configs/ignores.ts @@ -6,7 +6,7 @@ export async function ignores(): Promise> { { ignores: GLOB_EXCLUDE, // Awaits https://github.com/humanwhocodes/config-array/pull/131 - name: 'antfu/ignores', + name: "antfu/ignores", }, ]; } diff --git a/src/configs/react.ts b/src/configs/react.ts index 59fee7e83c..9b05bf735f 100644 --- a/src/configs/react.ts +++ b/src/configs/react.ts @@ -112,13 +112,13 @@ export async function react( allowExportNames: [ ...(isUsingNext ? [ - 'dynamic', - 'dynamicParams', - 'revalidate', - 'fetchCache', - 'runtime', - 'preferredRegion', - 'maxDuration', + "dynamic", + "dynamicParams", + "revalidate", + "fetchCache", + "runtime", + "preferredRegion", + "maxDuration", "config", "generateStaticParams", "metadata", diff --git a/src/configs/tsdoc.ts b/src/configs/tsdoc.ts index f317aa2357..df5aaab0d6 100644 --- a/src/configs/tsdoc.ts +++ b/src/configs/tsdoc.ts @@ -1,6 +1,10 @@ import { compat } from "../compat"; -import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, TypedFlatConfigItem } from "../types"; - +import type { + OptionsComponentExts, + OptionsFiles, + OptionsOverrides, + TypedFlatConfigItem, +} from "../types"; export async function tsdoc( options: OptionsFiles & OptionsComponentExts & OptionsOverrides = {}, diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index 4945d8ba45..23c112f086 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,7 +1,8 @@ import expectType from "eslint-plugin-expect-type/configs/recommended"; import tseslint from "typescript-eslint"; import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from "../globs"; -import { pluginAntfu, pluginSortDestructureKeysTypescript } from "../plugins"; +import sortDestructureKeysTypescriptConfig from "eslint-plugin-sort-destructure-keys-typescript/config"; +import { pluginAntfu } from "../plugins"; import type { OptionsComponentExts, OptionsFiles, @@ -103,7 +104,6 @@ export async function typescript( name: "antfu/typescript/setup", plugins: { antfu: pluginAntfu, - "sort-destructure-keys-typescript": pluginSortDestructureKeysTypescript, // "@typescript-eslint": pluginTs as any, }, }, @@ -172,6 +172,7 @@ export async function typescript( }, ...(isTypeAware ? [ + sortDestructureKeysTypescriptConfig(), { files: filesTypeAware, ignores: ignoresTypeAware, diff --git a/src/configs/vue.ts b/src/configs/vue.ts index a6dade04c7..665dd8b70f 100644 --- a/src/configs/vue.ts +++ b/src/configs/vue.ts @@ -24,7 +24,7 @@ export async function vue( vueVersion = 3, } = options; - const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {}; + const sfcBlocks = options.sfcBlocks === true ? {} : (options.sfcBlocks ?? {}); const { indent = 2 } = typeof stylistic === "boolean" ? {} : stylistic; diff --git a/src/factory.ts b/src/factory.ts index 840d8d81d8..f77411501c 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -31,6 +31,7 @@ import { vue, yaml, } from "./configs"; +import { defaultImportName } from "./configs/default-import-name"; import { formatters } from "./configs/formatters"; import { i18n } from "./configs/i18n"; import { prettier } from "./configs/prettier"; @@ -183,6 +184,7 @@ export function nirtamir2( stylistic: stylisticOptions, }), unicorn(), + defaultImportName(), command(), // Optional plugins (installed but not enabled by default) diff --git a/src/plugins.ts b/src/plugins.ts index f1f1520041..72d749e625 100644 --- a/src/plugins.ts +++ b/src/plugins.ts @@ -2,7 +2,6 @@ // @ts-nocheck export { default as pluginAntfu } from "eslint-plugin-antfu"; -export { default as pluginSortDestructureKeysTypescript } from "eslint-plugin-sort-destructure-keys-typescript"; export { default as pluginComments } from "eslint-plugin-eslint-comments"; export * as pluginImport from "eslint-plugin-import-x"; export { default as pluginNode } from "eslint-plugin-n"; diff --git a/src/types.ts b/src/types.ts index 7a0fb324fe..bb4940e539 100644 --- a/src/types.ts +++ b/src/types.ts @@ -164,9 +164,9 @@ export interface OptionsStylistic { } export type StylisticConfig = Pick< - StylisticCustomizeOptions, - "indent" | "quotes" | "jsx" | "semi" - > + StylisticCustomizeOptions, + "indent" | "quotes" | "jsx" | "semi" +>; export interface OptionsOverrides { overrides?: TypedFlatConfigItem["rules"];