From d2b1c2dabf19997300a6faced42e4c693fc8641d Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 28 Mar 2024 00:42:14 +0100 Subject: [PATCH] feat: integrate with `eslint-typegen` --- packages/eslint-config/package.json | 4 +-- packages/module/package.json | 1 + packages/module/src/modules/config.ts | 14 +++++++- playground/eslint.config.js | 2 +- pnpm-lock.yaml | 47 +++++++++++++++++++++++---- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 2b5e41ce..8b9fa8e5 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -29,14 +29,14 @@ "dependencies": { "@eslint/js": "^8.57.0", "@nuxt/eslint-plugin": "workspace:*", - "@rushstack/eslint-patch": "^1.8.0", + "@rushstack/eslint-patch": "^1.9.0", "@stylistic/eslint-plugin": "^1.7.0", "@typescript-eslint/eslint-plugin": "^7.4.0", "@typescript-eslint/parser": "^7.4.0", + "eslint-flat-config-utils": "^0.1.0", "eslint-plugin-vue": "^9.24.0", "globals": "^15.0.0", "pathe": "^1.1.2", - "eslint-flat-config-utils": "^0.1.0", "vue-eslint-parser": "^9.4.2" }, "devDependencies": { diff --git a/packages/module/package.json b/packages/module/package.json index a102e566..a98a72bf 100644 --- a/packages/module/package.json +++ b/packages/module/package.json @@ -51,6 +51,7 @@ "eslint-flat-config-utils": "^0.1.0", "eslint-flat-config-viewer": "^0.1.14", "get-port-please": "^3.1.2", + "eslint-typegen": "^0.1.4", "pathe": "^1.1.2", "unimport": "^3.7.1" }, diff --git a/packages/module/src/modules/config.ts b/packages/module/src/modules/config.ts index 50708b70..64a60f85 100644 --- a/packages/module/src/modules/config.ts +++ b/packages/module/src/modules/config.ts @@ -14,6 +14,10 @@ export async function setupConfigGen(options: ModuleOptions, nuxt: Nuxt) { createAddonGlobals(nuxt), ] + nuxt.hook('prepare:types', ({ declarations }) => { + declarations.push('/// ') + }) + addTemplate({ filename: 'eslint.config.mjs', write: true, @@ -65,6 +69,11 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons: { from: '@nuxt/eslint-config/flat', name: 'defineFlatConfigs', + }, + { + from: 'eslint-typegen', + name: 'default', + as: 'typegen' } ) @@ -88,7 +97,10 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons: return [ '// ESLint config generated by Nuxt', + '/// ', + '', stringifyImports(importLines, false), + '', 'export { defineFlatConfigs }', '', `export const configs = pipe()`, @@ -98,7 +110,7 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons: `)`, '', 'export function withNuxt(...customs) {', - ' return configs.append(...customs)', + ' return configs.append(...customs).onResolved(configs => typegen(configs, { dtsPath: new URL("./eslint-typegen.d.ts", import.meta.url) }))', '}', '', 'export default withNuxt', diff --git a/playground/eslint.config.js b/playground/eslint.config.js index f1685e31..590b4c56 100644 --- a/playground/eslint.config.js +++ b/playground/eslint.config.js @@ -1,4 +1,4 @@ // @ts-check import withNuxt from './.nuxt/eslint.config.mjs' -export default withNuxt() +export default withNuxt({}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b3f728a..e6b56b57 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -103,8 +103,8 @@ importers: specifier: workspace:* version: link:../eslint-plugin '@rushstack/eslint-patch': - specifier: ^1.8.0 - version: 1.8.0 + specifier: ^1.9.0 + version: 1.9.0 '@stylistic/eslint-plugin': specifier: ^1.7.0 version: 1.7.0(eslint@8.57.0)(typescript@5.4.3) @@ -114,6 +114,9 @@ importers: '@typescript-eslint/parser': specifier: ^7.4.0 version: 7.4.0(eslint@8.57.0)(typescript@5.4.3) + eslint-flat-config-utils: + specifier: ^0.1.0 + version: 0.1.0 eslint-plugin-vue: specifier: ^9.24.0 version: 9.24.0(eslint@8.57.0) @@ -133,9 +136,6 @@ importers: eslint: specifier: ^8.57.0 version: 8.57.0 - eslint-flat-config-utils: - specifier: ^0.1.0 - version: 0.1.0 typescript: specifier: ^5.4.3 version: 5.4.3 @@ -178,6 +178,9 @@ importers: eslint-flat-config-viewer: specifier: ^0.1.14 version: 0.1.14(eslint@8.57.0)(typescript@5.4.3) + eslint-typegen: + specifier: ^0.1.4 + version: 0.1.4 get-port-please: specifier: ^3.1.2 version: 3.1.2 @@ -229,6 +232,15 @@ packages: /@antfu/utils@0.7.7: resolution: {integrity: sha512-gFPqTG7otEJ8uP6wrhDv6mqwGWYZKNvAcCq6u9hOj0c+IKCEsY4L1oC9trPq2SaWIzAfHvqfBDxF591JkMf+kg==} + /@apidevtools/json-schema-ref-parser@11.5.4: + resolution: {integrity: sha512-o2fsypTGU0WxRxbax8zQoHiIB4dyrkwYfcm8TxZ+bx9pCzcWZbQtiMqpgBvWA/nJ2TrGjK5adCLfTH8wUeU/Wg==} + engines: {node: '>= 16'} + dependencies: + '@jsdevtools/ono': 7.1.3 + '@types/json-schema': 7.0.15 + js-yaml: 4.1.0 + dev: false + /@babel/code-frame@7.23.5: resolution: {integrity: sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==} engines: {node: '>=6.9.0'} @@ -1027,6 +1039,10 @@ packages: type-detect: 4.0.8 dev: true + /@jsdevtools/ono@7.1.3: + resolution: {integrity: sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==} + dev: false + /@kwsites/file-exists@1.1.1: resolution: {integrity: sha512-m9/5YGR18lIwxSFDwfE3oA7bWuq9kdau6ugN4H2rJeyhFQZcG9AgSHkQtSD15a8WvTgfz9aikZMrKPHvbpqFiw==} dependencies: @@ -2131,8 +2147,8 @@ packages: requiresBuild: true optional: true - /@rushstack/eslint-patch@1.8.0: - resolution: {integrity: sha512-0HejFckBN2W+ucM6cUOlwsByTKt9/+0tWhqUffNIcHqCXkthY/mZ7AuYPK/2IIaGWhdl0h+tICDO0ssLMd6XMQ==} + /@rushstack/eslint-patch@1.9.0: + resolution: {integrity: sha512-AAWymnpvHbGty1BmgbdfbqQDboXs6xN6h2yAacO4yKVyyUUBnpYkp+P9jjPrV9zrAGw7JVVriRtGOHPInnfjZQ==} dev: false /@sigstore/bundle@2.2.0: @@ -4186,6 +4202,7 @@ packages: resolution: {integrity: sha512-GVjeM6BITHRpax/lLV8IEdsyIFHH0/4ggN3WJ3IcMTxKRmbo1pA8chPE/WP4sjvkEo8W6WaeIopUMhlzHYeP4g==} dependencies: '@types/eslint': 8.56.6 + dev: false /eslint-flat-config-viewer@0.1.14(eslint@8.57.0)(typescript@5.4.3): resolution: {integrity: sha512-2ErHkowC7N9jiLHYAEI7lrm9phEPkyuZTCbRjVmj3B9yk/zVHhLCSlPGWzkgAEDW2MQRGSkvlbbhD7C9FRhYXQ==} @@ -4414,6 +4431,14 @@ packages: esrecurse: 4.3.0 estraverse: 5.3.0 + /eslint-typegen@0.1.4: + resolution: {integrity: sha512-Sb/xFinq1B5ZmcM+OispI9BQbuS1gb058WSeads/40y0/iYjxLLng77Q6MZPzEcpYuP8vV2t5qsC1Ca2Plc19Q==} + dependencies: + '@types/eslint': 8.56.6 + json-schema-to-typescript-lite: 14.0.0 + ohash: 1.1.3 + dev: false + /eslint-visitor-keys@3.4.3: resolution: {integrity: sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -5458,6 +5483,14 @@ packages: resolution: {integrity: sha512-aatBvbL26wVUCLmbWdCpeu9iF5wOyWpagiKkInA+kfws3sWdBrTnsvN2CKcyCYyUrc7rebNBlK6+kteg7ksecg==} engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + /json-schema-to-typescript-lite@14.0.0: + resolution: {integrity: sha512-On0b6UdEgdotLzWk37yNId2wK77P7UfxuCWDEgduoz1VLR4rPbDcQGW6zlHVgL62Bq7gERq0JMmUyAjJigxYHg==} + engines: {node: '>=20.0.0'} + dependencies: + '@apidevtools/json-schema-ref-parser': 11.5.4 + '@types/json-schema': 7.0.15 + dev: false + /json-schema-traverse@0.4.1: resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==}