-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lintstagedrc.cjs
31 lines (26 loc) · 998 Bytes
/
.lintstagedrc.cjs
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
const { ESLint } = require("eslint");
const eslintCli = new ESLint();
const asyncFilter = async (arr, predicate) => {
const results = await Promise.all(arr.map(predicate));
return arr.filter((_v, index) => results[index]);
};
const removeIgnoredFiles = async (files) => {
const filteredFiles = await asyncFilter(files, async (file) => {
const isIgnored = await eslintCli.isPathIgnored(file);
return !isIgnored;
});
return filteredFiles.join(" ");
};
const eslint = async (files) =>
"eslint --fix --max-warnings=0 " + (await removeIgnoredFiles(files));
const stylelint = (files) => `stylelint --fix --mw 0 ${files.join(" ")}`;
const prettier = (files) => `prettier --write ${files.join(" ")}`;
function rules(...args) {
return async (files) => Promise.all(args.map((f) => f(files)));
}
module.exports = {
"*.vue": rules(eslint, stylelint, prettier),
"*.js": rules(eslint, prettier),
"*.css": rules(stylelint, prettier),
"*.{html,yml,json,md}": rules(prettier),
};