-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathlint-diff.ts
More file actions
34 lines (28 loc) · 1016 Bytes
/
lint-diff.ts
File metadata and controls
34 lines (28 loc) · 1016 Bytes
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
import { execSync } from 'child_process';
import { CLIEngine as ESLint } from 'eslint';
import chalk from 'chalk';
const GIT_DIFF = 'git diff --cached --diff-filter=ACMR --name-only';
(async () => {
const linter = new ESLint({ extensions: ['.js', '.jsx', '.ts', '.tsx'] });
// file level
const fileList = await execSync(GIT_DIFF).toString().split('\n');
// ignore file which is not js/jsx/ts/tsx
const lintFileList = fileList.filter((file) => /\.(j|t)sx?$/g.test(file) && !linter.isPathIgnored(file));
if (!lintFileList.length) {
console.log(chalk.green('no file should be lint.'));
return;
}
try {
console.log(chalk.green(lintFileList.join('\n')));
console.log();
console.log(chalk.green('above file should be lint.'));
const report = linter.executeOnFiles(lintFileList);
const formatter = linter.getFormatter();
console.log(formatter(report.results));
} catch (error) {
process.exit(1);
}
})().catch((e) => {
console.trace(e);
process.exit(1);
});