-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.lintstagedrc.js
66 lines (60 loc) · 1.87 KB
/
.lintstagedrc.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
62
63
64
65
66
const { ESLint } = require('eslint');
const { chunk } = require('lodash');
const { relative, dirname } = require('path');
const glob = require('glob');
const removeIgnoredFiles = async files => {
const eslint = new ESLint();
const isIgnored = await Promise.all(
files.map(file => eslint.isPathIgnored(file)),
);
return files.filter((_, i) => !isIgnored[i]);
};
const chunkFileSize = 15;
const runChunks = (files, cmd) => {
const chunkArrays = chunk(files, chunkFileSize);
let commands = [];
for (const arr of chunkArrays) {
commands = commands.concat([`${cmd} ${arr.join(' ')}`]);
}
return commands;
};
module.exports = {
'src/**/*.*': files => {
return runChunks(files, `prettier --ignore-unknown --write`);
},
'src/**/*.{css,scss}': files => {
return runChunks(files, `stylelint -f verbose --fix`);
},
'src/**/*.html': files => {
const relativeFiles = files.map(x => relative(__dirname, x));
return runChunks(relativeFiles, `linthtml`);
},
'src/**/*.{ts,tsx,js,jsx}': async files => {
const filesToLint = await removeIgnoredFiles(files);
return runChunks(filesToLint, `eslint --max-warnings=0 --fix`);
},
'src/**/*.**': async files => {
const dirs = [
...new Set(
files.map(file =>
relative(__dirname, dirname(file)).replace(/\\/g, '/'),
),
),
];
const specsToFind = [...dirs].map(dir => dir + '/*.spec.ts');
const specs$ = specsToFind.map(
spec =>
new Promise((resolve, reject) => {
glob(spec, { cwd: __dirname }, (err, matches) =>
err ? reject(err) : resolve(matches),
);
}),
);
const specs = (await Promise.all(specs$)).flat(Infinity);
if (specs.length < 1) {
return [];
}
const includes = specs.map(spec => '--include=' + spec);
return runChunks(includes, `npm run test:ci -- --watch=false`);
},
};