-
Notifications
You must be signed in to change notification settings - Fork 5
/
lint.js
49 lines (41 loc) · 1.33 KB
/
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
const { existsSync, readFileSync } = require('fs');
const { CLIEngine } = require('eslint');
const mri = require('mri');
const paths = require('../config/paths');
const baseConfig = require(paths.selfESLintConfig);
function getGlobPatternsToIgnore(ignorePath) {
const contents = readFileSync(ignorePath, { encoding: 'utf8' });
return contents.split('\n').filter(Boolean);
}
const args = mri(process.argv.slice(2), {
boolean: 'check',
});
const subcommandOrTarget = args._[args._.length - 1];
const hasTarget = subcommandOrTarget !== 'lint';
const target = hasTarget ? subcommandOrTarget : paths.projectRoot;
const hasIgnoreOverride = existsSync(paths.projectESLintIgnore);
const ignorePath = hasIgnoreOverride
? paths.projectESLintIgnore
: paths.selfESLintIgnore;
const ignorePattern = getGlobPatternsToIgnore(ignorePath);
const engine = new CLIEngine({
cwd: paths.projectRoot,
baseConfig,
ignorePattern,
useEslintrc: false,
fix: !args.check,
});
const report = engine.executeOnFiles([target]);
let errorCount = report.errorCount;
if (!args.check) {
// Write any fixes to disk
CLIEngine.outputFixes(report);
errorCount -= report.fixableErrorCount;
}
// Print the linting results
const formatter = CLIEngine.getFormatter();
const output = formatter(report.results);
console.log(output);
if (errorCount > 0) {
process.exit(1);
}