@pega/custom-dx-components
Version:
Utility for building custom UI components
52 lines (38 loc) • 1.46 kB
JavaScript
import { ESLint } from 'eslint';
import chalk from 'chalk';
// import { addDebugLog } from '../../util.js';
export const lintComponent = async dirToLint => {
// addDebugLog("lintComponent", `dirToLint: ${dirToLint}`);
// console.log("in dx-component-builder-sdk: lintComponent - dirToLint: " + dirToLint);
console.log(chalk.green(` linting ${dirToLint}`));
// 1. Create an instance.
const eslint = new ESLint();
// 2. Lint files.
const results = await eslint.lintFiles([dirToLint]);
// 3. Format the results.
const formatter = await eslint.loadFormatter('stylish');
const resultText = formatter.format(results);
// Indicate linting is complete
console.log(chalk.green(` linting complete...`));
if (resultText.length > 0 && resultText.indexOf('error') >= 0) {
throw new Error(`Lint:\n${resultText}`);
} else {
console.log(resultText);
}
};
// inspired by https://eslint.org/docs/latest/developer-guide/nodejs-api
// (async function main() {
// // 1. Create an instance.
// const eslint = new ESLint();
// // 2. Lint files.
// const results = await eslint.lintFiles(["lib/**/*.js"]);
// // 3. Format the results.
// const formatter = await eslint.loadFormatter("stylish");
// const resultText = formatter.format(results);
// // 4. Output it.
// console.log(resultText);
// })().catch((error) => {
// process.exitCode = 1;
// console.error(error);
// });
export default lintComponent;