Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eslint] Support async formatters #58333

Merged
merged 1 commit into from Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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