-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-staged.config.js
47 lines (42 loc) · 1.42 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
// eslint-disable-next-line import/no-extraneous-dependencies
import { ESLint } from 'eslint';
const removeIgnoredFiles = async (files) => {
const eslint = new ESLint();
const isIgnored = await Promise.all(files.map((file) => eslint.isPathIgnored(file)));
const filteredFiles = files.filter((_, i) => isIgnored[i] !== true);
return filteredFiles.join(' ');
};
const fixableConfig = {
'*.{tsx,ts,mts}': async (files) => {
const filteredFiles = await removeIgnoredFiles(files);
return [
'tsc --noEmit',
'tsc --project ./client/tsconfig.json --noEmit',
`eslint --fix ${filteredFiles}`,
];
},
'*.{mjs,cjs,js,jsx}': async (files) => {
const filteredFiles = await removeIgnoredFiles(files);
return [`eslint --fix ${filteredFiles}`];
},
'*.json': ['prettier --write'],
'*.tf': ['terraform fmt ./terraform'],
};
const ciConfig = {
'*.{tsx,ts,mts}': async (files) => {
const filteredFiles = await removeIgnoredFiles(files);
return [
'tsc --noEmit',
'tsc --project ./client/tsconfig.json --noEmit',
`eslint ${filteredFiles}`,
];
},
'*.{mjs,cjs,js,jsx}': async (files) => {
const filteredFiles = await removeIgnoredFiles(files);
return [`eslint ${filteredFiles}`];
},
'*.json': ['prettier --check'],
'*.tf': ['terraform fmt --check ./terraform'],
};
const isCi = process.env.GITHUB_ACTIONS === 'true';
export default isCi ? ciConfig : fixableConfig;