Skip to content

Commit

Permalink
馃 Merge PR #58333 [eslint] Support async formatters by @fasttime
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Jan 22, 2022
1 parent 15738a6 commit ff28e2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions types/eslint/eslint-tests.ts
Expand Up @@ -682,6 +682,9 @@ let formatterPromise: Promise<ESLint.Formatter>;
formatterPromise = eslint.loadFormatter("codeframe");
formatterPromise = eslint.loadFormatter();

const customFormatter1: ESLint.Formatter = { format: () => "ok" };
const customFormatter2: ESLint.Formatter = { format: () => Promise.resolve("ok") };

let data: ESLint.LintResultData;
const meta: Rule.RuleMetaData = {
type: "suggestion",
Expand All @@ -702,9 +705,12 @@ data = { cwd: "/foo/bar", rulesMeta: { "no-extra-semi": meta } };

const version: string = ESLint.version;

resultsPromise.then(results => {
formatterPromise.then(formatter => formatter.format(results));
formatterPromise.then(formatter => formatter.format(results, data));
(async () => {
const results = await resultsPromise;
const formatter = await formatterPromise;

const output1: string = await formatter.format(results);
const output2: string = await formatter.format(results, data);

eslint.getRulesMetaForResults(results);

Expand Down Expand Up @@ -732,7 +738,7 @@ resultsPromise.then(results => {
message.ruleId = "foo";
}
}
});
})();

//#endregion

Expand Down
2 changes: 1 addition & 1 deletion types/eslint/index.d.ts
Expand Up @@ -884,7 +884,7 @@ export namespace ESLint {
}

interface Formatter {
format(results: LintResult[], data?: LintResultData): string;
format(results: LintResult[], data?: LintResultData): string | Promise<string>;
}

// Docs reference the type by this name
Expand Down

0 comments on commit ff28e2b

Please sign in to comment.