forked from frontity/frontity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-staged.js
49 lines (46 loc) · 1.15 KB
/
lint-staged.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
43
44
45
46
47
48
49
const lintStaged = require("lint-staged");
/**
* Run lint-staged programatically to catch the errors because we don't want
* eslint errors to prevent the commit. Eslint will be checked again using a
* GitHub action once the code is pushed.
*
* We use two separate lint-staged executions to prevent lint-staged from
* reverting the prettier changes if eslint fails.
*/
(async () => {
try {
/**
* This script adds a linebreak before each TSDocs comment. Unnecessary
* linebreaks and double linebreaks will be removed by prettier in the next
* step.
*/
await lintStaged({
allowEmpty: true,
config: {
"*.{js,jsx,ts,tsx}":
'replace-in-files --regex="\\/\\*\\*\\s*\n" --replacement="\n/**\n"',
},
});
/**
* Prettier.
*/
await lintStaged({
allowEmpty: true,
config: {
"*.{js,jsx,ts,tsx}": "prettier --write",
},
});
/**
* Eslint.
*/
await lintStaged({
allowEmpty: true,
config: {
"*.{js,jsx,ts,tsx}": "eslint --fix",
},
});
} catch (e) {
// Failed to load configuration.
console.error(e);
}
})();