forked from Synthetixio/synpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.js
42 lines (32 loc) · 984 Bytes
/
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
const fs = require('fs');
const CLIEngine = require('eslint').CLIEngine;
const argv = process.argv.slice(2);
const cli = new CLIEngine({
fix: false,
extensions: argv[2].split(','),
useEslintrc: true,
});
console.log('Starting to lint..');
// Lint all files
const report = cli.executeOnFiles(argv[0]);
// get the default formatter
const consoleFormatter = cli.getFormatter();
console.log('Lint finished');
// output to console
console.log(consoleFormatter(report.results));
// Output to sarif format
const otherFormatter = cli.getFormatter(
'@microsoft/eslint-formatter-sarif/sarif.js',
);
console.log('Saving sarif report..');
const filePath = argv[4] ? argv[4] : 'lint-results.sarif';
fs.writeFile(filePath, otherFormatter(report.results), 'utf8', () => {
console.log('Sarif report saved');
if (report.errorCount > 0) {
console.log('Errors found, exiting..');
process.exit(1);
} else {
console.log('No errors found');
process.exit(0);
}
});