Skip to content

Commit 1664749

Browse files
committed
Update dependencies (binaryen v125)
Updates dependencies in package.json and package-lock.json, including major upgrades to ESLint, TypeScript and binaryen. Refactors catch blocks in JS files to omit unused error variables for cleaner code (due to new ts version). Introduces a new eslint.config.js (v9) using the flat config format with tailored rules for JavaScript, TypeScript, AssemblyScript, and test files.
1 parent 5a125c7 commit 1664749

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1925
-2354
lines changed

NOTICE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ under the licensing terms detailed in LICENSE:
6262
* Kam Chehresa <kaz.che@gmail.com>
6363
* Mopsgamer <79159094+Mopsgamer@users.noreply.github.com>
6464
* EDM115 <github@edm115.dev>
65+
* Anakun <anakun@opnet.org>
6566

6667
Portions of this software are derived from third-party works licensed under
6768
the following terms:

cli/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export async function main(argv, options) {
425425
} catch (e1) {
426426
try {
427427
transform = require(resolved);
428-
} catch (e2) {
428+
} catch {
429429
return prepareResult(e1);
430430
}
431431
}
@@ -1024,7 +1024,7 @@ export async function main(argv, options) {
10241024
try {
10251025
stats.readCount++;
10261026
return await fs.promises.readFile(name, "utf8");
1027-
} catch (e) {
1027+
} catch {
10281028
return null;
10291029
}
10301030
}
@@ -1038,7 +1038,7 @@ export async function main(argv, options) {
10381038
await fs.promises.mkdir(dirPath, { recursive: true });
10391039
await fs.promises.writeFile(filePath, contents);
10401040
return true;
1041-
} catch (e) {
1041+
} catch {
10421042
return false;
10431043
}
10441044
}
@@ -1049,7 +1049,7 @@ export async function main(argv, options) {
10491049
stats.readCount++;
10501050
return (await fs.promises.readdir(path.join(baseDir, dirname)))
10511051
.filter(file => extension_re_except_d.test(file));
1052-
} catch (e) {
1052+
} catch {
10531053
return null;
10541054
}
10551055
}
@@ -1105,7 +1105,7 @@ async function getConfig(file, baseDir, readFile) {
11051105
let config;
11061106
try {
11071107
config = JSON.parse(contents);
1108-
} catch(ex) {
1108+
} catch {
11091109
throw new Error(`Asconfig is not valid json: ${location}`);
11101110
}
11111111

eslint.config.js

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

lib/loader/tests/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ function test(file) {
222222
{
223223
let ptr = exports.__newString("test");
224224
exports.__pin(ptr);
225-
try { exports.__pin(ptr); assert(false); } catch (e) { /* nop */ }
225+
try { exports.__pin(ptr); assert(false); } catch { /* nop */ }
226226
exports.__unpin(ptr);
227-
try { exports.__unpin(ptr); assert(false); } catch (e) { /* nop */ }
227+
try { exports.__unpin(ptr); assert(false); } catch { /* nop */ }
228228
}
229229

230230
// should be able to correctly call a function with variable arguments

0 commit comments

Comments
 (0)