bridge-node-server/eslint-for-arc.js
Martin Donnelly 57bd6c8e6a init
2018-06-24 21:15:03 +01:00

37 lines
1.3 KiB
JavaScript

/**
* @fileOverview There is a compatibility problem between eslint and arcanist.
* ESLint returns a non-zero code on exit if there are any lint errors
* in the file. But `arc` regex liniters expect to only get an
* non-zero exit code on true errors (e.g. eslint config errors).
*
* So we use this file and the ESLint API to build a version that
* only returns non-zero on actual errors (which will be unhandled
* exceptions, so we don't actually need to do anything to achieve)
*/
const CLIEngine = require('eslint').CLIEngine;
const cli = new CLIEngine();
/**
* Get the file to lint from the command line. The command line is always
* argv[0] - node exe
* argv[1] - this script
* argv[2] - the file passed on the command line
*/
if (process.argv.length !== 3) {
throw new Error('Must pass exactly 1 file on the command line');
}
const filename = process.argv[2];
// Lint the file passed in
const report = cli.executeOnFiles([filename]);
// Get the compact formatter
const formatter = cli.getFormatter('compact');
// Output to stdout so it can be picked up by the arcanist regex
process.stdout.write(formatter(report.results));
// Allow the program to exit normally, which will return code 0