forked from signalapp/Signal-Desktop
-
Notifications
You must be signed in to change notification settings - Fork 191
/
.lintstagedrc.js
42 lines (32 loc) · 1.07 KB
/
.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
34
35
36
37
38
39
40
41
42
const { ESLint } = require('eslint');
const removeIgnoredFiles = async files => {
const eslint = new ESLint();
const isIgnored = await Promise.all(
files.map(file => {
return eslint.isPathIgnored(file);
})
);
const filteredFiles = files.filter((_, i) => !isIgnored[i]);
return filteredFiles.join(' ');
};
const buildFormatCommand = async files => {
const filesToLint = await removeIgnoredFiles(files);
if (!filesToLint || !filesToLint.length) {
return '';
}
const results = filesToLint.map(f => path.relative(process.cwd(), f));
return results.length
? `prettier --ignore-unknown --list-different --write ${results.join(' ')}`
: '';
};
const buildLintCommand = async files => {
const filesToLint = await removeIgnoredFiles(files);
if (!filesToLint || !filesToLint.length) {
return '';
}
const results = filesToLint.map(f => path.relative(process.cwd(), f));
return results.length ? `eslint --cache ${results.join(' ')}` : '';
};
module.exports = {
'*.{css,js,json,scss,ts,tsx}': [buildFormatCommand, buildLintCommand],
};