-
Notifications
You must be signed in to change notification settings - Fork 6
/
.lintstagedrc.mjs
38 lines (32 loc) · 1011 Bytes
/
.lintstagedrc.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
import path from 'node:path';
const getLintFlags = (absolutePaths) => {
const cwd = process.cwd();
const relativePaths = absolutePaths.map((file) => path.relative(cwd, file));
/**
*
* Some file paths are too long and cannot be added as parameter to eslint
* https://serverfault.com/questions/9546/filename-length-limits-on-linux/9548#9548
*
* */
const filePathLengthLimit = relativePaths.find((path) => path.length > 250);
/**
*
* There is a case, when the command is too long and eslint cannot execute it.
*
* */
const isTooManyFilesToLint = relativePaths.length > 20;
return {
relativePaths,
filePathLengthLimit,
isTooManyFilesToLint,
};
};
export default {
'**/*.{js,ts}': (absolutePaths) => {
const { filePathLengthLimit, isTooManyFilesToLint, relativePaths } = getLintFlags(absolutePaths);
if (filePathLengthLimit || isTooManyFilesToLint) {
return 'npm run lint:js';
}
return `eslint ${relativePaths.join(' ')}`;
},
};