File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -4,22 +4,32 @@ import type { Linter } from 'eslint'
44import type { ESLintConfigGenAddon } from '../../../types'
55
66export function createAddonGlobals ( nuxt : Nuxt ) : ESLintConfigGenAddon {
7- let unimport : Unimport
7+ let unimport : Unimport | undefined
8+ let nitroUnimport : Unimport | undefined
89
910 nuxt . hook ( 'imports:context' , ( context ) => {
1011 unimport = context
1112 } )
1213
14+ nuxt . hook ( 'nitro:init' , ( nitro ) => {
15+ nitroUnimport = nitro . unimport
16+ } )
17+
1318 return {
1419 name : 'nuxt:eslint:import-globals' ,
1520 async getConfigs ( ) {
21+ const imports = [
22+ ...await unimport ?. getImports ( ) || [ ] ,
23+ ...await nitroUnimport ?. getImports ( ) || [ ] ,
24+ ]
25+
1626 return {
1727 configs : [
18- '// Set globals from imports registry\n'
19- + JSON . stringify ( < Linter . Config > {
28+ '// Set globals from imports registry' ,
29+ JSON . stringify ( < Linter . Config > {
2030 name : 'nuxt/import-globals' ,
2131 languageOptions : {
22- globals : Object . fromEntries ( ( await unimport . getImports ( ) ) . map ( i => [ i . as || i . name , 'readonly' ] ) ) ,
32+ globals : Object . fromEntries ( imports . map ( i => [ i . as || i . name , 'readonly' ] ) ) ,
2333 } ,
2434 } ) ,
2535 ] ,
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ export interface ESLintConfigGenAddonResult {
123123 */
124124 imports ?: Import [ ]
125125 /**
126- * Flat config items, should be stringified
126+ * Flat config items, should be stringified lines
127127 */
128128 configs ?: string [ ]
129129}
You can’t perform that action at this time.
0 commit comments