Skip to content

Commit

Permalink
feat: integrate with eslint-typegen
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 27, 2024
1 parent 3127d3f commit d2b1c2d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 13 additions & 1 deletion packages/module/src/modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export async function setupConfigGen(options: ModuleOptions, nuxt: Nuxt) {
createAddonGlobals(nuxt),
]

nuxt.hook('prepare:types', ({ declarations }) => {
declarations.push('/// <reference path="./eslint-typegen.d.ts" />')
})

addTemplate({
filename: 'eslint.config.mjs',
write: true,
Expand Down Expand Up @@ -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'
}
)

Expand All @@ -88,7 +97,10 @@ async function generateESLintConfig(options: ModuleOptions, nuxt: Nuxt, addons:

return [
'// ESLint config generated by Nuxt',
'/// <reference path="./eslint-typegen.d.ts" />',
'',
stringifyImports(importLines, false),
'',
'export { defineFlatConfigs }',
'',
`export const configs = pipe()`,
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion playground/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @ts-check
import withNuxt from './.nuxt/eslint.config.mjs'

export default withNuxt()
export default withNuxt({})
47 changes: 40 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2b1c2d

Please sign in to comment.