-
Notifications
You must be signed in to change notification settings - Fork 159
/
.eslintrc.lint-staged.js
46 lines (43 loc) · 1.48 KB
/
.eslintrc.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
const DEFAULT_CONFIG = require("./.eslintrc.js");
const TYPESCRIPT_ESLINT = "@typescript-eslint";
const TYPESCRIPT_ESLINT_PARSER_OPTIONS = new Set(["project", "allowAutomaticSingleRunInference", "tsconfigRootDir"]);
module.exports = {
...DEFAULT_CONFIG,
extends: [
...DEFAULT_CONFIG.extends.filter((extended) => !extended.startsWith(`plugin:${TYPESCRIPT_ESLINT}/`)),
// needed to disable recommended eslint rules that don't apply
"plugin:@typescript-eslint/eslint-recommended",
],
parserOptions: Object.entries(DEFAULT_CONFIG.parserOptions).reduce(
(newParserOptions, [parserOptionKey, parserOption]) => {
if (!TYPESCRIPT_ESLINT_PARSER_OPTIONS.has(parserOptionKey)) {
newParserOptions[parserOptionKey] = parserOption;
}
return newParserOptions;
},
{}
),
rules: Object.entries(DEFAULT_CONFIG.rules).reduce(
(newRules, [ruleId, rule]) => {
if (!doesRuleRequireTypeInformation(ruleId) || rule === "off") {
newRules[ruleId] = rule;
}
return newRules;
},
{
"no-unused-vars": "off",
}
),
};
function doesRuleRequireTypeInformation(ruleId) {
if (ruleId.startsWith(`${TYPESCRIPT_ESLINT}/`)) {
return true;
}
switch (ruleId) {
case "deprecation/deprecation":
case "jest/unbound-method":
return true;
default:
return false;
}
}