-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-staged.config.js
43 lines (32 loc) · 1.06 KB
/
lint-staged.config.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
const rootDirAbsolutePath = process.cwd();
function getRelativeFiles(files) {
return files.map((file) => file.replace(rootDirAbsolutePath, '.'));
}
function getTurboAffectedFilters(files) {
const affected = new Set();
files.forEach((file) => {
const [, category, segment] = file.split('/');
if(segment && ['apps', 'packages'].includes(category)) {
affected.add(`@repo/${segment}`);
}
});
const affectedKeys = Array.from(affected.keys());
const affectedFilters = affectedKeys.map((key) => `--filter=${key}`);
return affectedFilters;
}
module.exports = {
'*.{ts,tsx,js,json,html,css,scss,less,sass,svg}': (files) => {
const affectedFilters = getTurboAffectedFilters(files);
if(!affectedFilters.length) {
return [];
}
return [`yarn lint ${affectedFilters.join(' ')}`];
},
'**/*.{t,j}s?(x)': (files) => {
const affectedFilters = getTurboAffectedFilters(files);
if(!affectedFilters.length) {
return [];
}
return ['yarn type-check', `yarn test ${affectedFilters.join(' ')} --coverage`];
},
};