forked from DuCanhGH/next-pwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-staged.config.mjs
44 lines (40 loc) · 1.16 KB
/
lint-staged.config.mjs
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
import { ESLint } from "eslint";
import { quote } from "shell-quote";
const eslint = new ESLint();
const isWin = process.platform === "win32";
/**
* @param {string[]} str
* @returns
*/
const escapeStr = (str) => {
const escaped = quote(str);
return escaped.replace(/\\@/g, "@");
};
/**
* @type {Record<
* string,
* (filenames: string[]) => string | string[] | Promise<string | string[]>
* >}
*/
const lintStagedConfig = {
"**/*.{js,jsx,cjs,mjs,ts,tsx}": (filenames) => {
const escapedFileNames = filenames
.map((filename) => (isWin ? filename : escapeStr([filename])))
.join(" ");
return [
`eslint --fix ${filenames
.filter(async (file) => !(await eslint.isPathIgnored(file)))
.map((f) => `"${f}"`)
.join(" ")}`,
`pnpm format ${escapedFileNames}`,
`git add ${escapedFileNames}`,
];
},
"**/*.{json,md,mdx,css,html,yml,yaml,scss}": (filenames) => {
const escapedFileNames = filenames
.map((filename) => (isWin ? filename : escapeStr([filename])))
.join(" ");
return [`pnpm format ${escapedFileNames}`, `git add ${escapedFileNames}`];
},
};
export default lintStagedConfig;