2022-07-25 18:49:55 +03:00
|
|
|
const { ESLint } = require("eslint");
|
|
|
|
const packagePath = process.cwd();
|
|
|
|
|
|
|
|
(async function main() {
|
|
|
|
// 1. Create an instance.
|
|
|
|
const eslint = new ESLint({
|
|
|
|
cwd: packagePath,
|
2022-09-05 01:55:42 +03:00
|
|
|
baseConfig: require("../config/eslintrc.js"),
|
2022-07-25 18:49:55 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// 2. Lint files.
|
2022-08-02 00:13:30 +03:00
|
|
|
const results = await eslint.lintFiles(["src/**/*.ts"]);
|
2022-07-25 18:49:55 +03:00
|
|
|
|
|
|
|
// 3. Format the results.
|
|
|
|
const formatter = await eslint.loadFormatter("stylish");
|
|
|
|
const resultText = formatter.format(results);
|
|
|
|
|
|
|
|
// 4. Output it.
|
|
|
|
console.log(resultText);
|
2022-09-05 01:55:42 +03:00
|
|
|
|
|
|
|
if (results.some((r) => r.errorCount > 0)) {
|
|
|
|
throw new Error(`Linting failed with ${results[0].errorCount} errors`);
|
|
|
|
}
|
2022-07-25 18:49:55 +03:00
|
|
|
})().catch((error) => {
|
|
|
|
process.exitCode = 1;
|
|
|
|
console.error(error);
|
|
|
|
});
|