diff --git a/types/eslint/eslint-tests.ts b/types/eslint/eslint-tests.ts index 460703dd59..44642aef3e 100644 --- a/types/eslint/eslint-tests.ts +++ b/types/eslint/eslint-tests.ts @@ -1007,4 +1007,32 @@ ruleTester.run('simple-valid-test', rule, { } }); +(): Linter.FlatConfig => ({ files: ["abc"] }); +(): Linter.FlatConfig => ({ files: [(path) => false] }); +(): Linter.FlatConfig => ({ files: [["abc"]]}); +(): Linter.FlatConfig => ({ files: [[(path) => false]] }); +(): Linter.FlatConfig => ({ files: [["abc", (path) => false]] }); +(): Linter.FlatConfig => ({ files: ["abc", (path) => false, ["abc"], [(path) => false], ["abc", (path) => false]] }); + +// @ts-expect-error // Second level of nesting is not allowed +(): Linter.FlatConfig => ({ files: ["abc", (path) => false, ["abc"], [(path) => false], ["abc", (path) => false], [["abc"], [(path) => false]]] }); + +(): Linter.FlatConfig => ({ ignores: ["abc"] }); +(): Linter.FlatConfig => ({ ignores: [(path) => false] }); +(): Linter.FlatConfig => ({ ignores: ["abc", (path) => false] }); + +// @ts-expect-error // No nesting +(): Linter.FlatConfig => ({ ignores: ["abc", (path) => false, ["abc"], [(path) => false], ["abc", (path) => false]] }); + +// @ts-expect-error // Must be an array +(): Linter.FlatConfig => ({ files: "abc" }); + +// @ts-expect-error // Must be an array +(): Linter.FlatConfig => ({ ignores: "abc" }); + +// The following _should_ be an error, but we can't enforce on consumers +// as it requires exactOptionalPropertyTypes: true +// (): Linter.FlatConfig => ({ files: undefined }); +// (): Linter.FlatConfig => ({ ignores: undefined }); + //#endregion diff --git a/types/eslint/index.d.ts b/types/eslint/index.d.ts index 504e5a8730..255cbcca0f 100644 --- a/types/eslint/index.d.ts +++ b/types/eslint/index.d.ts @@ -933,19 +933,22 @@ export namespace Linter { preprocess?(text: string, filename: string): T[]; postprocess?(messages: LintMessage[][], filename: string): LintMessage[]; } + + type FlatConfigFileSpec = string | ((filePath: string) => boolean); + interface FlatConfig { /** * An array of glob patterns indicating the files that the configuration * object should apply to. If not specified, the configuration object applies * to all files */ - files?: string | string[]; + files?: Array; /** * An array of glob patterns indicating the files that the configuration * object should not apply to. If not specified, the configuration object * applies to all files matched by files */ - ignores?: string | string[]; + ignores?: FlatConfigFileSpec[]; /** * An object containing settings related to how JavaScript is configured for * linting.