-
Notifications
You must be signed in to change notification settings - Fork 8
/
typescript.js
217 lines (196 loc) · 7.68 KB
/
typescript.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
const typescriptESLintParser = require('@typescript-eslint/parser');
module.exports = {
languageOptions: {
'parserOptions': {
'parser': typescriptESLintParser,
'sourceType': 'module',
// Disable warning banner for possibly incompatible versions of TypeScript
'loggerFn': false,
},
},
'rules': {
// The standard ESLint `no-dupe-class-members` rule will report false
// positives for overloaded TypeScript class methods. This rule is safe to
// disable because actual duplicate class members will be caught by the
// TypeScript compiler.
'no-dupe-class-members': 'off',
// TODO: figure out how to fix no-undef.
// Currently, no-undef causes false positives for TypeScript class properties.
// With TypeScript-only code this rule can safely be disabled because
// TypeScript won't compile if the definition is missing. However, if we use
// any JavaScript in the project we need to have it enabled.
'no-undef': 'off',
// The standard ESLint `no-unused-vars' rule will throw false positives with
// class properties in TypeScript. The TypeScript-specific rule fixes this.
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
// For TypeScript code, `const`/`let` should be used exclusively
'no-var': 'error',
// new-cap throws errors with property decorators
'new-cap': 'off',
// TypeScript will be parsed in strict mode and output the `use-strict`
// directive for the transpiled JavaScript automatically.
'strict': [ 'error', 'never' ],
'no-empty-function': [ 'error', { 'allow': [ 'constructors' ] } ],
'@typescript-eslint/adjacent-overload-signatures': 'error',
// Disable ESLint's camelcase so we can override with our own
// naming convention rules.
'camelcase': 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'classProperty',
modifiers: [ 'private' ],
format: [ 'camelCase' ],
leadingUnderscore: 'require',
},
{
selector: 'classProperty',
modifiers: [ 'protected' ],
format: [ 'camelCase' ],
leadingUnderscore: 'require',
},
{
selector: 'classProperty',
modifiers: [ 'private', 'static' ],
format: [ 'snake_case' ],
leadingUnderscore: 'require',
},
{
selector: 'classProperty',
modifiers: [ 'private', 'readonly', 'static' ],
format: [ 'UPPER_CASE' ],
leadingUnderscore: 'require',
},
{
selector: 'classProperty',
modifiers: [ 'protected', 'readonly', 'static' ],
format: [ 'UPPER_CASE' ],
leadingUnderscore: 'require',
},
{
selector: 'classProperty',
modifiers: [ 'public', 'readonly', 'static' ],
format: [ 'UPPER_CASE' ],
},
{
selector: 'classProperty',
modifiers: [ 'protected', 'static' ],
format: [ 'snake_case' ],
leadingUnderscore: 'require',
},
{
selector: 'classProperty',
modifiers: [ 'public', 'static' ],
format: [ 'snake_case' ],
leadingUnderscore: 'forbid',
},
{
selector: 'enum',
format: [ 'PascalCase' ],
},
{
selector: 'typeLike',
format: [ 'PascalCase' ],
},
{
selector: 'variable',
format: [ 'camelCase', 'PascalCase' ],
},
{
selector: 'parameter',
format: [ 'camelCase', 'PascalCase' ],
leadingUnderscore: 'allow',
},
{
selector: 'variable',
modifiers: [ 'global' ],
format: [ 'UPPER_CASE', 'camelCase', 'PascalCase' ],
},
],
// no-shadow is incompatible with TypeScript code.
// @typescript-eslint/no-shadow replaces it.
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
// no-redeclare is incompatible with TypeScript code.
// @typescript-eslint/no-redeclare replaces it.
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': [ 'error' ],
'@typescript-eslint/explicit-function-return-type': [ 'error', { 'allowExpressions': true } ],
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/member-delimiter-style': 'error',
'@typescript-eslint/consistent-type-assertions': [ 'error', { 'assertionStyle': 'as' } ],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/member-ordering': [
'error',
{
'default': [
// Index signature
'signature',
'call-signature',
// Fields
'public-static-field',
'protected-static-field',
'private-static-field',
'public-instance-field',
'protected-instance-field',
'private-instance-field',
'public-abstract-field',
'protected-abstract-field',
'public-field',
'protected-field',
'private-field',
'static-field',
'instance-field',
'abstract-field',
'field',
// Constructors
'public-constructor',
'protected-constructor',
'private-constructor',
'constructor',
// Methods
[ 'public-static-method', 'public-static-get', 'public-static-set' ],
[ 'protected-static-method', 'protected-static-get', 'protected-static-set' ],
[ 'private-static-method', 'private-static-get', 'private-static-set' ],
[ 'public-instance-method', 'public-instance-get', 'public-instance-set' ],
[ 'protected-instance-method', 'protected-instance-get', 'protected-instance-set' ],
[ 'private-instance-method', 'private-instance-get', 'private-instance-set' ],
[ 'public-abstract-method', 'public-abstract-get', 'public-abstract-set' ],
[ 'protected-abstract-method', 'protected-abstract-get', 'protected-abstract-set' ],
'public-method',
'protected-method',
'private-method',
[ 'static-method', 'static-get', 'static-set' ],
[ 'instance-method', 'instance-get', 'instance-set' ],
[ 'abstract-method', 'abstract-get', 'abstract-set' ],
'method',
],
},
],
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/parameter-properties': [ 'error', { 'allow': [ 'private' ] } ],
'@typescript-eslint/triple-slash-reference': [ 'error', { 'path': 'never', 'types': 'never', 'lib': 'never' } ],
'@typescript-eslint/type-annotation-spacing': [
'error',
{
'before': false,
'after': true,
'overrides': {
'arrow': { 'before': true, 'after': true },
},
},
],
'@typescript-eslint/no-empty-interface': 'error',
// Turn off the core no-use-before-define to avoid double reporting errors.
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{
'functions': false,
'typedefs': false,
},
],
},
};