diff --git a/.github/renovate.json5 b/.github/renovate.json5 index f0d9e58a..255bb080 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,3 +1,3 @@ { - "extends": ["github>coderwyd/renovate-config"] + extends: ['github>coderwyd/renovate-config'], } diff --git a/.vscode/settings.json b/.vscode/settings.json index b2327aa6..b92ae843 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,39 +6,6 @@ "eslint.options": { "flags": ["unstable_ts_config"] }, - "editor.formatOnSave": false, - "eslint.validate": [ - "html", - "css", - "less", - "scss", - "json", - "jsonc", - "yaml", - "yml", - "markdown", - "toml", - "gql", - "graphql" - ], - // "eslint.runtime": "node", - "eslint.rules.customizations": [ - { "rule": "style/*", "severity": "off", "fixable": true }, - { "rule": "*-indent", "severity": "off", "fixable": true }, - { "rule": "*-spacing", "severity": "off", "fixable": true }, - { "rule": "*-spaces", "severity": "off", "fixable": true }, - { "rule": "*-order", "severity": "off", "fixable": true }, - { "rule": "*-dangle", "severity": "off", "fixable": true }, - { "rule": "*-newline", "severity": "off", "fixable": true }, - { "rule": "*quotes", "severity": "off", "fixable": true }, - { "rule": "*semi", "severity": "off", "fixable": true } - ], - "prettier.enable": false, - "cSpell.words": [ - "antfu", - "astro", - "coderwyd", - "rspack", - "unocss" - ] + "editor.formatOnSave": true, + "cSpell.words": ["antfu", "astro", "coderwyd", "rspack", "unocss"] } diff --git a/README.md b/README.md index 7df1f376..87add100 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ - ✨ Support Vue, React, Svelte. - 🎯 Designed to work with TypeScript, Vue out-of-box - 🏆 Reasonable defaults, best practices, only one-line of config -- 🎨 Use ESlint to format HTML, CSS, LESS, SCSS, YAML, TOML, Markdown, JSON, JSONC. ## Usage @@ -59,43 +58,14 @@ Add the following settings to your `.vscode/settings.json`: ```jsonc { - // Disable the default formatter, use eslint instead - "prettier.enable": false, + "prettier.enable": true, "editor.formatOnSave": false, // Auto fix "editor.codeActionsOnSave": { "source.fixAll": "explicit", - "source.organizeImports": "never" + "source.organizeImports": "never", }, - - // Silent the stylistic rules in you IDE, but still auto fix them - "eslint.rules.customizations": [ - { "rule": "style/*", "severity": "off", "fixable": true }, - { "rule": "format/*", "severity": "off", "fixable": true }, - { "rule": "*-indent", "severity": "off", "fixable": true }, - { "rule": "*-spacing", "severity": "off", "fixable": true }, - { "rule": "*-spaces", "severity": "off", "fixable": true }, - { "rule": "*-order", "severity": "off", "fixable": true }, - { "rule": "*-dangle", "severity": "off", "fixable": true }, - { "rule": "*-newline", "severity": "off", "fixable": true }, - { "rule": "*quotes", "severity": "off", "fixable": true }, - { "rule": "*semi", "severity": "off", "fixable": true } - ], - - // Enable eslint for all supported languages - "eslint.validate": [ - "html", - "css", - "less", - "scss", - "json", - "jsonc", - "yaml", - "yml", - "markdown", - "toml" - ] } ``` @@ -157,15 +127,6 @@ interface OptionsConfig extends OptionsComponentExts { */ typescript?: boolean | OptionsTypescript - /** - * Enable JSX related rules. - * - * Currently only stylistic rules are included. - * - * @default true - */ - jsx?: boolean - /** * Enable test support. * @@ -226,14 +187,6 @@ interface OptionsConfig extends OptionsComponentExts { */ unocss?: boolean | OptionsUnoCSS - /** - * Enable stylistic rules. - * - * @see https://eslint.style/ - * @default true - */ - stylistic?: boolean | (StylisticConfig & OptionsOverrides) - /** * Enable regexp rules. * @@ -242,23 +195,6 @@ interface OptionsConfig extends OptionsComponentExts { */ regexp?: boolean | (OptionsRegExp & OptionsOverrides) - /** - * Use external formatters to format files. - * - * @default - * { - * "html": true, - * "css": true, - * "graphql": false, - * "markdown": false - * "yaml": false - * "toml": false - * } - * - * When set to `true`, it will enable all formatters. - */ - formatter?: boolean | OptionsFormatters - /** * Control to disable some rules in editors. * @default auto-detect based on the process.env diff --git a/eslint.config.ts b/eslint.config.ts index 3f005b53..517d7961 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -1,6 +1,3 @@ -// @ts-expect-error missing types -import styleMigrate from '@stylistic/eslint-plugin-migrate' - import { defineConfig } from './src' export default defineConfig( @@ -8,7 +5,6 @@ export default defineConfig( vue: true, react: false, typescript: true, - formatter: true, }, { files: ['src/**/*.ts'], @@ -16,13 +12,4 @@ export default defineConfig( 'perfectionist/sort-objects': 'error', }, }, - { - files: ['src/configs/*.ts'], - plugins: { - 'style-migrate': styleMigrate, - }, - rules: { - 'style-migrate/migrate': ['error', { namespaceTo: 'style' }], - }, - }, ) diff --git a/package.json b/package.json index df44e027..24219462 100644 --- a/package.json +++ b/package.json @@ -83,35 +83,33 @@ "dependencies": { "@antfu/install-pkg": "^0.4.1", "@eslint-community/eslint-plugin-eslint-comments": "^4.4.0", - "@stylistic/eslint-plugin": "^2.8.0", "@toml-tools/parser": "^1.0.0", "@typescript-eslint/eslint-plugin": "^8.7.0", "@typescript-eslint/parser": "^8.7.0", "@vitest/eslint-plugin": "^1.1.4", "eslint-config-flat-gitignore": "^0.3.0", - "eslint-merge-processors": "^0.1.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-antfu": "^2.7.0", "eslint-plugin-command": "^0.2.5", "eslint-plugin-eslint-comments": "^3.2.0", - "eslint-plugin-format": "^0.1.2", "eslint-plugin-import-x": "^4.3.0", "eslint-plugin-jsdoc": "^50.2.4", "eslint-plugin-jsonc": "^2.16.0", "eslint-plugin-n": "^17.10.3", "eslint-plugin-no-only-tests": "^3.3.0", "eslint-plugin-perfectionist": "^3.7.0", + "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-regexp": "^2.6.0", "eslint-plugin-unicorn": "^55.0.0", "eslint-plugin-unused-imports": "^4.1.4", "eslint-plugin-vue": "^9.28.0", - "eslint-processor-vue-blocks": "^0.1.2", "eslint-typegen": "^0.3.2", "globals": "^15.9.0", "jsonc-eslint-parser": "^2.4.0", "local-pkg": "^0.5.0", "parse-gitignore": "^2.0.0", "picocolors": "^1.1.0", - "prettier-plugin-toml": "^2.0.1", + "prettier": "^3.3.3", "prompts": "^2.4.2", "vue-eslint-parser": "^9.4.3", "yargs": "^17.7.2" @@ -120,7 +118,7 @@ "@antfu/ni": "^0.23.0", "@eslint-react/eslint-plugin": "^1.14.2", "@eslint/config-inspector": "^0.5.4", - "@stylistic/eslint-plugin-migrate": "^2.8.0", + "@types/eslint-config-prettier": "^6.11.3", "@types/fs-extra": "^11.0.4", "@types/node": "^22.6.1", "@types/prompts": "^2.4.9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d87efef7..ee236284 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,9 +14,6 @@ importers: '@eslint-community/eslint-plugin-eslint-comments': specifier: ^4.4.0 version: 4.4.0(eslint@9.11.1(jiti@1.21.6)) - '@stylistic/eslint-plugin': - specifier: ^2.8.0 - version: 2.8.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) '@toml-tools/parser': specifier: ^1.0.0 version: 1.0.0 @@ -32,9 +29,9 @@ importers: eslint-config-flat-gitignore: specifier: ^0.3.0 version: 0.3.0(eslint@9.11.1(jiti@1.21.6)) - eslint-merge-processors: - specifier: ^0.1.0 - version: 0.1.0(eslint@9.11.1(jiti@1.21.6)) + eslint-config-prettier: + specifier: ^9.1.0 + version: 9.1.0(eslint@9.11.1(jiti@1.21.6)) eslint-plugin-antfu: specifier: ^2.7.0 version: 2.7.0(eslint@9.11.1(jiti@1.21.6)) @@ -44,9 +41,6 @@ importers: eslint-plugin-eslint-comments: specifier: ^3.2.0 version: 3.2.0(eslint@9.11.1(jiti@1.21.6)) - eslint-plugin-format: - specifier: ^0.1.2 - version: 0.1.2(eslint@9.11.1(jiti@1.21.6)) eslint-plugin-import-x: specifier: ^4.3.0 version: 4.3.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) @@ -65,6 +59,9 @@ importers: eslint-plugin-perfectionist: specifier: ^3.7.0 version: 3.7.0(eslint@9.11.1(jiti@1.21.6))(svelte-eslint-parser@0.41.1(svelte@4.2.19))(svelte@4.2.19)(typescript@5.6.2)(vue-eslint-parser@9.4.3(eslint@9.11.1(jiti@1.21.6))) + eslint-plugin-prettier: + specifier: ^5.2.1 + version: 5.2.1(eslint-config-prettier@9.1.0(eslint@9.11.1(jiti@1.21.6)))(eslint@9.11.1(jiti@1.21.6))(prettier@3.3.3) eslint-plugin-regexp: specifier: ^2.6.0 version: 2.6.0(eslint@9.11.1(jiti@1.21.6)) @@ -77,9 +74,6 @@ importers: eslint-plugin-vue: specifier: ^9.28.0 version: 9.28.0(eslint@9.11.1(jiti@1.21.6)) - eslint-processor-vue-blocks: - specifier: ^0.1.2 - version: 0.1.2(@vue/compiler-sfc@3.4.27)(eslint@9.11.1(jiti@1.21.6)) eslint-typegen: specifier: ^0.3.2 version: 0.3.2(eslint@9.11.1(jiti@1.21.6)) @@ -98,9 +92,9 @@ importers: picocolors: specifier: ^1.1.0 version: 1.1.0 - prettier-plugin-toml: - specifier: ^2.0.1 - version: 2.0.1(prettier@3.3.2) + prettier: + specifier: ^3.3.3 + version: 3.3.3 prompts: specifier: ^2.4.2 version: 2.4.2 @@ -120,9 +114,9 @@ importers: '@eslint/config-inspector': specifier: ^0.5.4 version: 0.5.4(eslint@9.11.1(jiti@1.21.6)) - '@stylistic/eslint-plugin-migrate': - specifier: ^2.8.0 - version: 2.8.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) + '@types/eslint-config-prettier': + specifier: ^6.11.3 + version: 6.11.3 '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4 @@ -155,7 +149,7 @@ importers: version: 2.44.0(eslint@9.11.1(jiti@1.21.6))(svelte@4.2.19) eslint-plugin-tailwindcss: specifier: ^3.17.4 - version: 3.17.4(tailwindcss@3.4.3) + version: 3.17.4(tailwindcss@3.4.13) execa: specifier: ^9.4.0 version: 9.4.0 @@ -221,10 +215,6 @@ packages: resolution: {integrity: sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==} engines: {node: '>=6.9.0'} - '@babel/helper-string-parser@7.24.1': - resolution: {integrity: sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==} - engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.24.5': resolution: {integrity: sha512-3q93SSKX2TWCG30M2G2kwaKeTYgEUp5Snjuj8qm729SObL6nbtUldAi37qbxkD5gg3xnBio+f9nqpSepGZMvxA==} engines: {node: '>=6.9.0'} @@ -233,15 +223,6 @@ packages: resolution: {integrity: sha512-8lLmua6AVh/8SLJRRVD6V8p73Hir9w5mJrhE+IPpILG31KKlI9iz5zmBYKcWPS59qSfgP9RaSBQSHHE81WKuEw==} engines: {node: '>=6.9.0'} - '@babel/parser@7.24.5': - resolution: {integrity: sha512-EOv5IK8arwh3LI47dz1b0tKUb/1uhHAnHJOrjgtQMIpu1uXd9mlFrJg9IUgGUgZ41Ch0K8REPTYpO7B76b4vJg==} - engines: {node: '>=6.0.0'} - hasBin: true - - '@babel/types@7.24.5': - resolution: {integrity: sha512-6mQNsaLeXTw0nxYUYu+NSa4Hx4BlF1x1x8/PMFbiR+GBSr+2DkECc69b8hgy2frEodNcvPffeH8YfWd3LI6jhQ==} - engines: {node: '>=6.9.0'} - '@chevrotain/cst-dts-gen@11.0.3': resolution: {integrity: sha512-BvIKpRLeS/8UbfxXxgC33xOumsacaeCKAjAeLyOn7Pcp95HiRbrpl14S+9vaZLolnbssPIUuiUd8IvgkRyt6NQ==} @@ -257,15 +238,6 @@ packages: '@chevrotain/utils@11.0.3': resolution: {integrity: sha512-YslZMgtJUyuMbZ+aKvfF3x1f5liK4mWNxghFRv7jqRR9C3R3fAOGTTKvxXDa2Y1s9zSbcpuO0cAxDYsc9SrXoQ==} - '@dprint/formatter@0.3.0': - resolution: {integrity: sha512-N9fxCxbaBOrDkteSOzaCqwWjso5iAe+WJPsHC021JfHNj2ThInPNEF13ORDKta3llq5D1TlclODCvOvipH7bWQ==} - - '@dprint/markdown@0.17.1': - resolution: {integrity: sha512-Mk9C9tHHSScB3JOUd2PEP3keWnJZ8Kqcd99qaVhknzhxgZF/gGTx0CMyd+lpsIV+Moe+OtbRnqAjp+hKVtT1zQ==} - - '@dprint/toml@0.6.2': - resolution: {integrity: sha512-Mk5unEANsL/L+WHYU3NpDXt1ARU5bNU5k5OZELxaJodDycKG6RoRnSlZXpW6+7UN2PSnETAFVUdKrh937ZwtHA==} - '@es-joy/jsdoccomment@0.48.0': resolution: {integrity: sha512-G6QUWIcC+KvSwXNsJyDTHvqUdNoAVJPPgkc3+Uk4WBKqZvoXhlvazOgm9aL0HwihJLQf0l+tOE2UFzXBqCqgDw==} engines: {node: '>=16'} @@ -603,9 +575,6 @@ packages: '@eslint-react/var@1.14.2': resolution: {integrity: sha512-OOxwTPcWoNJbpaWnULpq+QJzsdZveU/QCHZ6Lb1oNIdVPBc6nCKz3PH97hqYFpk3q+gnnNx2q6qhNIAfeu/8Ug==} - '@eslint-stylistic/metadata@2.8.0': - resolution: {integrity: sha512-/AvE8Jdp+t6T9WjMmPvbKKGNr+pzx7gkZskCOuU9/auO4TaSU1ukdDN4rE6kNXjNJqeRK8HaLbJkNLeGYf0cjw==} - '@eslint/compat@1.1.1': resolution: {integrity: sha512-lpHyRyplhGPL5mGEh6M9O5nnKk0Gz4bFI+Zu6tKlPpDUN7XshWvH9C/px4UVm87IAANE0W81CEsNGbS1KlzXpA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -800,28 +769,15 @@ packages: resolution: {integrity: sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==} engines: {node: '>=18'} - '@stylistic/eslint-plugin-migrate@2.8.0': - resolution: {integrity: sha512-XPxnm/ezY+ZbaCIXkUnpGsRe6LDAogj21UugrsyR03ZL50TGnsWWOAzL5rca4meML7Hgs42LexLVdPytJ5Bphg==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - - '@stylistic/eslint-plugin@2.8.0': - resolution: {integrity: sha512-Ufvk7hP+bf+pD35R/QfunF793XlSRIC7USr3/EdgduK9j13i2JjmsM0LUz3/foS+jDYp2fzyWZA9N44CPur0Ow==} - engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} - peerDependencies: - eslint: '>=8.40.0' - - '@taplo/core@0.1.1': - resolution: {integrity: sha512-BG/zLGf5wiNXGEVPvUAAX/4ilB3PwDUY2o0MV0y47mZbDZ9ad9UK/cIQsILat3bqbPJsALVbU6k3cskNZ3vAQg==} - - '@taplo/lib@0.4.0-alpha.2': - resolution: {integrity: sha512-DV/Re3DPVY+BhBtLZ3dmP4mP6YMLSsgq9qGLXwOV38lvNF/fBlgvQswzlXmzCEefL/3q2eMoefZpOI/+GLuCNA==} - '@toml-tools/lexer@1.0.0': resolution: {integrity: sha512-rVoOC9FibF2CICwCBWQnYcjAEOmLCJExer178K2AsY0Nk9FjJNVoVJuR5UAtuq42BZOajvH+ainf6Gj2GpCnXQ==} '@toml-tools/parser@1.0.0': resolution: {integrity: sha512-j8cd3A3ccLHppGoWI69urbiVJslrpwI6sZ61ySDUPxM/FTkQWRx/JkkF8aipnl0Ds0feWXyjyvmWzn70mIohYg==} + '@types/eslint-config-prettier@6.11.3': + resolution: {integrity: sha512-3wXCiM8croUnhg9LdtZUJQwNcQYGWxxdOWDjPe1ykCqJFPVpzAKfs/2dgSoCtAvdPeaponcWPI7mPcGGp9dkKQ==} + '@types/estree@1.0.5': resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} @@ -1004,21 +960,6 @@ packages: peerDependencies: '@eslint/config-array': '>=0.16.0' - '@vue/compiler-core@3.4.27': - resolution: {integrity: sha512-E+RyqY24KnyDXsCuQrI+mlcdW3ALND6U7Gqa/+bVwbcpcR3BRRIckFoz7Qyd4TTlnugtwuI7YgjbvsLmxb+yvg==} - - '@vue/compiler-dom@3.4.27': - resolution: {integrity: sha512-kUTvochG/oVgE1w5ViSr3KUBh9X7CWirebA3bezTbB5ZKBQZwR2Mwj9uoSKRMFcz4gSMzzLXBPD6KpCLb9nvWw==} - - '@vue/compiler-sfc@3.4.27': - resolution: {integrity: sha512-nDwntUEADssW8e0rrmE0+OrONwmRlegDA1pD6QhVeXxjIytV03yDqTey9SBDiALsvAd5U4ZrEKbMyVXhX6mCGA==} - - '@vue/compiler-ssr@3.4.27': - resolution: {integrity: sha512-CVRzSJIltzMG5FcidsW0jKNQnNRYC8bT21VegyMMtHmhW3UOI7knmUehzswXLrExDLE6lQCZdrhD4ogI7c+vuw==} - - '@vue/shared@3.4.27': - resolution: {integrity: sha512-DL3NmY2OFlqmYYrzp39yi3LDkKxa5vZVwxWdQ3rG0ekuWscHraeIbnI8t+aZK7qhYqEqWKTUdijadunb9pnrgA==} - acorn-jsx@5.3.2: resolution: {integrity: sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==} peerDependencies: @@ -1355,10 +1296,6 @@ packages: resolution: {integrity: sha512-dwDPwZL0dmye8Txp2gzFmA6sxALaSvdRDjPH0viLcKrtlOL3tw62nWWweVD1SdILDTJrbrL6tdWVN58Wo6U3eA==} engines: {node: '>=10.13.0'} - entities@4.5.0: - resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} - engines: {node: '>=0.12'} - environment@1.1.0: resolution: {integrity: sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==} engines: {node: '>=18'} @@ -1408,22 +1345,15 @@ packages: peerDependencies: eslint: ^9.5.0 - eslint-formatting-reporter@0.0.0: - resolution: {integrity: sha512-k9RdyTqxqN/wNYVaTk/ds5B5rA8lgoAmvceYN7bcZMBwU7TuXx5ntewJv81eF3pIL/CiJE+pJZm36llG8yhyyw==} + eslint-config-prettier@9.1.0: + resolution: {integrity: sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==} + hasBin: true peerDependencies: - eslint: '>=8.40.0' + eslint: '>=7.0.0' eslint-import-resolver-node@0.3.9: resolution: {integrity: sha512-WFj2isz22JahUv+B788TlO3N6zL3nNJGU8CcZbPZvVEkBPaJdCV4vy5wyghty5ROFbCRnm132v8BScu5/1BQ8g==} - eslint-merge-processors@0.1.0: - resolution: {integrity: sha512-IvRXXtEajLeyssvW4wJcZ2etxkR9mUf4zpNwgI+m/Uac9RfXHskuJefkHUcawVzePnd6xp24enp5jfgdHzjRdQ==} - peerDependencies: - eslint: '*' - - eslint-parser-plain@0.1.0: - resolution: {integrity: sha512-oOeA6FWU0UJT/Rxc3XF5Cq0nbIZbylm7j8+plqq0CZoE6m4u32OXJrR+9iy4srGMmF6v6pmgvP1zPxSRIGh3sg==} - eslint-plugin-antfu@2.7.0: resolution: {integrity: sha512-gZM3jq3ouqaoHmUNszb1Zo2Ux7RckSvkGksjLWz9ipBYGSv1EwwBETN6AdiUXn+RpVHXTbEMPAPlXJazcA6+iA==} peerDependencies: @@ -1446,11 +1376,6 @@ packages: peerDependencies: eslint: '>=4.19.1' - eslint-plugin-format@0.1.2: - resolution: {integrity: sha512-ZrcO3aiumgJ6ENAv65IWkPjtW77ML/5mp0YrRK0jdvvaZJb+4kKWbaQTMr/XbJo6CtELRmCApAziEKh7L2NbdQ==} - peerDependencies: - eslint: ^8.40.0 || ^9.0.0 - eslint-plugin-import-x@4.3.0: resolution: {integrity: sha512-PxGzP7gAjF2DLeRnQtbYkkgZDg1intFyYr/XS1LgTYXUDrSXMHGkXx8++6i2eDv2jMs0jfeO6G6ykyeWxiFX7w==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -1498,6 +1423,20 @@ packages: vue-eslint-parser: optional: true + eslint-plugin-prettier@5.2.1: + resolution: {integrity: sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==} + engines: {node: ^14.18.0 || >=16.0.0} + peerDependencies: + '@types/eslint': '>=8.0.0' + eslint: '>=8.0.0' + eslint-config-prettier: '*' + prettier: '>=3.0.0' + peerDependenciesMeta: + '@types/eslint': + optional: true + eslint-config-prettier: + optional: true + eslint-plugin-react-debug@1.14.2: resolution: {integrity: sha512-5DlSAx4dHhqbGpPMOyEu7lhdWExwxI1e/3MeKSJBfigQamdA0dIZi/K0ZkeVqbSS8ItU+G/Ba1ek6vYCtadNvA==} engines: {bun: '>=1.0.15', node: '>=18.18.0'} @@ -1612,12 +1551,6 @@ packages: peerDependencies: eslint: ^6.2.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 - eslint-processor-vue-blocks@0.1.2: - resolution: {integrity: sha512-PfpJ4uKHnqeL/fXUnzYkOax3aIenlwewXRX8jFinA1a2yCFnLgMuiH3xvCgvHHUlV2xJWQHbCTdiJWGwb3NqpQ==} - peerDependencies: - '@vue/compiler-sfc': ^3.3.0 - eslint: ^8.50.0 || ^9.0.0 - eslint-scope@7.2.2: resolution: {integrity: sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1673,9 +1606,6 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} - estree-walker@2.0.2: - resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} - estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} @@ -2482,8 +2412,8 @@ packages: yaml: optional: true - postcss-nested@6.0.1: - resolution: {integrity: sha512-mEp4xPMi5bSWiMbsgoPfcP74lsWLHkQbZc3sY+jWYd65CUwXrUaTp0fmNpa01ZcETKlIgUdFN/MpS2xZtqL9dQ==} + postcss-nested@6.2.0: + resolution: {integrity: sha512-HQbt28KulC5AJzG+cZtj9kvKB93CFCdLvog1WFLf1D+xmMvPGlBstkpTEZfK5+AN9hfJocyBFCNiqyS48bpgzQ==} engines: {node: '>=12.0'} peerDependencies: postcss: ^8.2.14 @@ -2504,13 +2434,13 @@ packages: resolution: {integrity: sha512-UMz42UD0UY0EApS0ZL9o1XnLhSTtvvvLe5Dc2H2O56fvRZi+KulDyf5ctDhhtYJBGKStV2FL1fy6253cmLgqVQ==} engines: {node: '>=4'} + postcss-selector-parser@6.1.2: + resolution: {integrity: sha512-Q8qQfPiZ+THO/3ZrOrO0cJJKfpYCagtMUkXbnEfmgUjwXg6z/WBeOyS9APBBPCTSiDV+s4SwQGu8yFsiMRIudg==} + engines: {node: '>=4'} + postcss-value-parser@4.2.0: resolution: {integrity: sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==} - postcss@8.4.38: - resolution: {integrity: sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==} - engines: {node: ^10 || ^12 || >=14} - postcss@8.4.39: resolution: {integrity: sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==} engines: {node: ^10 || ^12 || >=14} @@ -2523,14 +2453,8 @@ packages: resolution: {integrity: sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==} engines: {node: '>=6.0.0'} - prettier-plugin-toml@2.0.1: - resolution: {integrity: sha512-99z1YOkViECHtXQjGIigd3talI/ybUI1zB3yniAwUrlWBXupNXThB1hM6bwSMUEj2/+tomTlMtT98F5t4s8IWA==} - engines: {node: '>=16.0.0'} - peerDependencies: - prettier: ^3.0.3 - - prettier@3.3.2: - resolution: {integrity: sha512-rAVeHYMcv8ATV5d508CFdn+8/pHPpXeIid1DdrPwXnaAdH7cqjVbpJaT5eq4yRAFU/lsbwYwSF/n5iNrdJHPQA==} + prettier@3.3.3: + resolution: {integrity: sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==} engines: {node: '>=14'} hasBin: true @@ -2795,16 +2719,12 @@ packages: resolution: {integrity: sha512-Vhf+bUa//YSTYKseDiiEuQmhGCoIF3CVBhunm3r/DQnYiGT4JssmnKQc44BIyOZRK2pKjXXAgbhfmbeoC9CJpA==} engines: {node: '>=12.20'} - synckit@0.9.0: - resolution: {integrity: sha512-7RnqIMq572L8PeEzKeBINYEJDDxpcH8JEgLwUqBd3TkofhFRbkq4QLR0u+36avGAhCRbk2nnmjcW9SE531hPDg==} - engines: {node: ^14.18.0 || >=16.0.0} - synckit@0.9.1: resolution: {integrity: sha512-7gr8p9TQP6RAHusBOSLs46F4564ZrjV8xFmw5zCmgmhGUcw2hxsShhJ6CEiHQMgPDwAQ1fWHPM0ypc4RMAig4A==} engines: {node: ^14.18.0 || >=16.0.0} - tailwindcss@3.4.3: - resolution: {integrity: sha512-U7sxQk/n397Bmx4JHbJx/iSOOv5G+II3f1kpLpY2QeUv5DcPdcTsYLlusZfq1NthHS1c1cZoyFmmkex1rzke0A==} + tailwindcss@3.4.13: + resolution: {integrity: sha512-KqjHOJKogOUt5Bs752ykCeiwvi0fKVkr5oqsFNt/8px/tA8scFPIlkygsf6jXrfCqGHz7VflA6+yytWuM+XhFw==} engines: {node: '>=14.0.0'} hasBin: true @@ -2833,10 +2753,6 @@ packages: resolution: {integrity: sha512-NbBoFBpqfcgd1tCiO8Lkfdk+xrA7mlLR9zgvZcZWQQwU63XAfUePyd6wZBaU93Hqw347lHnwFzttAkemHzzz4g==} engines: {node: '>=12.0.0'} - to-fast-properties@2.0.0: - resolution: {integrity: sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==} - engines: {node: '>=4'} - to-regex-range@5.0.1: resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} engines: {node: '>=8.0'} @@ -3073,8 +2989,6 @@ snapshots: '@babel/highlight': 7.24.5 picocolors: 1.1.0 - '@babel/helper-string-parser@7.24.1': {} - '@babel/helper-validator-identifier@7.24.5': {} '@babel/highlight@7.24.5': @@ -3084,16 +2998,6 @@ snapshots: js-tokens: 4.0.0 picocolors: 1.1.0 - '@babel/parser@7.24.5': - dependencies: - '@babel/types': 7.24.5 - - '@babel/types@7.24.5': - dependencies: - '@babel/helper-string-parser': 7.24.1 - '@babel/helper-validator-identifier': 7.24.5 - to-fast-properties: 2.0.0 - '@chevrotain/cst-dts-gen@11.0.3': dependencies: '@chevrotain/gast': 11.0.3 @@ -3111,12 +3015,6 @@ snapshots: '@chevrotain/utils@11.0.3': {} - '@dprint/formatter@0.3.0': {} - - '@dprint/markdown@0.17.1': {} - - '@dprint/toml@0.6.2': {} - '@es-joy/jsdoccomment@0.48.0': dependencies: comment-parser: 1.4.1 @@ -3386,8 +3284,6 @@ snapshots: - supports-color - typescript - '@eslint-stylistic/metadata@2.8.0': {} - '@eslint/compat@1.1.1': {} '@eslint/config-array@0.17.1': @@ -3575,33 +3471,6 @@ snapshots: '@sindresorhus/merge-streams@4.0.0': {} - '@stylistic/eslint-plugin-migrate@2.8.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2)': - dependencies: - '@eslint-stylistic/metadata': 2.8.0 - '@typescript-eslint/utils': 8.5.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) - transitivePeerDependencies: - - eslint - - supports-color - - typescript - - '@stylistic/eslint-plugin@2.8.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2)': - dependencies: - '@typescript-eslint/utils': 8.5.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) - eslint: 9.11.1(jiti@1.21.6) - eslint-visitor-keys: 4.0.0 - espree: 10.1.0 - estraverse: 5.3.0 - picomatch: 4.0.2 - transitivePeerDependencies: - - supports-color - - typescript - - '@taplo/core@0.1.1': {} - - '@taplo/lib@0.4.0-alpha.2': - dependencies: - '@taplo/core': 0.1.1 - '@toml-tools/lexer@1.0.0': dependencies: chevrotain: 11.0.3 @@ -3611,6 +3480,8 @@ snapshots: '@toml-tools/lexer': 1.0.0 chevrotain: 11.0.3 + '@types/eslint-config-prettier@6.11.3': {} + '@types/estree@1.0.5': {} '@types/estree@1.0.6': {} @@ -3845,38 +3716,6 @@ snapshots: '@eslint/config-array': 0.17.1 '@nodelib/fs.walk': 2.0.0 - '@vue/compiler-core@3.4.27': - dependencies: - '@babel/parser': 7.24.5 - '@vue/shared': 3.4.27 - entities: 4.5.0 - estree-walker: 2.0.2 - source-map-js: 1.2.0 - - '@vue/compiler-dom@3.4.27': - dependencies: - '@vue/compiler-core': 3.4.27 - '@vue/shared': 3.4.27 - - '@vue/compiler-sfc@3.4.27': - dependencies: - '@babel/parser': 7.24.5 - '@vue/compiler-core': 3.4.27 - '@vue/compiler-dom': 3.4.27 - '@vue/compiler-ssr': 3.4.27 - '@vue/shared': 3.4.27 - estree-walker: 2.0.2 - magic-string: 0.30.11 - postcss: 8.4.39 - source-map-js: 1.2.0 - - '@vue/compiler-ssr@3.4.27': - dependencies: - '@vue/compiler-dom': 3.4.27 - '@vue/shared': 3.4.27 - - '@vue/shared@3.4.27': {} - acorn-jsx@5.3.2(acorn@8.12.1): dependencies: acorn: 8.12.1 @@ -4184,8 +4023,6 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.2.1 - entities@4.5.0: {} - environment@1.1.0: {} error-ex@1.3.2: @@ -4269,10 +4106,9 @@ snapshots: eslint: 9.11.1(jiti@1.21.6) find-up-simple: 1.0.0 - eslint-formatting-reporter@0.0.0(eslint@9.11.1(jiti@1.21.6)): + eslint-config-prettier@9.1.0(eslint@9.11.1(jiti@1.21.6)): dependencies: eslint: 9.11.1(jiti@1.21.6) - prettier-linter-helpers: 1.0.0 eslint-import-resolver-node@0.3.9: dependencies: @@ -4282,12 +4118,6 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-merge-processors@0.1.0(eslint@9.11.1(jiti@1.21.6)): - dependencies: - eslint: 9.11.1(jiti@1.21.6) - - eslint-parser-plain@0.1.0: {} - eslint-plugin-antfu@2.7.0(eslint@9.11.1(jiti@1.21.6)): dependencies: '@antfu/utils': 0.7.10 @@ -4311,17 +4141,6 @@ snapshots: eslint: 9.11.1(jiti@1.21.6) ignore: 5.3.1 - eslint-plugin-format@0.1.2(eslint@9.11.1(jiti@1.21.6)): - dependencies: - '@dprint/formatter': 0.3.0 - '@dprint/markdown': 0.17.1 - '@dprint/toml': 0.6.2 - eslint: 9.11.1(jiti@1.21.6) - eslint-formatting-reporter: 0.0.0(eslint@9.11.1(jiti@1.21.6)) - eslint-parser-plain: 0.1.0 - prettier: 3.3.2 - synckit: 0.9.0 - eslint-plugin-import-x@4.3.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2): dependencies: '@typescript-eslint/utils': 8.6.0(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) @@ -4396,6 +4215,15 @@ snapshots: - supports-color - typescript + eslint-plugin-prettier@5.2.1(eslint-config-prettier@9.1.0(eslint@9.11.1(jiti@1.21.6)))(eslint@9.11.1(jiti@1.21.6))(prettier@3.3.3): + dependencies: + eslint: 9.11.1(jiti@1.21.6) + prettier: 3.3.3 + prettier-linter-helpers: 1.0.0 + synckit: 0.9.1 + optionalDependencies: + eslint-config-prettier: 9.1.0(eslint@9.11.1(jiti@1.21.6)) + eslint-plugin-react-debug@1.14.2(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2): dependencies: '@eslint-react/ast': 1.14.2(eslint@9.11.1(jiti@1.21.6))(typescript@5.6.2) @@ -4554,11 +4382,11 @@ snapshots: transitivePeerDependencies: - ts-node - eslint-plugin-tailwindcss@3.17.4(tailwindcss@3.4.3): + eslint-plugin-tailwindcss@3.17.4(tailwindcss@3.4.13): dependencies: fast-glob: 3.3.2 - postcss: 8.4.38 - tailwindcss: 3.4.3 + postcss: 8.4.39 + tailwindcss: 3.4.13 eslint-plugin-unicorn@55.0.0(eslint@9.11.1(jiti@1.21.6)): dependencies: @@ -4600,11 +4428,6 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-processor-vue-blocks@0.1.2(@vue/compiler-sfc@3.4.27)(eslint@9.11.1(jiti@1.21.6)): - dependencies: - '@vue/compiler-sfc': 3.4.27 - eslint: 9.11.1(jiti@1.21.6) - eslint-scope@7.2.2: dependencies: esrecurse: 4.3.0 @@ -4695,8 +4518,6 @@ snapshots: estraverse@5.3.0: {} - estree-walker@2.0.2: {} - estree-walker@3.0.3: dependencies: '@types/estree': 1.0.5 @@ -5463,10 +5284,10 @@ snapshots: tsx: 4.19.1 yaml: 2.5.0 - postcss-nested@6.0.1(postcss@8.4.39): + postcss-nested@6.2.0(postcss@8.4.39): dependencies: postcss: 8.4.39 - postcss-selector-parser: 6.1.0 + postcss-selector-parser: 6.1.2 postcss-safe-parser@6.0.0(postcss@8.4.39): dependencies: @@ -5481,13 +5302,12 @@ snapshots: cssesc: 3.0.0 util-deprecate: 1.0.2 - postcss-value-parser@4.2.0: {} - - postcss@8.4.38: + postcss-selector-parser@6.1.2: dependencies: - nanoid: 3.3.7 - picocolors: 1.1.0 - source-map-js: 1.2.0 + cssesc: 3.0.0 + util-deprecate: 1.0.2 + + postcss-value-parser@4.2.0: {} postcss@8.4.39: dependencies: @@ -5501,12 +5321,7 @@ snapshots: dependencies: fast-diff: 1.3.0 - prettier-plugin-toml@2.0.1(prettier@3.3.2): - dependencies: - '@taplo/lib': 0.4.0-alpha.2 - prettier: 3.3.2 - - prettier@3.3.2: {} + prettier@3.3.3: {} pretty-ms@9.0.0: dependencies: @@ -5780,17 +5595,12 @@ snapshots: dependencies: tslib: 2.7.0 - synckit@0.9.0: - dependencies: - '@pkgr/core': 0.1.1 - tslib: 2.7.0 - synckit@0.9.1: dependencies: '@pkgr/core': 0.1.1 tslib: 2.7.0 - tailwindcss@3.4.3: + tailwindcss@3.4.13: dependencies: '@alloc/quick-lru': 5.2.0 arg: 5.0.2 @@ -5810,7 +5620,7 @@ snapshots: postcss-import: 15.1.0(postcss@8.4.39) postcss-js: 4.0.1(postcss@8.4.39) postcss-load-config: 4.0.2(postcss@8.4.39) - postcss-nested: 6.0.1(postcss@8.4.39) + postcss-nested: 6.2.0(postcss@8.4.39) postcss-selector-parser: 6.1.0 resolve: 1.22.8 sucrase: 3.35.0 @@ -5845,8 +5655,6 @@ snapshots: fdir: 6.3.0(picomatch@4.0.2) picomatch: 4.0.2 - to-fast-properties@2.0.0: {} - to-regex-range@5.0.1: dependencies: is-number: 7.0.0 diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 00000000..cc7cbd2a --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,34 @@ +export default { + semi: false, + singleQuote: true, + overrides: [ + { + files: [ + '**/node_modules/**', + '**/dist/**', + '**/output/**', + '**/coverage/**', + '**/temp/**', + '**/.vitepress/cache/**', + '**/.nuxt/**', + '**/.vercel/**', + '**/.changeset/**', + '**/.idea/**', + '**/.output/**', + '**/.vite-inspect/**', + + '**/CHANGELOG*.md', + '**/*.min.*', + '**/LICENSE*', + '**/__snapshots__', + '**/auto-import?(s).d.ts', + '**/components.d.ts', + '**/typed-router.d.ts', + '**/pnpm-lock.yaml', + ], + options: { + requirePragma: true, + }, + }, + ], +} diff --git a/scripts/typegen.ts b/scripts/typegen.ts index 7241e27f..a8aad686 100644 --- a/scripts/typegen.ts +++ b/scripts/typegen.ts @@ -5,18 +5,16 @@ import picocolors from 'picocolors' import { command, comments, - formatter, imports, javascript, jsdoc, jsonc, - jsx, node, perfectionist, + prettier, react, regexp, sortPackageJson, - stylistic, svelte, tailwindcss, test, @@ -36,19 +34,17 @@ const configs = await combine( }, }, comments(), - formatter(), imports(), javascript(), jsdoc(), jsonc(), - jsx(), node(), perfectionist(), react(), sortPackageJson(), - stylistic(), svelte(), test(), + prettier(), typescript(), unicorn(), unocss(), @@ -58,7 +54,7 @@ const configs = await combine( tailwindcss(), ) -const configNames = configs.map(i => i.name).filter(Boolean) as string[] +const configNames = configs.map((i) => i.name).filter(Boolean) as string[] let dts = await flatConfigsToRulesDTS(configs, { includeAugmentation: false, @@ -66,7 +62,7 @@ let dts = await flatConfigsToRulesDTS(configs, { dts += ` // Names of all the configs -export type ConfigNames = ${configNames.map(i => `'${i}'`).join(' | ')} +export type ConfigNames = ${configNames.map((i) => `'${i}'`).join(' | ')} ` await writeFile('src/types/typegen.d.ts', dts) diff --git a/src/cli/constants.ts b/src/cli/constants.ts index 6e5386e7..bc308d1d 100644 --- a/src/cli/constants.ts +++ b/src/cli/constants.ts @@ -10,44 +10,11 @@ export const eslintVersion = devDependencies.eslint export { version } export const vscodeSettingsString = ` - // Disable the default formatter, use eslint instead - "prettier.enable": false, - "editor.formatOnSave": false, + "editor.formatOnSave": true, // Auto fix "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit", "source.organizeImports": "never" }, - - // Silent the stylistic rules in you IDE, but still auto fix them - "eslint.rules.customizations": [ - { "rule": "style/*", "severity": "off", "fixable": true }, - { "rule": "format/*", "severity": "off", "fixable": true }, - { "rule": "*-indent", "severity": "off", "fixable": true }, - { "rule": "*-spacing", "severity": "off", "fixable": true }, - { "rule": "*-spaces", "severity": "off", "fixable": true }, - { "rule": "*-order", "severity": "off", "fixable": true }, - { "rule": "*-dangle", "severity": "off", "fixable": true }, - { "rule": "*-newline", "severity": "off", "fixable": true }, - { "rule": "*quotes", "severity": "off", "fixable": true }, - { "rule": "*semi", "severity": "off", "fixable": true } - ], - - // Enable eslint for all supported languages - "eslint.validate": [ - "svelte", - "html", - "css", - "less", - "scss", - "json", - "jsonc", - "yaml", - "yml", - "markdown", - "toml", - "gql", - "graphql" - ] ` diff --git a/src/cli/index.ts b/src/cli/index.ts index b581d54f..5d838fb6 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import process from 'node:process' import c from 'picocolors' import yargs from 'yargs' @@ -16,7 +15,7 @@ const instance = yargs(hideBin(process.argv)) .command( '*', 'Run the initialization or migration', - args => + (args) => args .option('yes', { alias: 'y', @@ -29,8 +28,7 @@ const instance = yargs(hideBin(process.argv)) console.log() try { await run(args) - } - catch (error) { + } catch (error) { console.error(c.inverse(c.red(' Failed to migrate '))) console.error(c.red(`${CROSS} ${String(error)}`)) process.exit(1) diff --git a/src/cli/run.ts b/src/cli/run.ts index 43b22943..e4497766 100644 --- a/src/cli/run.ts +++ b/src/cli/run.ts @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import fs from 'node:fs' import fsp from 'node:fs/promises' import path from 'node:path' @@ -52,8 +51,7 @@ export async function run(options: RuleOptions = {}) { name: 'confirmed', type: 'confirm', }) - if (!confirmed) - return process.exit(1) + if (!confirmed) return process.exit(1) } // Update package.json @@ -64,8 +62,7 @@ export async function run(options: RuleOptions = {}) { pkg.devDependencies ??= {} pkg.devDependencies['@coderwyd/eslint-config'] = `^${version}` - if (!pkg.devDependencies.eslint) - pkg.devDependencies.eslint = eslintVersion + if (!pkg.devDependencies.eslint) pkg.devDependencies.eslint = eslintVersion await fsp.writeFile(pathPackageJSON, JSON.stringify(pkg, null, 2)) console.log(c.green(`${CHECK} changes wrote to package.json`)) @@ -82,8 +79,7 @@ export async function run(options: RuleOptions = {}) { for (const glob of globs) { if (glob.type === 'ignore') { eslintIgnores.push(...glob.patterns) - } - else if (glob.type === 'unignore') { + } else if (glob.type === 'unignore') { eslintIgnores.push( ...glob.patterns.map((pattern: string) => `!${pattern}`), ) @@ -100,8 +96,7 @@ import { defineConfig } from '@coderwyd/eslint-config' export default defineConfig({\n${coderwydConfig}\n}) `.trimStart() - } - else { + } else { eslintConfigContent = ` const { defineConfig } = require('@coderwyd/eslint-config') @@ -145,8 +140,7 @@ module.exports = defineConfig({\n${coderwydConfig}\n}) }, }, ) - } - catch (error: any) { + } catch (error: any) { console.log(error.message) return } @@ -162,13 +156,12 @@ module.exports = defineConfig({\n${coderwydConfig}\n}) if (!fs.existsSync(settingsPath)) { await fsp.writeFile(settingsPath, `{${vscodeSettingsString}}\n`, 'utf-8') console.log(c.green(`${CHECK} created .vscode/settings.json`)) - } - else { + } else { let settingsContent = await fsp.readFile(settingsPath, 'utf8') settingsContent = settingsContent.trim().replace(/\s*\}$/, '') - settingsContent - += settingsContent.endsWith(',') || settingsContent.endsWith('{') + settingsContent += + settingsContent.endsWith(',') || settingsContent.endsWith('{') ? '' : ',' settingsContent += `${vscodeSettingsString}}\n` diff --git a/src/cli/utils.ts b/src/cli/utils.ts index 2215b5ca..d4afef94 100644 --- a/src/cli/utils.ts +++ b/src/cli/utils.ts @@ -4,8 +4,7 @@ export function isGitClean() { try { execSync('git diff-index --quiet HEAD --') return true - } - catch { + } catch { return false } } diff --git a/src/configs/formatter.ts b/src/configs/formatter.ts deleted file mode 100644 index d82966aa..00000000 --- a/src/configs/formatter.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { - GLOB_CSS, - GLOB_GRAPHQL, - GLOB_HTML, - GLOB_LESS, - GLOB_MARKDOWN, - GLOB_POSTCSS, - GLOB_SCSS, - GLOB_TOML, - GLOB_YAML, -} from '../constants/glob' -import { ensurePackages, interopDefault, parserPlain } from '../shared' -import { StylisticConfigDefaults } from './stylistic' -import type { - OptionsFormatters, - PartialPrettierExtendedOptions, - PrettierParser, - StylisticConfig, - TypedFlatConfigItem, -} from '../types' - -export async function formatter( - options: OptionsFormatters | true = {}, - stylistic: StylisticConfig = {}, -): Promise { - const { css, graphql, html, markdown, toml, yaml } - = options === true - ? { - css: true, - graphql: true, - html: true, - markdown: true, - toml: true, - yaml: true, - } - : options - - const { indent, quotes, semi } = { - ...StylisticConfigDefaults, - ...stylistic, - } - - const prettierOptions: PartialPrettierExtendedOptions = Object.assign( - { - endOfLine: 'auto', - printWidth: 80, - semi, - singleQuote: quotes === 'single', - tabWidth: typeof indent === 'number' ? indent : 2, - trailingComma: 'all', - useTabs: indent === 'tab', - } satisfies PartialPrettierExtendedOptions, - typeof options === 'boolean' ? {} : options.prettierOptions || {}, - ) - await ensurePackages(['eslint-plugin-format']) - - const pluginFormat = await interopDefault(import('eslint-plugin-format')) - - function createPrettierFormatter( - files: string[], - parser: PrettierParser, - plugins?: string[], - ) { - const rules = { - ...prettierOptions, - parser, - } - - const markdownRules = { - printWidth: 120, - ...rules, - embeddedLanguageFormatting: 'off', - } - - if (plugins?.length) - rules.plugins = [...(rules.plugins || []), ...plugins] - - const config: TypedFlatConfigItem = { - files, - languageOptions: { - parser: parserPlain, - }, - name: `coderwyd/formatter/${parser}`, - plugins: { - format: pluginFormat, - }, - rules: { - 'format/prettier': [ - 'warn', - parser === 'markdown' ? markdownRules : rules, - ], - }, - } - - return config - } - - const configs: TypedFlatConfigItem[] = [ - { - name: 'coderwyd/formatter/setup', - plugins: { - format: pluginFormat, - }, - }, - ] - - if (html) { - const htmlConfig = createPrettierFormatter([GLOB_HTML], 'html') - configs.push(htmlConfig) - } - - if (css) { - const cssConfig = createPrettierFormatter([GLOB_CSS, GLOB_POSTCSS], 'css') - const scssConfig = createPrettierFormatter([GLOB_SCSS], 'scss') - const lessConfig = createPrettierFormatter([GLOB_LESS], 'less') - - configs.push(cssConfig, scssConfig, lessConfig) - } - - if (markdown) { - const markdownConfig = createPrettierFormatter([GLOB_MARKDOWN], 'markdown') - configs.push(markdownConfig) - } - - if (graphql) { - const graphqlConfig = createPrettierFormatter([GLOB_GRAPHQL], 'graphql') - configs.push(graphqlConfig) - } - - if (yaml) { - const yamlConfig = createPrettierFormatter([GLOB_YAML], 'yaml') - configs.push(yamlConfig) - } - - if (toml) { - await ensurePackages(['@toml-tools/parser', 'prettier-plugin-toml']) - - const tomlConfig = createPrettierFormatter([GLOB_TOML], 'toml', [ - 'prettier-plugin-toml', - ]) - - configs.push(tomlConfig) - } - - return configs -} diff --git a/src/configs/ignores.ts b/src/configs/ignores.ts index c6072d77..98b960c4 100644 --- a/src/configs/ignores.ts +++ b/src/configs/ignores.ts @@ -4,10 +4,7 @@ import type { TypedFlatConfigItem } from '../types' export function ignores(userIgnores: string[] = []): TypedFlatConfigItem[] { return [ { - ignores: [ - ...GLOB_EXCLUDE, - ...userIgnores, - ], + ignores: [...GLOB_EXCLUDE, ...userIgnores], name: 'coderwyd/ignores', }, ] diff --git a/src/configs/imports.ts b/src/configs/imports.ts index 0171902f..1964f6dc 100644 --- a/src/configs/imports.ts +++ b/src/configs/imports.ts @@ -1,10 +1,7 @@ import { pluginAntfu, pluginImport } from '../plugins' -import type { OptionsStylistic, TypedFlatConfigItem } from '../types' +import type { TypedFlatConfigItem } from '../types' -export function imports( - options: OptionsStylistic = {}, -): TypedFlatConfigItem[] { - const { stylistic = true } = options +export function imports(): TypedFlatConfigItem[] { return [ { name: 'coderwyd/imports/rules', @@ -23,12 +20,6 @@ export function imports( 'import/no-named-default': 'error', 'import/no-self-import': 'error', 'import/no-webpack-loader-syntax': 'error', - - ...(stylistic - ? { - 'import/newline-after-import': ['error', { count: 1 }], - } - : {}), }, }, ] diff --git a/src/configs/index.ts b/src/configs/index.ts index 9aca8397..8bb18d10 100644 --- a/src/configs/index.ts +++ b/src/configs/index.ts @@ -1,19 +1,17 @@ export * from './command' export * from './comments' -export * from './disables' -export * from './formatter' export * from './ignores' export * from './imports' export * from './javascript' export * from './jsdoc' export * from './jsonc' -export * from './jsx' export * from './node' export * from './perfectionist' +export * from './prettier' export * from './react' export * from './regexp' export * from './sort' -export * from './stylistic' +export * from './specials' export * from './svelte' export * from './tailwindcss' export * from './test' diff --git a/src/configs/javascript.ts b/src/configs/javascript.ts index 2ec98681..e4b76561 100644 --- a/src/configs/javascript.ts +++ b/src/configs/javascript.ts @@ -55,7 +55,7 @@ export function javascript( 'constructor-super': 'error', 'default-case-last': 'error', 'dot-notation': ['error', { allowKeywords: true }], - 'eqeqeq': ['error', 'smart'], + eqeqeq: ['error', 'smart'], 'for-direction': 'error', 'getter-return': 'error', 'new-cap': [ @@ -239,7 +239,7 @@ export function javascript( ], 'valid-typeof': ['error', { requireStringLiterals: true }], 'vars-on-top': 'error', - 'yoda': ['error', 'never'], + yoda: ['error', 'never'], ...overrides, }, diff --git a/src/configs/jsdoc.ts b/src/configs/jsdoc.ts index c6a546c2..36c474e1 100644 --- a/src/configs/jsdoc.ts +++ b/src/configs/jsdoc.ts @@ -1,10 +1,7 @@ import { interopDefault } from '../shared' -import type { OptionsStylistic, TypedFlatConfigItem } from '../types' +import type { TypedFlatConfigItem } from '../types' -export async function jsdoc( - options: OptionsStylistic = {}, -): Promise { - const { stylistic = true } = options +export async function jsdoc(): Promise { return [ { name: 'coderwyd/jsdoc/rules', @@ -27,13 +24,6 @@ export async function jsdoc( 'jsdoc/require-returns-check': 'warn', 'jsdoc/require-returns-description': 'warn', 'jsdoc/require-yields-check': 'warn', - - ...(stylistic - ? { - 'jsdoc/check-alignment': 'warn', - 'jsdoc/multiline-blocks': 'warn', - } - : {}), }, }, ] diff --git a/src/configs/jsonc.ts b/src/configs/jsonc.ts index 6f118af4..64b80584 100644 --- a/src/configs/jsonc.ts +++ b/src/configs/jsonc.ts @@ -3,22 +3,14 @@ import { interopDefault } from '../shared' import type { OptionsFiles, OptionsOverrides, - OptionsStylistic, TypedFlatConfigItem, } from '../types' export async function jsonc( - options: OptionsFiles & OptionsStylistic & OptionsOverrides = {}, + options: OptionsFiles & OptionsOverrides = {}, ): Promise { - const { - files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], - overrides = {}, - stylistic = true, - } = options || {} - - const { - indent = 2, - } = typeof stylistic === 'boolean' ? {} : stylistic + const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } = + options || {} const [pluginJsonc, parserJsonc] = await Promise.all([ interopDefault(import('eslint-plugin-jsonc')), @@ -66,30 +58,6 @@ export async function jsonc( 'jsonc/valid-json-number': 'error', 'jsonc/vue-custom-block/no-parsing-error': 'error', - ...(stylistic - ? { - 'jsonc/array-bracket-spacing': ['error', 'never'], - 'jsonc/comma-dangle': ['error', 'never'], - 'jsonc/comma-style': ['error', 'last'], - 'jsonc/indent': ['error', indent], - 'jsonc/key-spacing': [ - 'error', - { afterColon: true, beforeColon: false }, - ], - 'jsonc/object-curly-newline': [ - 'error', - { consistent: true, multiline: true }, - ], - 'jsonc/object-curly-spacing': ['error', 'always'], - 'jsonc/object-property-newline': [ - 'error', - { allowMultiplePropertiesPerLine: true }, - ], - 'jsonc/quote-props': 'error', - 'jsonc/quotes': 'error', - } - : {}), - ...overrides, }, }, diff --git a/src/configs/jsx.ts b/src/configs/jsx.ts deleted file mode 100644 index 8c5a49a1..00000000 --- a/src/configs/jsx.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { GLOB_JSX, GLOB_TSX } from '../constants/glob' -import type { TypedFlatConfigItem } from '../types' - -export function jsx(): TypedFlatConfigItem[] { - return [ - { - files: [GLOB_JSX, GLOB_TSX], - languageOptions: { - parserOptions: { - ecmaFeatures: { - jsx: true, - }, - }, - }, - name: 'coderwyd/jsx/setup', - }, - ] -} diff --git a/src/configs/perfectionist.ts b/src/configs/perfectionist.ts index 9ba17ed0..93dab613 100644 --- a/src/configs/perfectionist.ts +++ b/src/configs/perfectionist.ts @@ -14,7 +14,10 @@ export function perfectionist(): TypedFlatConfigItem[] { perfectionist: pluginPerfectionist, }, rules: { - 'perfectionist/sort-exports': ['error', { order: 'asc', type: 'natural' }], + 'perfectionist/sort-exports': [ + 'error', + { order: 'asc', type: 'natural' }, + ], 'perfectionist/sort-imports': [ 'warn', { diff --git a/src/configs/prettier.ts b/src/configs/prettier.ts new file mode 100644 index 00000000..c832a5bd --- /dev/null +++ b/src/configs/prettier.ts @@ -0,0 +1,24 @@ +import prettierRules from 'eslint-config-prettier' +import { interopDefault } from '../shared' +import type { TypedFlatConfigItem } from '../types' + +const { rules: eslintRules } = prettierRules + +export async function prettier(): Promise { + const pluginPrettier = await interopDefault(import('eslint-plugin-prettier')) + + return [ + { + name: 'coderwyd/prettier/rules', + plugins: { + prettier: pluginPrettier, + }, + rules: { + ...eslintRules, + 'arrow-body-style': 'off', + 'prefer-arrow-callback': 'off', + 'prettier/prettier': 'warn', + }, + }, + ] +} diff --git a/src/configs/react.ts b/src/configs/react.ts index cda5d31a..7d617833 100644 --- a/src/configs/react.ts +++ b/src/configs/react.ts @@ -28,8 +28,8 @@ export async function react( : undefined const isTypeAware = !!tsconfigPath - const [pluginReact, pluginReactHooks, pluginReactRefresh, parserTs] - = await Promise.all([ + const [pluginReact, pluginReactHooks, pluginReactRefresh, parserTs] = + await Promise.all([ interopDefault(import('@eslint-react/eslint-plugin')), interopDefault(import('eslint-plugin-react-hooks')), interopDefault(import('eslint-plugin-react-refresh')), @@ -37,7 +37,7 @@ export async function react( ] as const) const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some( - i => isPackageExists(i), + (i) => isPackageExists(i), ) const plugins = pluginReact.configs.all.plugins @@ -46,7 +46,7 @@ export async function react( { name: 'coderwyd/react/setup', plugins: { - 'react': plugins['@eslint-react'], + react: plugins['@eslint-react'], 'react-dom': plugins['@eslint-react/dom'], 'react-hooks': pluginReactHooks, 'react-hooks-extra': plugins['@eslint-react/hooks-extra'], diff --git a/src/configs/regexp.ts b/src/configs/regexp.ts index ff34bfb9..d02fa38d 100644 --- a/src/configs/regexp.ts +++ b/src/configs/regexp.ts @@ -16,8 +16,7 @@ export function regexp( if (options.level === 'warn') { Object.keys(rules).forEach((key) => { - if (rules[key] === 'error') - rules[key] = 'warn' + if (rules[key] === 'error') rules[key] = 'warn' }) } diff --git a/src/configs/disables.ts b/src/configs/specials.ts similarity index 81% rename from src/configs/disables.ts rename to src/configs/specials.ts index 971b4512..2bddd131 100644 --- a/src/configs/disables.ts +++ b/src/configs/specials.ts @@ -1,11 +1,11 @@ import { GLOB_DTS, GLOB_SRC, GLOB_SRC_EXT } from '../constants/glob' import type { TypedFlatConfigItem } from '../types' -export function disables(): TypedFlatConfigItem[] { +export function specials(): TypedFlatConfigItem[] { return [ { files: [`**/scripts/${GLOB_SRC}`], - name: 'coderwyd/disables/scripts', + name: 'coderwyd/specials/scripts', rules: { 'antfu/no-top-level-await': 'off', 'no-console': 'off', @@ -14,7 +14,7 @@ export function disables(): TypedFlatConfigItem[] { }, { files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`], - name: 'coderwyd/disables/cli', + name: 'coderwyd/specials/cli', rules: { 'antfu/no-top-level-await': 'off', 'no-console': 'off', @@ -22,7 +22,7 @@ export function disables(): TypedFlatConfigItem[] { }, { files: ['**/bin/**/*', `**/bin.${GLOB_SRC_EXT}`], - name: 'coderwyd/disables/bin', + name: 'coderwyd/specials/bin', rules: { 'antfu/no-import-dist': 'off', 'antfu/no-import-node-modules-by-path': 'off', @@ -30,7 +30,7 @@ export function disables(): TypedFlatConfigItem[] { }, { files: [GLOB_DTS], - name: 'coderwyd/disables/dts', + name: 'coderwyd/specials/dts', rules: { 'eslint-comments/no-unlimited-disable': 'off', 'import/no-duplicates': 'off', @@ -40,7 +40,7 @@ export function disables(): TypedFlatConfigItem[] { }, { files: ['**/*.{test,spec}.([tj])s?(x)'], - name: 'coderwyd/disables/test', + name: 'coderwyd/specials/test', rules: { 'antfu/no-top-level-await': 'off', 'no-unused-expressions': 'off', @@ -48,7 +48,7 @@ export function disables(): TypedFlatConfigItem[] { }, { files: ['**/*.js', '**/*.cjs'], - name: 'coderwyd/disables/cjs', + name: 'coderwyd/specials/cjs', rules: { 'ts/no-require-imports': 'off', }, diff --git a/src/configs/stylistic.ts b/src/configs/stylistic.ts deleted file mode 100644 index f3203a06..00000000 --- a/src/configs/stylistic.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { pluginAntfu } from '../plugins' -import { interopDefault } from '../shared' -import type { - OptionsOverrides, - StylisticConfig, - TypedFlatConfigItem, -} from '../types' - -export const StylisticConfigDefaults: StylisticConfig = { - indent: 2, - jsx: true, - quotes: 'single', - semi: false, -} - -export async function stylistic( - options: StylisticConfig & OptionsOverrides = {}, -): Promise { - const { - indent, - jsx, - overrides = {}, - quotes, - semi, - } = { - ...StylisticConfigDefaults, - ...options, - } - - const pluginStylistic = await interopDefault( - import('@stylistic/eslint-plugin'), - ) - - const config = pluginStylistic.configs.customize({ - flat: true, - indent, - jsx, - pluginName: 'style', - quotes, - semi, - }) - - return [ - { - name: 'coderwyd/stylistic/rules', - plugins: { - antfu: pluginAntfu, - style: pluginStylistic, - }, - rules: { - ...config.rules, - - 'antfu/consistent-chaining': 'error', - 'antfu/consistent-list-newline': 'error', - - 'antfu/curly': 'error', - 'antfu/if-newline': 'warn', - 'antfu/top-level-function': 'warn', - - ...overrides, - }, - }, - ] -} diff --git a/src/configs/svelte.ts b/src/configs/svelte.ts index 2447352d..48ec9b4a 100644 --- a/src/configs/svelte.ts +++ b/src/configs/svelte.ts @@ -4,21 +4,13 @@ import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, - OptionsStylistic, TypedFlatConfigItem, } from '../types' export async function svelte( - options: OptionsHasTypeScript & - OptionsOverrides & - OptionsStylistic & - OptionsFiles = {}, + options: OptionsHasTypeScript & OptionsOverrides & OptionsFiles = {}, ): Promise { - const { files = [GLOB_SVELTE], overrides = {}, stylistic = true } = options - const { - indent = 2, - quotes = 'single', - } = typeof stylistic === 'boolean' ? {} : stylistic + const { files = [GLOB_SVELTE], overrides = {} } = options await ensurePackages(['eslint-plugin-svelte']) @@ -94,24 +86,6 @@ export async function svelte( }, ], - ...(stylistic - ? { - 'style/indent': 'off', // superseded by svelte/indent - 'style/no-trailing-spaces': 'off', // superseded by svelte/no-trailing-spaces - 'svelte/derived-has-same-inputs-outputs': 'error', - 'svelte/html-closing-bracket-spacing': 'error', - 'svelte/html-quotes': ['error', { prefer: quotes }], - 'svelte/indent': [ - 'error', - { alignAttributesVertically: true, indent }, - ], - 'svelte/mustache-spacing': 'error', - 'svelte/no-spaces-around-equal-signs-in-attribute': 'error', - 'svelte/no-trailing-spaces': 'error', - 'svelte/spaced-html-comment': 'error', - } - : {}), - ...overrides, }, }, diff --git a/src/configs/typescript.ts b/src/configs/typescript.ts index 0d0a7fa4..fc521143 100644 --- a/src/configs/typescript.ts +++ b/src/configs/typescript.ts @@ -1,5 +1,10 @@ import process from 'node:process' -import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from '../constants/glob' +import { + GLOB_ASTRO_TS, + GLOB_MARKDOWN, + GLOB_TS, + GLOB_TSX, +} from '../constants/glob' import { pluginAntfu } from '../plugins' import { interopDefault, renameRules } from '../shared' import type { @@ -18,12 +23,17 @@ export async function typescript( OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions = {}, ): Promise { - const { componentExts = [], overrides = {}, overridesTypeAware = {}, parserOptions = {} } = options + const { + componentExts = [], + overrides = {}, + overridesTypeAware = {}, + parserOptions = {}, + } = options const files = options.files ?? [ GLOB_TS, GLOB_TSX, - ...componentExts.map(ext => `**/*.${ext}`), + ...componentExts.map((ext) => `**/*.${ext}`), ] const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX] @@ -75,7 +85,7 @@ export async function typescript( languageOptions: { parser: parserTs, parserOptions: { - extraFileExtensions: componentExts.map(ext => `.${ext}`), + extraFileExtensions: componentExts.map((ext) => `.${ext}`), sourceType: 'module', ...(typeAware ? { @@ -138,8 +148,11 @@ export async function typescript( 'ts/no-dynamic-delete': 'off', 'ts/no-empty-object-type': [ 'error', - { allowInterfaces: 'with-single-extends', // interface Derived extends Base {} - allowObjectTypes: 'never', allowWithName: 'Props$' }, + { + allowInterfaces: 'with-single-extends', // interface Derived extends Base {} + allowObjectTypes: 'never', + allowWithName: 'Props$', + }, ], 'ts/no-explicit-any': 'off', 'ts/no-extraneous-class': 'off', @@ -148,11 +161,14 @@ export async function typescript( 'ts/no-non-null-assertion': 'off', 'ts/no-redeclare': ['error', { builtinGlobals: false }], 'ts/no-require-imports': 'error', - 'ts/no-unused-expressions': ['error', { - allowShortCircuit: true, - allowTaggedTemplates: true, - allowTernary: true, - }], + 'ts/no-unused-expressions': [ + 'error', + { + allowShortCircuit: true, + allowTaggedTemplates: true, + allowTernary: true, + }, + ], 'ts/no-unused-vars': 'off', 'ts/no-use-before-define': [ 'error', diff --git a/src/configs/vue.ts b/src/configs/vue.ts index 2d002ed5..e3e8d2f5 100644 --- a/src/configs/vue.ts +++ b/src/configs/vue.ts @@ -1,11 +1,9 @@ -import { mergeProcessors } from 'eslint-merge-processors' import { GLOB_VUE } from '../constants/glob' import { getVueVersion, interopDefault } from '../shared' import type { OptionsFiles, OptionsHasTypeScript, OptionsOverrides, - OptionsStylistic, OptionsVue, TypedFlatConfigItem, } from '../types' @@ -14,19 +12,13 @@ export async function vue( options: OptionsVue & OptionsHasTypeScript & OptionsOverrides & - OptionsStylistic & OptionsFiles = {}, ): Promise { - const { files = [GLOB_VUE], overrides = {}, stylistic = true } = options + const { files = [GLOB_VUE], overrides = {} } = options - const sfcBlocks = options.sfcBlocks === true ? {} : options.sfcBlocks ?? {} - - const { indent = 2 } = typeof stylistic === 'boolean' ? {} : stylistic - - const [pluginVue, parserVue, processorVueBlocks] = await Promise.all([ + const [pluginVue, parserVue] = await Promise.all([ interopDefault(import('eslint-plugin-vue')), interopDefault(import('vue-eslint-parser')), - interopDefault(import('eslint-processor-vue-blocks')), ] as const) type VueConfigKey = import('eslint-plugin-vue').VueConfigKey @@ -46,32 +38,6 @@ export async function vue( }, {}) return [ - { - // This allows Vue plugin to work with auto imports - // https://github.com/vuejs/eslint-plugin-vue/pull/2422 - languageOptions: { - globals: { - computed: 'readonly', - defineEmits: 'readonly', - defineExpose: 'readonly', - defineProps: 'readonly', - onMounted: 'readonly', - onUnmounted: 'readonly', - reactive: 'readonly', - ref: 'readonly', - shallowReactive: 'readonly', - shallowRef: 'readonly', - toRef: 'readonly', - toRefs: 'readonly', - watch: 'readonly', - watchEffect: 'readonly', - }, - }, - name: 'coderwyd/vue/setup', - plugins: { - vue: pluginVue, - }, - }, { files, languageOptions: { @@ -90,19 +56,10 @@ export async function vue( }, }, name: 'coderwyd/vue/rules', - processor: - sfcBlocks === false - ? pluginVue.processors!['.vue'] - : mergeProcessors([ - pluginVue.processors!['.vue'], - processorVueBlocks({ - ...sfcBlocks, - blocks: { - styles: true, - ...sfcBlocks.blocks, - }, - }), - ]), + plugins: { + vue: pluginVue, + }, + processor: pluginVue.processors!['.vue'], rules: { ...pluginVue.configs.base.rules, ...vueRules, @@ -138,11 +95,7 @@ export async function vue( }, ], // 'vue/define-props-declaration': ['warn', 'type-based'], - 'vue/dot-location': ['error', 'property'], - 'vue/dot-notation': ['error', { allowKeywords: true }], 'vue/eqeqeq': ['error', 'smart'], - 'vue/html-indent': ['error', indent], - 'vue/html-quotes': ['error', 'double'], 'vue/html-self-closing': [ 'error', { @@ -159,7 +112,6 @@ export async function vue( 'vue/multi-word-component-names': 'off', // 'vue/next-tick-style': ['warn', 'promise'], 'vue/no-constant-condition': 'warn', - 'vue/no-dupe-keys': 'off', 'vue/no-duplicate-attr-inheritance': 'warn', 'vue/no-empty-pattern': 'error', 'vue/no-extra-parens': ['error', 'functions'], @@ -191,6 +143,7 @@ export async function vue( ignoreConstructors: false, }, ], + 'vue/padding-line-between-blocks': ['error', 'always'], 'vue/prefer-define-options': 'warn', 'vue/prefer-separate-static-class': 'error', 'vue/prefer-template': 'error', @@ -210,54 +163,8 @@ export async function vue( // 'vue/singleline-html-element-content-newline': 'off', 'vue/space-infix-ops': 'error', 'vue/space-unary-ops': ['error', { nonwords: false, words: true }], - 'vue/valid-define-options': 'warn', - ...(stylistic - ? { - 'vue/array-bracket-spacing': ['error', 'never'], - 'vue/arrow-spacing': ['error', { after: true, before: true }], - 'vue/block-spacing': ['error', 'always'], - 'vue/block-tag-newline': [ - 'error', - { - multiline: 'always', - singleline: 'always', - }, - ], - 'vue/brace-style': [ - 'error', - 'stroustrup', - { allowSingleLine: true }, - ], - 'vue/comma-dangle': ['error', 'always-multiline'], - 'vue/comma-spacing': ['error', { after: true, before: false }], - 'vue/comma-style': ['error', 'last'], - 'vue/html-comment-content-newline': 'warn', - 'vue/html-comment-content-spacing': [ - 'error', - 'always', - { - exceptions: ['-'], - }, - ], - 'vue/key-spacing': [ - 'error', - { afterColon: true, beforeColon: false }, - ], - 'vue/keyword-spacing': ['error', { after: true, before: true }], - 'vue/object-curly-newline': 'off', - 'vue/object-curly-spacing': ['error', 'always'], - 'vue/object-property-newline': [ - 'error', - { allowMultiplePropertiesPerLine: true }, - ], - 'vue/operator-linebreak': ['error', 'before'], - 'vue/padding-line-between-blocks': ['error', 'always'], - 'vue/quote-props': ['error', 'consistent-as-needed'], - 'vue/space-in-parens': ['error', 'never'], - 'vue/template-curly-spacing': 'error', - } - : {}), + 'vue/valid-define-options': 'warn', ...overrides, }, diff --git a/src/constants/glob.ts b/src/constants/glob.ts index 07cd0918..a72bec4b 100644 --- a/src/constants/glob.ts +++ b/src/constants/glob.ts @@ -31,8 +31,6 @@ export const GLOB_YAML = '**/*.y?(a)ml' export const GLOB_TOML = '**/*.toml' export const GLOB_GRAPHQL = '**/*.{g,graph}ql' -export const GLOB_PRETTIER_LINT = [GLOB_SRC, GLOB_VUE] - export const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}` export const GLOB_TS_CONFIG = '**/tsconfig.json' diff --git a/src/env.ts b/src/env.ts index fc2e23ee..ddcd74c8 100644 --- a/src/env.ts +++ b/src/env.ts @@ -2,21 +2,16 @@ import process from 'node:process' import { isPackageExists } from 'local-pkg' export const isInEditor = !!( - (process.env.VSCODE_PID - || process.env.VSCODE_CWD - || process.env.JETBRAINS_IDE - || process.env.VIM - || process.env.NVIM) - && !process.env.CI + (process.env.VSCODE_PID || + process.env.VSCODE_CWD || + process.env.JETBRAINS_IDE || + process.env.VIM || + process.env.NVIM) && + !process.env.CI ) export const hasTypeScript = isPackageExists('typescript') -const VueJsPackages = [ - 'vue', - 'nuxt', - 'vitepress', - '@slidev/cli', -] +const VueJsPackages = ['vue', 'nuxt', 'vitepress', '@slidev/cli'] export const hasVue = hasPackages(VueJsPackages) @@ -34,5 +29,5 @@ export const isUsingRemix = hasPackages(RemixPackages) export const isUsingNext = hasPackages(NextJsPackages) function hasPackages(packages: string[]) { - return packages.some(name => isPackageExists(name)) + return packages.some((name) => isPackageExists(name)) } diff --git a/src/index.ts b/src/index.ts index 8ec1d845..9abab911 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,21 +2,19 @@ import type { Linter } from 'eslint' import { command, comments, - disables, - formatter, ignores, imports, javascript, jsdoc, jsonc, - jsx, node, perfectionist, + prettier, react, regexp, sortPackageJson, sortTsconfig, - stylistic, + specials, svelte, tailwindcss, test, @@ -25,10 +23,7 @@ import { unocss, vue, } from './configs' -import { - hasTypeScript, - hasVue, -} from './env' +import { hasTypeScript, hasVue } from './env' import { combine, getOverrides, @@ -55,12 +50,11 @@ export const defaultPluginRenaming = { '@eslint-react/hooks-extra': 'react-hooks-extra', '@eslint-react/naming-convention': 'react-naming-convention', - '@stylistic': 'style', '@typescript-eslint': 'ts', 'import-x': 'import', - 'n': 'node', - 'vitest': 'test', - 'yml': 'yaml', + n: 'node', + vitest: 'test', + yml: 'yaml', } /** @@ -82,12 +76,7 @@ export async function defineConfig( const { autoRenamePlugins = true, componentExts = [], - formatter: formatterOptions = { - css: true, - html: true, - }, gitignore: enableGitignore = true, - jsx: enableJsx = true, react: enableReact = false, regexp: enableRegexp = true, svelte: enableSvelte = false, @@ -102,40 +91,37 @@ export async function defineConfig( isInEditor = isInEditorEnv() if (isInEditor) // eslint-disable-next-line no-console - console.log('[@coderwyd/eslint-config] Detected running in editor, some rules are disabled.') + console.log( + '[@coderwyd/eslint-config] Detected running in editor, some rules are disabled.', + ) } - const stylisticOptions - = options.stylistic === false - ? false - : typeof options.stylistic === 'object' - ? options.stylistic - : {} - - if (stylisticOptions && !('jsx' in stylisticOptions)) - stylisticOptions.jsx = enableJsx - const configs: Awaitable[] = [] if (enableGitignore) { if (typeof enableGitignore !== 'boolean') { configs.push( - interopDefault(import('eslint-config-flat-gitignore')).then(r => [ + interopDefault(import('eslint-config-flat-gitignore')).then((r) => [ r({ ...enableGitignore, name: 'coderwyd/gitignore', }), ]), ) - } - else { - configs.push(interopDefault(import('eslint-config-flat-gitignore')) - .then(r => [r({ name: 'coderwyd/gitignore', strict: false })])) + } else { + configs.push( + interopDefault(import('eslint-config-flat-gitignore')).then((r) => [ + r({ name: 'coderwyd/gitignore', strict: false }), + ]), + ) } } const typescriptOptions = resolveSubOptions(options, 'typescript') - const tsconfigPath = 'tsconfigPath' in typescriptOptions ? typescriptOptions.tsconfigPath : undefined + const tsconfigPath = + 'tsconfigPath' in typescriptOptions + ? typescriptOptions.tsconfigPath + : undefined // Base configs configs.push( @@ -146,25 +132,17 @@ export async function defineConfig( }), comments(), node(), - jsdoc({ - stylistic: stylisticOptions, - }), - imports({ - stylistic: stylisticOptions, - }), + jsdoc(), + imports(), unicorn(), command(), + prettier(), // Optional plugins (installed but not enabled by default) perfectionist(), ) - if (enableVue) - componentExts.push('vue') - - if (enableJsx) { - configs.push(jsx()) - } + if (enableVue) componentExts.push('vue') if (enableTypeScript) { configs.push( @@ -176,15 +154,6 @@ export async function defineConfig( ) } - if (stylisticOptions) { - configs.push( - stylistic({ - ...stylisticOptions, - overrides: getOverrides(options, 'stylistic'), - }), - ) - } - if (enableRegexp) configs.push(regexp(typeof enableRegexp === 'boolean' ? {} : enableRegexp)) @@ -202,7 +171,6 @@ export async function defineConfig( vue({ ...resolveSubOptions(options, 'vue'), overrides: getOverrides(options, 'typescript'), - stylistic: stylisticOptions, typescript: !!enableTypeScript, }), ) @@ -221,7 +189,6 @@ export async function defineConfig( configs.push( svelte({ overrides: getOverrides(options, 'svelte'), - stylistic: stylisticOptions, typescript: !!enableTypeScript, }), ) @@ -248,36 +215,27 @@ export async function defineConfig( configs.push( jsonc({ overrides: getOverrides(options, 'jsonc'), - stylistic: stylisticOptions, }), sortPackageJson(), sortTsconfig(), ) } - if (formatterOptions) { - configs.push( - formatter( - formatterOptions, - typeof stylisticOptions === 'boolean' ? {} : stylisticOptions, - ), - ) - } - configs.push(disables()) + configs.push(specials()) if ('files' in options) { - throw new Error('[@coderwyd/eslint-config] The first argument should not contain the "files" property as the options are supposed to be global. Place it in the second or later config instead.') + throw new Error( + '[@coderwyd/eslint-config] The first argument should not contain the "files" property as the options are supposed to be global. Place it in the second or later config instead.', + ) } // User can optionally pass a flat config item to the first argument // We pick the known keys as ESLint would do schema validation const fusedConfig = flatConfigProps.reduce((acc, key) => { - if (key in options) - acc[key] = options[key] as any + if (key in options) acc[key] = options[key] as any return acc }, {} as TypedFlatConfigItem) - if (Object.keys(fusedConfig).length > 0) - configs.push([fusedConfig]) + if (Object.keys(fusedConfig).length > 0) configs.push([fusedConfig]) const merged = await combine(...configs, ...userConfigs) diff --git a/src/shared/index.ts b/src/shared/index.ts index 91d344de..3e26a61e 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -95,13 +95,11 @@ export function renamePluginInConfigs( ): TypedFlatConfigItem[] { return configs.map((i) => { const clone = { ...i } - if (clone.rules) - clone.rules = renameRules(clone.rules, map) + if (clone.rules) clone.rules = renameRules(clone.rules, map) if (clone.plugins) { clone.plugins = Object.fromEntries( Object.entries(clone.plugins).map(([key, value]) => { - if (key in map) - return [map[key], value] + if (key in map) return [map[key], value] return [key, value] }), ) @@ -134,12 +132,15 @@ export function isPackageInScope(name: string): boolean { } export async function ensurePackages(packages: string[]) { - if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) + if ( + process.env.CI || + process.stdout.isTTY === false || + isCwdInScope === false + ) return - const nonExistingPackages = packages.filter(i => !isPackageInScope(i)) - if (nonExistingPackages.length === 0) - return + const nonExistingPackages = packages.filter((i) => !isPackageInScope(i)) + if (nonExistingPackages.length === 0) return const { default: prompts } = await import('prompts') const { result } = await prompts([ @@ -152,7 +153,7 @@ export async function ensurePackages(packages: string[]) { }, ]) if (result) { - await import('@antfu/install-pkg').then(i => + await import('@antfu/install-pkg').then((i) => i.installPackage(nonExistingPackages, { dev: true }), ) } @@ -176,24 +177,26 @@ export function getOverrides( } export function isInEditorEnv(): boolean { - if (process.env.CI) + if (process.env.CI) return false + if (isInGitHooksOrLintStaged()) { return false - if (isInGitHooksOrLintStaged()) - return false - return !!(process.env.VSCODE_PID - || process.env.VSCODE_CWD - || process.env.JETBRAINS_IDE - || process.env.VIM - || process.env.NVIM - || false + } + return !!( + process.env.VSCODE_PID || + process.env.VSCODE_CWD || + process.env.JETBRAINS_IDE || + process.env.VIM || + process.env.NVIM || + false ) } export function isInGitHooksOrLintStaged(): boolean { - return !!(process.env.GIT_PARAMS - || process.env.VSCODE_GIT_COMMAND - || process.env.npm_lifecycle_script?.startsWith('lint-staged') - || process.env.npm_lifecycle_script?.startsWith('nano-staged') - || false + return !!( + process.env.GIT_PARAMS || + process.env.VSCODE_GIT_COMMAND || + process.env.npm_lifecycle_script?.startsWith('lint-staged') || + process.env.npm_lifecycle_script?.startsWith('nano-staged') || + false ) } diff --git a/src/types/index.ts b/src/types/index.ts index 37fb1797..c99e34c9 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,11 +1,6 @@ -import type { StylisticCustomizeOptions } from '@stylistic/eslint-plugin' import type { ParserOptions } from '@typescript-eslint/parser' import type { FlatGitignoreOptions } from 'eslint-config-flat-gitignore' -import type { Options as VueBlocksOptions } from 'eslint-processor-vue-blocks' -import type { - PartialPrettierExtendedOptions, - TypedFlatConfigItem, -} from './rule' +import type { TypedFlatConfigItem } from './rule' export * from './rule' @@ -22,46 +17,6 @@ export type OptionsTypescript = | (OptionsTypeScriptWithTypes & OptionsOverrides) | (OptionsTypeScriptParserOptions & OptionsOverrides) -export interface OptionsFormatters { - /** - * Enable formatting support for HTML. - */ - html?: boolean - - /** - * Enable formatting support for CSS, Less, Sass, and SCSS. - */ - css?: boolean - - /** - * Enable formatting support for Markdown. - */ - markdown?: boolean - - /** - * Enable formatting support for GraphQL. - */ - graphql?: boolean - - /** - * Enable formatting support for Yaml. - */ - yaml?: boolean - - /** - * Enable formatting support for Toml. - */ - toml?: boolean - - /** - * Custom options for Prettier. - * - * By default it's controlled by our own config. - * - */ - prettierOptions?: PartialPrettierExtendedOptions -} - export interface OptionsComponentExts { /** * Additional extensions for components. @@ -108,12 +63,6 @@ export interface OptionsHasTypeScript { typescript?: boolean } -export interface OptionsStylistic { - stylistic?: boolean | StylisticConfig -} - -export interface StylisticConfig extends Pick {} - export interface OptionsIsInEditor { isInEditor?: boolean } @@ -142,22 +91,7 @@ export interface OptionsUnoCSS extends OptionsOverrides { strict?: boolean } -export interface OptionsVue extends OptionsOverrides { - /** - * Create virtual files for Vue SFC blocks to enable linting. - * - * @see https://github.com/antfu/eslint-processor-vue-blocks - * @default true - */ - sfcBlocks?: boolean | VueBlocksOptions - - /** - * The vue version - * - * @default 3 - */ - version?: 2 | 3 -} +export interface OptionsVue extends OptionsOverrides {} export interface OptionsConfig extends OptionsComponentExts { /** @@ -191,15 +125,6 @@ export interface OptionsConfig extends OptionsComponentExts { */ typescript?: boolean | OptionsTypescript - /** - * Enable JSX related rules. - * - * Currently only stylistic rules are included. - * - * @default true - */ - jsx?: boolean - /** * Enable test support. * @@ -260,14 +185,6 @@ export interface OptionsConfig extends OptionsComponentExts { */ unocss?: boolean | OptionsUnoCSS - /** - * Enable stylistic rules. - * - * @see https://eslint.style/ - * @default true - */ - stylistic?: boolean | (StylisticConfig & OptionsOverrides) - /** * Enable regexp rules. * @@ -276,23 +193,6 @@ export interface OptionsConfig extends OptionsComponentExts { */ regexp?: boolean | (OptionsRegExp & OptionsOverrides) - /** - * Use external formatters to format files. - * - * @default - * { - * "html": true, - * "css": true, - * "graphql": false, - * "markdown": false - * "yaml": false - * "toml": false - * } - * - * When set to `true`, it will enable all formatters. - */ - formatter?: boolean | OptionsFormatters - /** * Control to disable some rules in editors. * @default auto-detect based on the process.env diff --git a/src/types/rule.ts b/src/types/rule.ts index fc49bc84..cd3f0043 100644 --- a/src/types/rule.ts +++ b/src/types/rule.ts @@ -17,142 +17,3 @@ export type TypedFlatConfigItem = Omit< */ plugins?: Record } - -export type BuiltInParserName = - | 'acorn' - | 'angular' - | 'babel-flow' - | 'babel-ts' - | 'babel' - | 'css' - | 'espree' - | 'flow' - | 'glimmer' - | 'graphql' - | 'html' - | 'json-stringify' - | 'json' - | 'json5' - | 'less' - | 'lwc' - | 'markdown' - | 'mdx' - | 'meriyah' - | 'scss' - | 'typescript' - | 'vue' - | 'xml' - | 'yaml' - -type PrettierCustomParser = 'toml' -export type PrettierParser = BuiltInParserName | PrettierCustomParser - -export type LiteralUnion = - | T - | (Pick & { _?: never | undefined }) - -interface RequiredOptions { - /** - * Specify the line length that the printer will wrap on. - * @default 120 - */ - printWidth: number - /** - * Specify the number of spaces per indentation-level. - */ - tabWidth: number - /** - * Indent lines with tabs instead of spaces - */ - useTabs?: boolean - /** - * Print semicolons at the ends of statements. - */ - semi: boolean - /** - * Use single quotes instead of double quotes. - */ - singleQuote: boolean - /** - * Use single quotes in JSX. - */ - jsxSingleQuote: boolean - /** - * Print trailing commas wherever possible. - */ - trailingComma: 'none' | 'es5' | 'all' - /** - * Print spaces between brackets in object literals. - */ - bracketSpacing: boolean - /** - * Put the `>` of a multi-line HTML (HTML, XML, JSX, Vue, Angular) element at the end of the last line instead of being - * alone on the next line (does not apply to self closing elements). - */ - bracketSameLine: boolean - /** - * Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line. - * @deprecated use bracketSameLine instead - */ - jsxBracketSameLine: boolean - /** - * Format only a segment of a file. - */ - rangeStart: number - /** - * Format only a segment of a file. - * @default Number.POSITIVE_INFINITY - */ - rangeEnd: number - /** - * By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer. - * In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out. - * @default "preserve" - */ - proseWrap: 'always' | 'never' | 'preserve' - /** - * Include parentheses around a sole arrow function parameter. - * @default "always" - */ - arrowParens: 'avoid' | 'always' - /** - * Provide ability to support new languages to prettier. - */ - plugins: Array - /** - * How to handle whitespaces in HTML. - * @default "css" - */ - htmlWhitespaceSensitivity: 'css' | 'strict' | 'ignore' - /** - * Which end of line characters to apply. - * @default "lf" - */ - endOfLine: 'auto' | 'lf' | 'crlf' | 'cr' - /** - * Change when properties in objects are quoted. - * @default "as-needed" - */ - quoteProps: 'as-needed' | 'consistent' | 'preserve' - /** - * Whether or not to indent the code inside