/
lint.mjs
91 lines (79 loc) · 2.39 KB
/
lint.mjs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
import process from 'node:process';
import {ESLint} from 'eslint';
import unicorn from '../../index.js';
import allConfig from '../../configs/all.js';
const files = [process.argv[2] || '.'];
const fix = process.argv.includes('--fix');
const eslint = new ESLint({
baseConfig: allConfig,
useEslintrc: false,
extensions: ['.js', '.mjs'],
plugins: {
unicorn,
},
fix,
overrideConfig: {
ignorePatterns: [
'coverage',
'test/integration/fixtures',
'test/integration/fixtures-local',
],
rules: {
// https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1109#issuecomment-782689255
'unicorn/consistent-destructuring': 'off',
// Buggy
'unicorn/custom-error-definition': 'off',
// Annoying
'unicorn/no-keyword-prefix': 'off',
'unicorn/no-unsafe-regex': 'off',
// Not ready yet
'unicorn/prefer-string-replace-all': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/prefer-at': 'off',
// TODO: Turn this on when `xo` updated `eslint-plugin-unicorn`
'unicorn/text-encoding-identifier-case': 'off',
},
overrides: [
{
files: [
'**/*.js',
],
rules: {
'unicorn/prefer-module': 'off',
},
},
],
},
});
const sum = (collection, fieldName) =>
collection.reduce((total, {[fieldName]: value}) => total + value, 0);
(async function () {
const results = await eslint.lintFiles(files);
if (fix) {
await ESLint.outputFixes(results);
}
const errorCount = sum(results, 'errorCount');
const warningCount = sum(results, 'warningCount');
const fixableErrorCount = sum(results, 'fixableErrorCount');
const fixableWarningCount = sum(results, 'fixableWarningCount');
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 run-rules-on-codebase <file>\` to check again.`);
if (hasFixable) {
console.log();
console.log('You may also want run `npm run run-rules-on-codebase <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);
});