-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
128 lines (122 loc) · 4.11 KB
/
.eslintrc.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const config = require('eslint-config-react-app');
function updateWarnRulesToErrorRules(rules) {
const newRules = {};
Object.keys(rules).forEach((key) => {
const value = rules[key];
if (Array.isArray(value)) {
newRules[key] = value.map((part) => (part === 'warn' ? 'error' : part));
} else if (value === 'warn') {
newRules[key] = 'error';
} else {
newRules[key] = value;
}
});
return newRules;
}
function convertOverridesToArray(overrides) {
if (!Array.isArray(overrides)) {
return [overrides];
}
return overrides;
}
// Extend the create-react-app config and set all warnings to errors. Also add
// config extensions for Prettier integration, and our own rules (based on
// tslint-react).
const newConfig = Object.assign({}, config, {
extends: [...config.extends, 'react-app/jest', 'plugin:prettier/recommended'],
rules: Object.assign(updateWarnRulesToErrorRules(config.rules), {
'react/jsx-boolean-value': ['error', 'always'],
'react/jsx-key': 'error',
'react/jsx-no-bind': ['error', { allowArrowFunctions: true }],
'react/self-closing-comp': 'error',
'react/no-string-refs': 'error',
'constructor-super': 'error',
curly: 'error',
'dot-notation': 'error',
'guard-for-in': 'error',
'new-parens': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-cond-assign': 'error',
'no-console': 'warn',
'no-debugger': 'error',
'no-empty': 'error',
'no-empty-function': 'error',
'no-new-wrappers': 'error',
'no-throw-literal': 'error',
'no-undef-init': 'error',
'no-unsafe-finally': 'error',
'no-unused-labels': 'error',
'no-var': 'error',
'object-shorthand': 'error',
'one-var': ['error', 'never'],
'prefer-const': 'error',
radix: 'error',
'use-isnan': 'error',
'no-shadow': 'error',
'no-unused-expressions': 'error',
}),
overrides: convertOverridesToArray(config.overrides).map((override) => {
if (override.parser === '@typescript-eslint/parser') {
// Add our custom TypeScript rules here. These are based on
// tslint/recommended.
return Object.assign({}, override, {
rules: Object.assign(updateWarnRulesToErrorRules(override.rules), {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': [
'error',
{ default: 'array-simple' },
],
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/naming-convention': [
'error',
{
selector: ['variableLike', 'memberLike'],
format: ['camelCase'],
},
{
selector: ['property', 'variable'],
format: ['camelCase', 'UPPER_CASE'],
},
{
selector: ['function', 'parameter'],
format: ['camelCase', 'PascalCase'],
},
{ selector: 'typeLike', format: ['PascalCase'] },
],
'@typescript-eslint/explicit-member-accessibility': [
'error',
{
overrides: {
constructors: 'no-public',
},
},
],
'@typescript-eslint/consistent-type-assertions': [
'error',
{ assertionStyle: 'as' },
],
'@typescript-eslint/consistent-type-definitions': [
'error',
'interface',
],
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/triple-slash-reference': [
'error',
{ types: 'prefer-import' },
],
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/unified-signatures': 'error',
}),
});
}
return Object.assign({}, override, {
rules: updateWarnRulesToErrorRules(override.rules),
});
}),
});
module.exports = newConfig;