-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlint-staged.config.js
56 lines (49 loc) · 1.5 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
44
45
46
47
48
49
50
51
52
53
54
55
56
import process from "node:process";
import glob from "fast-glob";
import fs from "fs-extra";
import path from "pathe";
const isFormat = process.env["TYPE"] === "format";
const typescriptExtensions = ["js", "jsx", "ts", "tsx"];
const pkgs = glob.sync("packages/*", {
absolute: false,
onlyDirectories: true,
});
/**
* Packages containing a `src` directory. Each package should have its own
* tsconfig.json file located within the `src` directory.
*/
const withSrcPkgs = pkgs.filter((pkg) => fs.existsSync(path.join(pkg, "src")));
/**
* @type {import('lint-staged').Configuration}
*/
const config = isFormat
? {
"**/*.css": "stylelint --fix",
"**/*": [
"eslint --report-unused-disable-directives --fix --max-warnings=0 --no-error-on-unmatched-pattern --no-warn-ignored",
"prettier --ignore-unknown --write",
],
}
: {
"**/*": "cspell lint --no-must-find-files",
...Object.fromEntries(
pkgs.flatMap((pkg) => {
if (withSrcPkgs.includes(pkg)) {
return [
[`${pkg}/*.config.{js,ts}`, () => `pnpm exec tsc -p ${pkg}`],
[
`${pkg}/src/**/*.{${typescriptExtensions.join(",")}}`,
() => `pnpm exec tsc -p ${pkg}/src`,
],
];
}
return [
[
`${pkg}/**/*.{${typescriptExtensions.join(",")}}`,
() => `pnpm exec tsc -p ${pkg}`,
],
];
}),
),
};
export default config;