79129037

Date: 2024-10-26 16:58:39
Score: 0.5
Natty:
Report link

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);
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Zymotik's
  • Low reputation (0.5):
Posted by: Adam Fanello