From 5595264344cf3b23255227c9abaf5ec2f5367090 Mon Sep 17 00:00:00 2001 From: Neko Date: Wed, 2 Aug 2023 15:55:37 +0800 Subject: [PATCH 1/3] fix: parser in FlatConfig should be an object --- src/flat-config/language-options.d.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/flat-config/language-options.d.ts b/src/flat-config/language-options.d.ts index 123cb880..2b2f75fd 100644 --- a/src/flat-config/language-options.d.ts +++ b/src/flat-config/language-options.d.ts @@ -1,9 +1,5 @@ -import type { - EcmaVersion, - Parser, - ParserOptions, - SourceType, -} from '../parser-options'; +import type { Linter } from 'eslint'; +import type { EcmaVersion, ParserOptions, SourceType } from '../parser-options'; /** * An object containing settings related to how JavaScript is configured for linting @@ -43,7 +39,7 @@ export interface LanguageOptions { * * @see [Configuring a custom parser and its options](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuring-a-custom-parser-and-its-options) */ - parser?: Parser; + parser?: Linter.ParserModule; /** * An object specifying additional options that are passed directly to the `parser()` method on the parser. The available options are parser-dependent. From 621213494986a4207342d772e1f56488a4439d7e Mon Sep 17 00:00:00 2001 From: Neko Date: Wed, 2 Aug 2023 16:01:26 +0800 Subject: [PATCH 2/3] refactor: update comment --- src/flat-config/language-options.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flat-config/language-options.d.ts b/src/flat-config/language-options.d.ts index 2b2f75fd..5aab057a 100644 --- a/src/flat-config/language-options.d.ts +++ b/src/flat-config/language-options.d.ts @@ -33,7 +33,7 @@ export interface LanguageOptions { >; /** - * Either an object containing a `parse()` method or a string indicating the name of a parser inside of a plugin (i.e., `"pluginName/parserName"`). + * An object containing a parse() or parseForESLint() method. * * @default "@/espree" * From d44a4e5353453f06ad434817e7b1993008ba2f30 Mon Sep 17 00:00:00 2001 From: Neko Date: Thu, 3 Aug 2023 11:32:56 +0800 Subject: [PATCH 3/3] refactor: manually define ParserModule --- src/flat-config/language-options.d.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/flat-config/language-options.d.ts b/src/flat-config/language-options.d.ts index 5aab057a..d18a4cd7 100644 --- a/src/flat-config/language-options.d.ts +++ b/src/flat-config/language-options.d.ts @@ -1,5 +1,19 @@ -import type { Linter } from 'eslint'; -import type { EcmaVersion, ParserOptions, SourceType } from '../parser-options'; +import type { + EcmaVersion, + Parser, + ParserOptions, + SourceType, +} from '../parser-options'; + +export type ParserModule = + | { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + parse(text: string, options?: any): any; + } + | { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + parseForESLint(text: string, options?: any): any; + }; /** * An object containing settings related to how JavaScript is configured for linting @@ -33,13 +47,13 @@ export interface LanguageOptions { >; /** - * An object containing a parse() or parseForESLint() method. + * Either an object containing a `parse()` method or a string indicating the name of a parser inside of a plugin (i.e., `"pluginName/parserName"`). * * @default "@/espree" * * @see [Configuring a custom parser and its options](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#configuring-a-custom-parser-and-its-options) */ - parser?: Linter.ParserModule; + parser?: Parser | ParserModule; /** * An object specifying additional options that are passed directly to the `parser()` method on the parser. The available options are parser-dependent.