31 lines
675 B
JavaScript
31 lines
675 B
JavaScript
const { ESLint } = require("eslint");
|
|
|
|
function readStdin() {
|
|
return new Promise((resolve) => {
|
|
let data = "";
|
|
process.stdin.setEncoding("utf8");
|
|
process.stdin.on("readable", () => {
|
|
let chunk;
|
|
while ((chunk = process.stdin.read())) {
|
|
data += chunk;
|
|
}
|
|
});
|
|
process.stdin.on("end", () => {
|
|
resolve(data);
|
|
});
|
|
});
|
|
}
|
|
|
|
(async function () {
|
|
const [file] = process.argv.slice(3);
|
|
|
|
const eslint = new ESLint({ fix: true });
|
|
const code = await readStdin();
|
|
|
|
const results = await eslint.lintText(code, { filePath: file });
|
|
|
|
const fixedResult =
|
|
results[0] && results[0].output ? results[0].output : code;
|
|
|
|
process.stdout.write(fixedResult);
|
|
})();
|