Skip to content

Commit 4786023

Browse files
committed
Fix lint for parameter decorator fixtures
1 parent 0d59a95 commit 4786023

File tree

2 files changed

+274
-1
lines changed

2 files changed

+274
-1
lines changed

.eslintrc.cjs

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
/* global module */
2+
3+
module.exports = {
4+
root: true,
5+
ignorePatterns: [
6+
// These fixtures intentionally exercise AssemblyScript-only syntax that
7+
// TypeScript's parser rejects before lint rules can run.
8+
"tests/compiler/parameter-decorators.ts",
9+
"tests/transform/parameter-decorators.ts"
10+
],
11+
parser: "@typescript-eslint/parser",
12+
plugins: [
13+
"@typescript-eslint",
14+
],
15+
extends: [
16+
"eslint:recommended",
17+
"plugin:@typescript-eslint/eslint-recommended",
18+
"plugin:@typescript-eslint/recommended",
19+
],
20+
parserOptions: {
21+
ecmaVersion: 2020,
22+
sourceType: "module",
23+
ecmaFeatures: {}
24+
},
25+
globals: {
26+
"globalThis": "readonly",
27+
"BigInt64Array": "readonly",
28+
"BigUint64Array": "readonly",
29+
"WebAssembly": "readonly",
30+
"FinalizationRegistry": "readonly",
31+
"fetch": "readonly",
32+
"URL": "readonly",
33+
"console": "readonly"
34+
},
35+
36+
// === General rules =========================================================
37+
38+
rules: {
39+
// Omitted semicolons are hugely popular, yet within the compiler it makes
40+
// sense to be better safe than sorry.
41+
"semi": "error",
42+
43+
// Our code bases uses 2 spaces for indentation, and we enforce it here so
44+
// files don't mix spaces, tabs or different indentation levels.
45+
"indent": ["error", 2, {
46+
"SwitchCase": 1,
47+
"VariableDeclarator": "first",
48+
"offsetTernaryExpressions": true,
49+
"ignoredNodes": [ // FIXME: something's odd here
50+
"ConditionalExpression > *",
51+
"ConditionalExpression > * > *",
52+
"ConditionalExpression > * > * > *"
53+
]
54+
}],
55+
56+
// This is mostly visual style, making comments look uniform.
57+
"spaced-comment": ["error", "always", {
58+
"markers": ["/"], // triple-slash
59+
"exceptions": ["/"] // all slashes
60+
}],
61+
62+
// This tends to be annoying as it encourages developers to make everything
63+
// that is never reassigned a 'const', sometimes semantically incorrect so,
64+
// typically leading to huge diffs in follow-up PRs modifying affected code.
65+
"prefer-const": "off",
66+
67+
// It is perfectly fine to declare top-level variables with `var`, yet this
68+
// rule doesn't provide configuration options that would help.
69+
"no-var": "off",
70+
71+
// Quite often, dealing with multiple related cases at once or otherwise
72+
// falling through is exactly the point of using a switch.
73+
"no-fallthrough": "off",
74+
75+
// Typical false-positives here are `do { ... } while (true)` statements or
76+
// similar, but the only option provided here is not checking any loops.
77+
"no-constant-condition": ["error", { checkLoops: false }],
78+
79+
// Functions are nested in blocks occasionally, and there haven't been any
80+
// problems with this so far, so turning the check off.
81+
"no-inner-declarations": "off",
82+
83+
// Quite common in scenarios where an iteration starts at `current = this`.
84+
"@typescript-eslint/no-this-alias": "off",
85+
86+
// Interferes with tests and 64-bit literals
87+
"@typescript-eslint/no-loss-of-precision": "off",
88+
89+
// Disabled here, but enabled again for JavaScript files.
90+
"no-unused-vars": "off",
91+
92+
// Disabled here, but enabled again for TypeScript files.
93+
"@typescript-eslint/no-unused-vars": "off"
94+
},
95+
overrides: [
96+
97+
// === JavaScript rules ====================================================
98+
99+
{
100+
env: {
101+
"browser": true,
102+
"amd": true,
103+
"node": true,
104+
"es6": true
105+
},
106+
files: [
107+
"**/*.js",
108+
"bin/*"
109+
],
110+
rules: {
111+
// We are testing both ESM and UMD, so don't limit us.
112+
"@typescript-eslint/no-var-requires": "off",
113+
114+
// This rule does not behave well in JS files.
115+
"@typescript-eslint/explicit-module-boundary-types": "off",
116+
117+
// Enforcing to remove function parameters on stubs makes code less
118+
// maintainable, so we instead allow unused function parameters.
119+
"no-unused-vars": [
120+
"warn", {
121+
"vars": "local",
122+
"args": "none",
123+
"ignoreRestSiblings": false
124+
}
125+
],
126+
127+
"@typescript-eslint/no-loss-of-precision": "error",
128+
}
129+
},
130+
131+
// === TypeScript rules ====================================================
132+
133+
{
134+
files: [
135+
"**/*.ts"
136+
],
137+
rules: {
138+
// Enforcing to remove function parameters on stubs makes code less
139+
// maintainable, so we instead allow unused function parameters.
140+
"@typescript-eslint/no-unused-vars": [
141+
"warn", {
142+
"vars": "local",
143+
"varsIgnorePattern": "^[A-Z](?:From|To)?$", // ignore type params
144+
"args": "none",
145+
"ignoreRestSiblings": false
146+
}
147+
]
148+
}
149+
},
150+
151+
// === AssemblyScript rules (extends TypeScript rules) =====================
152+
153+
{
154+
files: [
155+
"**/assembly/**/*.ts",
156+
"src/**/*.ts",
157+
"lib/parse/src/**/*.ts"
158+
],
159+
rules: {
160+
// Namespaces are quite useful in AssemblyScript
161+
"@typescript-eslint/no-namespace": "off",
162+
163+
// There is actually codegen difference here
164+
"@typescript-eslint/no-array-constructor": "off",
165+
166+
// Sometimes it can't be avoided to add a @ts-ignore
167+
"@typescript-eslint/ban-ts-comment": "off",
168+
169+
// Utilized to achieve portability in some cases
170+
"@typescript-eslint/no-non-null-assertion": "off",
171+
}
172+
},
173+
174+
// === Compiler rules (extends AssemblyScript rules) =======================
175+
176+
{
177+
files: [
178+
"src/**/*.ts",
179+
"std/assembly/**/*.ts"
180+
],
181+
rules: {
182+
// There is an actual codegen difference here - TODO: revisit
183+
"no-cond-assign": "off",
184+
185+
// Not all types can be omitted in AS yet - TODO: revisit
186+
"@typescript-eslint/no-inferrable-types": "off",
187+
188+
// Used rarely to reference internals that are not user-visible
189+
"@typescript-eslint/triple-slash-reference": "off",
190+
191+
// The compiler has its own `Function` class for example
192+
"no-shadow-restricted-names": "off",
193+
"@typescript-eslint/ban-types": "off"
194+
}
195+
},
196+
197+
// === Standard Library rules (extends AssemblyScript rules) ===============
198+
199+
{
200+
files: [
201+
"std/assembly/**/*.ts"
202+
],
203+
rules: {
204+
// We are implementing with --noLib, so we shadow all the time
205+
"no-shadow-restricted-names": "off",
206+
207+
// Similarly, sometimes we need the return type to be String, not string
208+
"@typescript-eslint/ban-types": "off"
209+
}
210+
},
211+
212+
// === Standard Definition rules (extends TypeScript rules) ================
213+
214+
{
215+
files: [
216+
"std/**/*.d.ts"
217+
],
218+
rules: {
219+
// Often required to achieve compatibility with TypeScript
220+
"@typescript-eslint/no-explicit-any": "off",
221+
222+
// Interfaces can be stubs here, i.e. not yet fully implemented
223+
"@typescript-eslint/no-empty-interface": "off",
224+
225+
// Definitions make use of `object` to model rather unusual constraints
226+
"@typescript-eslint/ban-types": "off"
227+
}
228+
},
229+
230+
// === Compiler Definition rules (extends TypeScript rules) ================
231+
232+
{
233+
files: [
234+
"./dist/*.d.ts"
235+
],
236+
rules: {
237+
// Our definitions are complicated, and all attempts to describe them
238+
// as modules have failed so far. As such, we re-export namespaces.
239+
"@typescript-eslint/no-namespace": "off",
240+
"@typescript-eslint/triple-slash-reference": "off"
241+
}
242+
},
243+
244+
// === Test rules (extends TypeScript rules) ===============================
245+
246+
{
247+
files: [
248+
"./tests/compiler/**/*.ts",
249+
"./lib/loader/tests/assembly/**/*.ts"
250+
],
251+
rules: {
252+
// Tests typically include unusual code patterns on purpose. This is
253+
// very likely not an extensive list, but covers what's there so far.
254+
"no-empty": "off",
255+
"no-cond-assign": "off",
256+
"no-compare-neg-zero": "off",
257+
"no-inner-declarations": "off",
258+
"no-constant-condition": "off",
259+
"use-isnan": "off",
260+
"@typescript-eslint/no-namespace": "off",
261+
"@typescript-eslint/no-unused-vars": "off",
262+
"@typescript-eslint/no-empty-function": "off",
263+
"@typescript-eslint/no-non-null-assertion": "off",
264+
"@typescript-eslint/no-extra-semi": "off",
265+
"@typescript-eslint/no-inferrable-types": "off",
266+
"@typescript-eslint/ban-types": "off",
267+
"@typescript-eslint/triple-slash-reference": "off",
268+
"@typescript-eslint/ban-ts-comment": "off",
269+
"@typescript-eslint/no-extra-non-null-assertion": "off",
270+
"@typescript-eslint/no-empty-interface": "off"
271+
}
272+
},
273+
]
274+
};

src/program.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ import {
129129
IndexSignatureNode,
130130
InterfaceDeclaration,
131131
MethodDeclaration,
132-
ModuleDeclaration,
133132
NamespaceDeclaration,
134133
ReturnStatement,
135134
SwitchCase,

0 commit comments

Comments
 (0)