-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
es-lint.js
executable file
·49 lines (40 loc) · 1.5 KB
/
es-lint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
/**
* @license Copyright 2019 Palantir Technologies, Inc. All rights reserved.
* @fileoverview Runs ESLint, with support for generating JUnit report
*/
// @ts-check
"use strict";
const path = require("path");
const fs = require("fs");
const { junitReportPath } = require("./utils");
const { spawn, execSync } = require("child_process");
const glob = require("glob");
let format = "codeframe";
let out;
let outputStream = process.stdout;
if (process.env.JUNIT_REPORT_PATH != null) {
format = "junit";
out = junitReportPath("eslint");
console.info(`TSLint report will appear in ${out}`);
outputStream = fs.createWriteStream(out, { flags: "w+" });
}
const gitRoot = execSync("git rev-parse --show-toplevel").toString().trim();
const commandLineOptions = ["-c", path.join(gitRoot, "./.eslintrc.json"), "--color", "-f", format];
if (process.argv.includes("--fix")) {
commandLineOptions.push("--fix")
}
// ESLint will fail if provided with no files, so we expand the glob before running it
const fileGlob = "{src,test}/**/*.tsx";
const absoluteFileGlob = path.resolve(process.cwd(), fileGlob);
const anyFilesToLint = glob.sync(absoluteFileGlob)
if (anyFilesToLint.length === 0) {
console.log(`Not running ESLint because no files match the glob "${fileGlob}"`)
process.exit();
}
const eslint = spawn("eslint", [...commandLineOptions, absoluteFileGlob]);
eslint.stdout.pipe(outputStream);
eslint.stderr.pipe(process.stderr);
eslint.on("close", code => {
process.exitCode = code;
});