Skip to content

Commit

Permalink
fix(eslint-config): do not eagerly import ts-eslint parser, close #485
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 22, 2024
1 parent bbd812e commit 4b5d65c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/eslint-config/src/flat/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import type { Linter } from 'eslint'
import type { NuxtESLintConfigOptions } from '@nuxt/eslint-config/flat'
import { resolveOptions } from '../utils'

export { parserTs, pluginTs }

export default function typescript(options: NuxtESLintConfigOptions): Linter.Config[] {
const resolved = resolveOptions(options)

Expand Down
10 changes: 6 additions & 4 deletions packages/eslint-config/src/flat/configs/vue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as parserVue from 'vue-eslint-parser'
import parserTs from '@typescript-eslint/parser'

// @ts-expect-error missing types
import pluginVue from 'eslint-plugin-vue'
import type { Linter } from 'eslint'
Expand All @@ -10,10 +8,14 @@ import { removeUndefined, resolveOptions } from '../utils'
// imported from 'eslint-plugin-vue/lib/utils/inline-non-void-elements.json'
const INLINE_ELEMENTS = ['a', 'abbr', 'audio', 'b', 'bdi', 'bdo', 'canvas', 'cite', 'code', 'data', 'del', 'dfn', 'em', 'i', 'iframe', 'ins', 'kbd', 'label', 'map', 'mark', 'noscript', 'object', 'output', 'picture', 'q', 'ruby', 's', 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'svg', 'time', 'u', 'var', 'video']

export default function vue(options: NuxtESLintConfigOptions): Linter.Config[] {
export default async function vue(options: NuxtESLintConfigOptions): Promise<Linter.Config[]> {
const resolved = resolveOptions(options)
const hasTs = resolved.features.typescript !== false

const parser = hasTs
? await import('./typescript').then(mod => mod.parserTs)
: undefined

const {
indent = 2,
commaDangle = 'always-multiline',
Expand All @@ -30,7 +32,7 @@ export default function vue(options: NuxtESLintConfigOptions): Linter.Config[] {
parserOptions: {
ecmaVersion: 'latest',
extraFileExtensions: ['.vue'],
parser: hasTs ? parserTs : undefined,
parser,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
Expand Down

1 comment on commit 4b5d65c

@Revadike
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.