/
lint.js
executable file
·61 lines (50 loc) · 1.64 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
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
'use strict';
const {ESLint} = require('eslint');
const unicorn = require('../..');
const {recommended} = unicorn.configs;
const files = [process.argv[2] || '.'];
const fix = process.argv.includes('--fix');
const eslint = new ESLint({
baseConfig: recommended,
useEslintrc: false,
plugins: {
unicorn
},
fix,
overrideConfig: {
ignorePatterns: [
'coverage',
'test/integration/fixtures'
]
}
});
(async function () {
const results = await eslint.lintFiles(files);
if (fix) {
await ESLint.outputFixes(results);
}
const errorCount = results.reduce((total, {errorCount}) => total + errorCount, 0);
const warningCount = results.reduce((total, {warningCount}) => total + warningCount, 0);
const fixableErrorCount = results.reduce((total, {fixableErrorCount}) => total + fixableErrorCount, 0);
const fixableWarningCount = results.reduce((total, {fixableWarningCount}) => total + fixableWarningCount, 0);
const hasFixable = fixableErrorCount || fixableWarningCount;
if (errorCount || warningCount) {
const {format} = await eslint.loadFormatter();
console.log(format(results));
console.log();
console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run lint <file>\` to check again.`);
if (hasFixable) {
console.log();
console.log('You may also want run `npm run lint <file> --fix` to fix fixable problems.');
}
console.log();
console.log('* If you\'re making a new rule, you can fix this later. *');
} else {
console.log('All tests have passed.');
}
process.exit(errorCount);
})().catch(error => {
process.exitCode = 1;
console.error(error);
});