As the @Zymotik's answer states, there are two answers: ESList Output and write your own. Since ESLint Output is unmaintained and no longer works, here's option #2:
import { ESLint } from "eslint";
import * as fs from "node:fs/promises";
import * as path from "node:path";
try {
const eslint = new ESLint({});
const results = await eslint.lintFiles(process.cwd());
await fs.writeFile(path.join(process.cwd(), "eslint-output.json"), JSON.stringify(results));
const hasProblems = results.some((result) => result.errorCount > 0 || result.warningCount > 0);
if (hasProblems) {
const metadata = {
cwd: process.cwd(),
rulesMeta: eslint.getRulesMetaForResults(results),
};
const formatter = await eslint.loadFormatter("stylish");
console.log(await formatter.format(results, metadata));
process.exit(1);
}
} catch (error) {
console.error(error);
process.exit(1);
}
process.exit(0);