Skip to content

Commit 861c6da

Browse files
authored
fix: correct ESLint typings (#20122)
* fix: correct `ESLint` typings * add tests * clarify `DeprecatedRuleUse.info` behavior
1 parent 347906d commit 861c6da

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/types/index.d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ export class ESLint {
19631963

19641964
calculateConfigForFile(filePath: string): Promise<any>;
19651965

1966-
findConfigFile(): Promise<string | undefined>;
1966+
findConfigFile(filePath?: string): Promise<string | undefined>;
19671967

19681968
isPathIgnored(filePath: string): Promise<boolean>;
19691969

@@ -2045,7 +2045,7 @@ export namespace ESLint {
20452045

20462046
// Autofix
20472047
fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
2048-
fixTypes?: FixType[] | undefined;
2048+
fixTypes?: FixType[] | null | undefined;
20492049

20502050
// Cache-related
20512051
cache?: boolean | undefined;
@@ -2079,7 +2079,7 @@ export namespace ESLint {
20792079

20802080
// Autofix
20812081
fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
2082-
fixTypes?: FixType[] | undefined;
2082+
fixTypes?: FixType[] | null | undefined;
20832083

20842084
// Cache-related
20852085
cache?: boolean | undefined;
@@ -2168,9 +2168,10 @@ export namespace ESLint {
21682168

21692169
/**
21702170
* The raw deprecated info provided by the rule.
2171-
* Unset if the rule's `meta.deprecated` property is a boolean.
2171+
* - Undefined if the rule's `meta.deprecated` property is a boolean.
2172+
* - Unset when using the legacy eslintrc configuration.
21722173
*/
2173-
info?: DeprecatedInfo;
2174+
info?: DeprecatedInfo | undefined;
21742175
}
21752176

21762177
/**

tests/lib/types/types.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,7 @@ linterWithEslintrcConfig.getRules();
15071507
eslint = new ESLint({ fix: true });
15081508
eslint = new ESLint({ fix: message => false });
15091509
eslint = new ESLint({ fixTypes: ["directive", "problem"] });
1510+
eslint = new ESLint({ fixTypes: null });
15101511
eslint = new ESLint({ flags: ["foo", "bar"] });
15111512
eslint = new ESLint({ globInputPaths: true });
15121513
eslint = new ESLint({ ignore: true });
@@ -1575,6 +1576,9 @@ linterWithEslintrcConfig.getRules();
15751576

15761577
eslint.calculateConfigForFile("./config.json");
15771578

1579+
eslint.findConfigFile("src/index.js");
1580+
eslint.findConfigFile();
1581+
15781582
eslint.isPathIgnored("./dist/index.js");
15791583

15801584
let formatterPromise: Promise<ESLint.Formatter>;
@@ -1655,6 +1659,7 @@ linterWithEslintrcConfig.getRules();
16551659
eslint = new LegacyESLint({ fix: true });
16561660
eslint = new LegacyESLint({ fix: message => false });
16571661
eslint = new LegacyESLint({ fixTypes: ["directive", "problem"] });
1662+
eslint = new LegacyESLint({ fixTypes: null });
16581663
eslint = new LegacyESLint({ flags: ["foo", "bar"] });
16591664
eslint = new LegacyESLint({ globInputPaths: true });
16601665
eslint = new LegacyESLint({ ignore: true });
@@ -1824,6 +1829,7 @@ for (const result of results) {
18241829
const deprecatedRule = result.usedDeprecatedRules[0];
18251830
deprecatedRule.ruleId = "foo";
18261831
deprecatedRule.replacedBy = ["bar"];
1832+
deprecatedRule.info = undefined;
18271833
deprecatedRule.info = {
18281834
message: "use bar instead",
18291835
replacedBy: [

0 commit comments

Comments
 (0)