From 37f0a3b41bb2036a5e71b72bc76e1599d2d9c41d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 25 Oct 2023 19:41:09 -0700 Subject: [PATCH] eslint: Forbid unchecked casts in TypeScript. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 4 ++++ web/debug-require-webpack-plugin.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index d91f1f4414..88e2e54e8a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -172,6 +172,10 @@ // Disable base rule to avoid conflict "no-use-before-define": "off", + "@typescript-eslint/consistent-type-assertions": [ + "error", + {"assertionStyle": "never"} + ], "@typescript-eslint/consistent-type-definitions": ["error", "type"], "@typescript-eslint/consistent-type-imports": "error", "@typescript-eslint/explicit-function-return-type": [ diff --git a/web/debug-require-webpack-plugin.ts b/web/debug-require-webpack-plugin.ts index c5bd6e59bb..d19fbb15a5 100644 --- a/web/debug-require-webpack-plugin.ts +++ b/web/debug-require-webpack-plugin.ts @@ -22,6 +22,7 @@ export default class DebugRequirePlugin implements WebpackPluginInstance { .tap("DebugRequirePlugin", (resolver) => { resolver.getHook("beforeRawModule").tap("DebugRequirePlugin", (req) => { if (!(nameSymbol in req)) { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions (req as NamedRequest)[nameSymbol] = req.request; } return undefined!; @@ -31,6 +32,7 @@ export default class DebugRequirePlugin implements WebpackPluginInstance { if (req.path !== false) { const inPath = path.relative(compiler.context, req.path); if (!inPath.startsWith("../") && !(nameSymbol in req)) { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions (req as NamedRequest)[nameSymbol] = "./" + inPath; } } @@ -40,6 +42,7 @@ export default class DebugRequirePlugin implements WebpackPluginInstance { resolver .getHook("beforeResolved") .tap("DebugRequirePlugin", (req: ResolveRequest) => { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions const name = (req as NamedRequest)[nameSymbol]; if (name !== undefined && req.path !== false) { const names = resolved.get(req.path);