forked from Autapomorph/dino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.lintstagedrc.js
40 lines (32 loc) · 1.27 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
const fs = require('fs');
const path = require('path');
const ignore = require('ignore');
const getIgnore = (ignoreFile, defaultIgnorePatterns) => {
const ig = ignore();
if (defaultIgnorePatterns) {
ig.add(defaultIgnorePatterns);
}
if (fs.existsSync(ignoreFile)) {
const ignoreFileContent = fs.readFileSync(ignoreFile);
ig.add(ignoreFileContent.toString());
}
return ig;
};
const filterIgnore = (ignore, filenames) => ignore.filter(filenames);
const joinMatch = match => match.join(' ');
const getMatch = (filenames, ignoreFile, defaultIgnorePatterns) =>
joinMatch(filterIgnore(getIgnore(ignoreFile, defaultIgnorePatterns), filenames));
const addCommand = ([command, match]) => (match.length ? `${command} ${match}` : undefined);
const getCommands = (...commands) => commands.map(addCommand).filter(Boolean);
module.exports = {
'*.{js,jsx,ts,tsx}': filenames => {
const eslintMatch = getMatch(filenames, path.join('.eslintignore'), ['.*']);
const prettierMatch = getMatch(filenames, path.join('.prettierignore'));
return getCommands(
['prettier --write', prettierMatch],
['eslint --max-warnings=0', eslintMatch],
);
},
'*.{css,scss,sass,less}': ['prettier --write', 'stylelint --fix'],
'*.{json,md}': [`prettier --write`],
};