Update eslint.FlatConfig to remove string alternatives from files and ignores and expand type to cover all accepted values (functions and nested arrays) (#65530)

This commit is contained in:
Matt Wilkinson
2023-06-08 21:23:47 +01:00
committed by GitHub
parent 0c7cc4248d
commit e860dd706f
2 changed files with 33 additions and 2 deletions

View File

@@ -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

View File

@@ -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<FlatConfigFileSpec | FlatConfigFileSpec[]>;
/**
* 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.