-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlint-staged.config.js
73 lines (61 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { dirname, relative, resolve } from "node:path";
import ts from "typescript";
/**
* @type {(tsconfigFilename: string) => string}
*/
const getTscFilesPattern = (tsconfigFilename) => {
const configPath = ts.findConfigFile(
import.meta.dirname,
ts.sys.fileExists,
tsconfigFilename,
);
if (!configPath) {
throw new Error(`${tsconfigFilename} is not found`);
}
const { config } = ts.readConfigFile(configPath, ts.sys.readFile);
const { fileNames } = ts.parseJsonConfigFileContent(
config,
ts.sys,
resolve(import.meta.dirname, dirname(tsconfigFilename)),
);
return `(${[configPath, ...fileNames]
.map((path) => relative(import.meta.dirname, path))
.join("|")})`;
};
/**
* @type {import("lint-staged").Config}
*/
const config = {
".gitignore?(-sync)": () => "bun run ignore-sync",
"biome.jsonc": () =>
process.env["CI"]
? "biome ci --error-on-warnings ."
: "bun run check:biome",
"*.{js,mjs,cjs,jsx,mjsx,ts,mts,cts,tsx,mtsx,json,jsonc}": process.env["CI"]
? "biome ci --error-on-warnings"
: "biome check --apply-unsafe --error-on-warnings",
"prettier.config.js": () =>
process.env["CI"] ? "prettier --check ." : "bun run check:prettier",
"*.{md,yml,yaml,css}": process.env["CI"]
? "prettier --check"
: "prettier --write --cache",
"cspell.config.cjs": () => "bun run check:cspell",
"*": `cspell --no-must-find-files${process.env["CI"] ? "" : " --cache"}`,
};
/**
* @type {import("lint-staged").Config}
*/
const ciOnlyConfig = {
"(*.{js,mjs,cjs,jsx,mjsx,ts,mts,cts,tsx,mtsx,mdx,json}|.github/workflows/*|.husky/*)":
() => "bun run check:knip",
[getTscFilesPattern("tsconfig.base.json")]: () => "bun run check:tsc:base",
[getTscFilesPattern("tsconfig.src.json")]: () => [
// generate type definitions (e.g. next-env.d.ts)
"bun run build",
"bun run check:tsc:src",
],
};
/**
* @type {import("lint-staged").Config}
*/
export default { ...config, ...(process.env["CI"] ? ciOnlyConfig : {}) };