-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-staged.config.js
47 lines (41 loc) · 1.14 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
/**
* @typedef {string | string[]} Task
* @typedef {(filenames: string[]) => Task | Promise<Task>} FunctionTask
* @typedef {Record<string, Task | FunctionTask | (Task | FunctionTask)[]> | FunctionTask} Config
*/
/**
* @type {Config}
*/
const baseConfig = {
'*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}': [
() => ['tsc --noEmit'],
'eslint --cache --cache-location node_modules/.cache/eslint --fix',
],
'package.json': 'sort-package-json',
};
const prettier =
'prettier --cache --cache-location node_modules/.cache/prettier --write --ignore-unknown';
/**
* @type {Config}
*/
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const config = Object.fromEntries([
// Add prettier to each linter task or task list.
...Object.entries(baseConfig).map(([pattern, linter]) => [
pattern,
[...(Array.isArray(linter) ? linter : [linter]), prettier],
]),
// Format everything else with prettier.
[
[
'*',
Object.keys(baseConfig).map((pattern) =>
pattern.split(', ').map((subpattern) => `!${subpattern}`),
),
]
.flat(2)
.join(', '),
prettier,
],
]);
export default config;