-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.lintstagedrc.js
33 lines (27 loc) · 979 Bytes
/
.lintstagedrc.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
const micromatch = require('micromatch');
const prettier = require('prettier');
const addQuotes = (a) => `'${a}'`;
let allStagedFiles;
function prettierCmds() {
const prettierSupportedExtensions = prettier
.getSupportInfo()
.languages.map(({ extensions }) => extensions)
.flat();
const files = micromatch(
allStagedFiles,
prettierSupportedExtensions.map((extension) => `**/*${extension}`)
);
return files.length ? [`prettier --write ${files.map(addQuotes).join(' ')}`] : [];
}
function eslintCmds() {
const files = micromatch(allStagedFiles, '**/*.js');
return files.length ? [`eslint --cache --fix ${files.map(addQuotes).join(' ')}`] : [];
}
function syncpackCmds() {
const files = micromatch(allStagedFiles, '**/package.json');
return files.length ? [`syncpack format --source '{${files.join(',')}}'`] : [];
}
module.exports = (files) => {
allStagedFiles = files;
return [...prettierCmds(), ...eslintCmds(), ...syncpackCmds()];
};