Skip to content

Commit ba6ebfa

Browse files
authored
fix: correct typings for loadESLint() and shouldUseFlatConfig() (#20393)
* fix: correct typings for `loadESLint()` * wip: update `shouldUseFlatConfig` * wip: update JSDoc
1 parent a176319 commit ba6ebfa

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

lib/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const { SourceCode } = require("./languages/js/source-code");
1919
//-----------------------------------------------------------------------------
2020

2121
/**
22-
* Loads the correct ESLint constructor given the options.
23-
* @returns {Promise<ESLint>} The ESLint constructor
22+
* Loads the correct `ESLint` constructor.
23+
* @returns {Promise<ESLint>} The ESLint constructor.
2424
*/
2525
async function loadESLint() {
2626
return ESLint;

lib/eslint/eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ class ESLint {
13461346

13471347
/**
13481348
* Returns whether flat config should be used.
1349-
* @returns {Promise<boolean>} Whether flat config should be used.
1349+
* @returns {Promise<true>} Whether flat config should be used.
13501350
*/
13511351
async function shouldUseFlatConfig() {
13521352
return true;

lib/types/index.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export namespace AST {
115115
end: ESTree.Position;
116116
}
117117

118-
type Range = [number, number];
118+
type Range = SourceRange;
119119

120120
interface Program extends ESTree.Program {
121121
comments: ESTree.Comment[];
@@ -1344,9 +1344,10 @@ export namespace ESLint {
13441344

13451345
// #endregion
13461346

1347-
export function loadESLint(options?: {
1348-
useFlatConfig?: boolean | undefined;
1349-
}): Promise<typeof ESLint>;
1347+
/**
1348+
* Loads the correct `ESLint` constructor.
1349+
*/
1350+
export function loadESLint(): Promise<typeof ESLint>;
13501351

13511352
// #region RuleTester
13521353

lib/types/use-at-your-own-risk.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ import { Rule } from "./index.js";
3131
export const builtinRules: Map<string, Rule.RuleModule>;
3232

3333
/** @deprecated */
34-
export function shouldUseFlatConfig(): Promise<boolean>;
34+
export function shouldUseFlatConfig(): Promise<true>;

tests/lib/types/types.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,11 +2302,16 @@ flatConfigWithRules.rules; // $ExpectType Partial<ESLintRules> | undefined
23022302

23032303
async (useFlatConfig?: boolean) => {
23042304
await loadESLint(); // $ExpectType typeof ESLint
2305-
await loadESLint({}); // $ExpectType typeof ESLint
2306-
await loadESLint({ useFlatConfig: undefined }); // $ExpectType typeof ESLint
2307-
await loadESLint({ useFlatConfig: true }); // $ExpectType typeof ESLint
2308-
await loadESLint({ useFlatConfig: false }); // $ExpectType typeof ESLint
2309-
await loadESLint({ useFlatConfig }); // $ExpectType typeof ESLint
2305+
// @ts-expect-error `loadESLint()` does not accept arguments since ESLint v10.0.0
2306+
await loadESLint({});
2307+
// @ts-expect-error `loadESLint()` does not accept arguments since ESLint v10.0.0
2308+
await loadESLint({ useFlatConfig: undefined });
2309+
// @ts-expect-error `loadESLint()` does not accept arguments since ESLint v10.0.0
2310+
await loadESLint({ useFlatConfig: true });
2311+
// @ts-expect-error `loadESLint()` does not accept arguments since ESLint v10.0.0
2312+
await loadESLint({ useFlatConfig: false });
2313+
// @ts-expect-error `loadESLint()` does not accept arguments since ESLint v10.0.0
2314+
await loadESLint({ useFlatConfig });
23102315

23112316
const DefaultESLint = await loadESLint();
23122317
if (DefaultESLint.configType === "flat") {
@@ -2318,7 +2323,7 @@ async (useFlatConfig?: boolean) => {
23182323

23192324
builtinRules; // $ExpectType Map<string, RuleModule>
23202325

2321-
shouldUseFlatConfig(); // $ExpectType Promise<boolean>
2326+
shouldUseFlatConfig(); // $ExpectType Promise<true>
23222327

23232328
// #endregion
23242329

0 commit comments

Comments
 (0)