1
+ module . exports = {
2
+ root : true ,
3
+ parser : "@typescript-eslint/parser" ,
4
+ plugins : [
5
+ "@typescript-eslint" ,
6
+ ] ,
7
+ extends : [
8
+ "eslint:recommended" ,
9
+ "plugin:@typescript-eslint/eslint-recommended" ,
10
+ "plugin:@typescript-eslint/recommended" ,
11
+ ] ,
12
+ parserOptions : {
13
+ ecmaVersion : 2020 ,
14
+ sourceType : "module" ,
15
+ ecmaFeatures : { }
16
+ } ,
17
+ ignorePatterns : [ "node_modules/**/*" ] ,
18
+ // === General rules =========================================================
19
+
20
+ rules : {
21
+ // Omitted semicolons are hugely popular, yet within the compiler it makes
22
+ // sense to be better safe than sorry.
23
+ "semi" : "error" ,
24
+
25
+ // Our code bases uses 2 spaces for indentation, and we enforce it here so
26
+ // files don't mix spaces, tabs or different indentation levels.
27
+ "indent" : [ "error" , 2 , {
28
+ "SwitchCase" : 1 ,
29
+ "VariableDeclarator" : "first" ,
30
+ "offsetTernaryExpressions" : true ,
31
+ "ignoredNodes" : [ // FIXME: something's odd here
32
+ "ConditionalExpression > *" ,
33
+ "ConditionalExpression > * > *" ,
34
+ "ConditionalExpression > * > * > *"
35
+ ]
36
+ } ] ,
37
+
38
+ // This is mostly visual style, making comments look uniform.
39
+ "spaced-comment" : [ "error" , "always" , {
40
+ "markers" : [ "/" ] , // triple-slash
41
+ "exceptions" : [ "/" ] // all slashes
42
+ } ] ,
43
+
44
+ // This tends to be annoying as it encourages developers to make everything
45
+ // that is never reassigned a 'const', sometimes semantically incorrect so,
46
+ // typically leading to huge diffs in follow-up PRs modifying affected code.
47
+ "prefer-const" : "off" ,
48
+
49
+ // It is perfectly fine to declare top-level variables with `var`, yet this
50
+ // rule doesn't provide configuration options that would help.
51
+ "no-var" : "off" ,
52
+
53
+ // Quite often, dealing with multiple related cases at once or otherwise
54
+ // falling through is exactly the point of using a switch.
55
+ "no-fallthrough" : "off" ,
56
+
57
+ // Typical false-positives here are `do { ... } while (true)` statements or
58
+ // similar, but the only option provided here is not checking any loops.
59
+ "no-constant-condition" : [ "error" , { checkLoops : false } ] ,
60
+
61
+ // Functions are nested in blocks occasionally, and there haven't been any
62
+ // problems with this so far, so turning the check off.
63
+ "no-inner-declarations" : "off" ,
64
+
65
+ // Quite common in scenarios where an iteration starts at `current = this`.
66
+ "@typescript-eslint/no-this-alias" : "off" ,
67
+
68
+ // Disabled here, but enabled again for JavaScript files.
69
+ "no-unused-vars" : "off" ,
70
+
71
+ // Disabled here, but enabled again for TypeScript files.
72
+ "@typescript-eslint/no-unused-vars" : "off"
73
+ } ,
74
+ overrides : [
75
+
76
+ // === TypeScript rules ====================================================
77
+
78
+ {
79
+ files : [
80
+ "**/assembly/**/*.ts"
81
+ ] ,
82
+ rules : {
83
+ // Enforcing to remove function parameters on stubs makes code less
84
+ // maintainable, so we instead allow unused function parameters.
85
+ "@typescript-eslint/no-unused-vars" : [
86
+ "warn" , {
87
+ "vars" : "local" ,
88
+ "varsIgnorePattern" : "^_|^[A-Z](?:From|To)?$" , // ignore type params
89
+ "args" : "none" ,
90
+ "ignoreRestSiblings" : false
91
+ }
92
+ ] ,
93
+
94
+ // Namespaces are quite useful in AssemblyScript
95
+ "@typescript-eslint/no-namespace" : "off" ,
96
+
97
+ // There is actually codegen difference here
98
+ "@typescript-eslint/no-array-constructor" : "off" ,
99
+
100
+ // Sometimes it can't be avoided to add a @ts-ignore
101
+ "@typescript-eslint/ban-ts-comment" : "off" ,
102
+
103
+ // Utilized to achieve portability in some cases
104
+ "@typescript-eslint/no-non-null-assertion" : "off" ,
105
+ }
106
+ } ,
107
+
108
+ // === Compiler rules (extends AssemblyScript rules) =======================
109
+
110
+ {
111
+ files : [
112
+ "**/assembly/**/*.ts"
113
+ ] ,
114
+ rules : {
115
+ // There is an actual codegen difference here - TODO: revisit
116
+ "no-cond-assign" : "off" ,
117
+
118
+ // Not all types can be omitted in AS yet - TODO: revisit
119
+ "@typescript-eslint/no-inferrable-types" : "off" ,
120
+
121
+ // Used rarely to reference internals that are not user-visible
122
+ "@typescript-eslint/triple-slash-reference" : "off" ,
123
+
124
+ // The compiler has its own `Function` class for example
125
+ "no-shadow-restricted-names" : "off" ,
126
+ "@typescript-eslint/ban-types" : "off"
127
+ }
128
+ } ,
129
+
130
+ // === Standard Library rules (extends AssemblyScript rules) ===============
131
+
132
+ {
133
+ files : [
134
+ "**/assembly/**/*.ts"
135
+ ] ,
136
+ rules : {
137
+ // We are implementing with --noLib, so we shadow all the time
138
+ "no-shadow-restricted-names" : "off" ,
139
+
140
+ // Similarly, sometimes we need the return type to be String, not string
141
+ "@typescript-eslint/ban-types" : "off"
142
+ }
143
+ } ,
144
+
145
+ // === Standard Definition rules (extends TypeScript rules) ================
146
+
147
+ {
148
+ files : [
149
+ "**/assembly/**/*.d.ts"
150
+ ] ,
151
+ rules : {
152
+ // Often required to achieve compatibility with TypeScript
153
+ "@typescript-eslint/no-explicit-any" : "off" ,
154
+
155
+ // Interfaces can be stubs here, i.e. not yet fully implemented
156
+ "@typescript-eslint/no-empty-interface" : "off" ,
157
+
158
+ // Definitions make use of `object` to model rather unusual constraints
159
+ "@typescript-eslint/ban-types" : "off"
160
+ }
161
+ } ,
162
+
163
+
164
+
165
+ // === Test rules (extends TypeScript rules) ===============================
166
+
167
+ {
168
+ files : [
169
+ "**/assembly/__tests__/**/*.ts"
170
+ ] ,
171
+ rules : {
172
+ // Tests typically include unusual code patterns on purpose. This is
173
+ // very likely not an extensive list, but covers what's there so far.
174
+ "no-empty" : "off" ,
175
+ "no-cond-assign" : "off" ,
176
+ "no-compare-neg-zero" : "off" ,
177
+ "no-inner-declarations" : "off" ,
178
+ "no-constant-condition" : "off" ,
179
+ "use-isnan" : "off" ,
180
+ "@typescript-eslint/no-namespace" : "off" ,
181
+ "@typescript-eslint/no-unused-vars" : "off" ,
182
+ "@typescript-eslint/no-empty-function" : "off" ,
183
+ "@typescript-eslint/no-non-null-assertion" : "off" ,
184
+ "@typescript-eslint/no-extra-semi" : "off" ,
185
+ "@typescript-eslint/no-inferrable-types" : "off" ,
186
+ "@typescript-eslint/ban-types" : "off" ,
187
+ "@typescript-eslint/triple-slash-reference" : "off" ,
188
+ "@typescript-eslint/ban-ts-comment" : "off" ,
189
+ "@typescript-eslint/no-extra-non-null-assertion" : "off" ,
190
+ "@typescript-eslint/no-empty-interface" : "off"
191
+ }
192
+ } ,
193
+ ]
194
+ } ;
0 commit comments