-
Notifications
You must be signed in to change notification settings - Fork 1
/
lint-staged.config.js
43 lines (36 loc) · 1.1 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
import micromatch from 'micromatch';
import * as path from 'path';
/**
* @param {string[]} files
* @returns {string[]}
*/
export default function lint(files) {
const commands = [];
if (micromatch(files, '**/package.json.md').length) {
commands.push('pnpm syncpack:check');
}
const packages = new Set(
micromatch(files, '**/packages/**/*')
.map((file) =>
file
.replace(import.meta.dirname, '')
.match(new RegExp(`packages${path.sep}([^${path.sep}]+)`))
?.pop(),
)
.filter(Boolean)
.map((pkg) => `pnpm --filter ${pkg} test run`),
);
commands.push(...packages);
const tsFiles = micromatch(files, '**/*.ts(x)?').map((file) =>
file.replace(import.meta.dirname, '').slice(1),
);
if (tsFiles.length) {
commands.push(`pnpm prettier --check ${tsFiles.join(' ')}`);
if (micromatch(files, '**/eslint.config.js').length) {
commands.push('pnpm eslint --max-warnings 0 --no-warn-ignored .');
} else {
commands.push(`pnpm eslint --max-warnings 0 --no-warn-ignored ${tsFiles.join(' ')}`);
}
}
return commands;
}