diff --git a/biome.jsonc b/biome.jsonc index 0fa5b7eff3c..6688f9c3bc9 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -52,9 +52,7 @@ "noFallthroughSwitchClause": "off", "noConfusingVoidType": "off", "noPrototypeBuiltins": "off", - "noImplicitAnyLet": "off", "noAssignInExpressions": "off", - "noArrayIndexKey": "off", "noControlCharactersInRegex": "off", "noExplicitAny": "off" } @@ -78,4 +76,4 @@ "clientKind": "git", "useIgnoreFile": true } -} \ No newline at end of file +} diff --git a/packages/rspack-cli/src/cli.ts b/packages/rspack-cli/src/cli.ts index ecb900a8e56..079d1ee5389 100644 --- a/packages/rspack-cli/src/cli.ts +++ b/packages/rspack-cli/src/cli.ts @@ -60,7 +60,7 @@ export class RspackCLI { ? (config as MultiRspackOptions).some(i => i.watch) : (config as RspackOptions).watch; - let compiler; + let compiler: MultiCompiler | Compiler | null; try { compiler = rspack(config, isWatch ? callback : undefined); } catch (e) { @@ -80,13 +80,7 @@ export class RspackCLI { createColors(useColor?: boolean): RspackCLIColors { const { createColors, isColorSupported } = require("colorette"); - let shouldUseColor; - - if (useColor) { - shouldUseColor = useColor; - } else { - shouldUseColor = isColorSupported; - } + const shouldUseColor = useColor || isColorSupported; return { ...createColors({ useColor: shouldUseColor }), diff --git a/packages/rspack-dev-server/src/ansiHTML.ts b/packages/rspack-dev-server/src/ansiHTML.ts index 480a0cc50a2..52094c03caf 100644 --- a/packages/rspack-dev-server/src/ansiHTML.ts +++ b/packages/rspack-dev-server/src/ansiHTML.ts @@ -147,8 +147,8 @@ export default function ansiHTML(text: string) { this.splice(0, count); } }); - let seq; let rep = ""; + let seq: string; while ((seq = match[0])) { match.advance(1); rep += applySeq(seq); diff --git a/packages/rspack-dev-server/src/middleware.ts b/packages/rspack-dev-server/src/middleware.ts index 79d0419e44f..8d3068639fc 100644 --- a/packages/rspack-dev-server/src/middleware.ts +++ b/packages/rspack-dev-server/src/middleware.ts @@ -63,7 +63,7 @@ export function getRspackMemoryAssets( if (!buffer) { return next(); } - let contentType; + let contentType: string; if (filename === "") { contentType = "text/html; charset=utf-8"; } else { diff --git a/packages/rspack-test-tools/src/compare/format-code.ts b/packages/rspack-test-tools/src/compare/format-code.ts index efbc4b2787a..f883755d0b7 100644 --- a/packages/rspack-test-tools/src/compare/format-code.ts +++ b/packages/rspack-test-tools/src/compare/format-code.ts @@ -79,8 +79,8 @@ export function formatCode( } }, IfStatement(path) { - let consequentNode; - let alternateNode; + let consequentNode: T.Statement | undefined; + let alternateNode: T.Statement | undefined; if (options.ignoreBlockOnlyStatement) { const consequent = path.get("consequent"); if ( diff --git a/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts b/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts index 2454e79e81c..bd08436025f 100644 --- a/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts +++ b/packages/rspack-test-tools/src/plugin/webpack-module-placeholder-plugin.ts @@ -12,7 +12,7 @@ function createRenderRuntimeModulesFn(Template) { const source = new ConcatSource(); for (const module of runtimeModules) { const codeGenerationResults = renderContext.codeGenerationResults; - let runtimeSource; + let runtimeSource: string; if (codeGenerationResults) { runtimeSource = codeGenerationResults.getSource( module, @@ -72,7 +72,7 @@ export class WebpackModulePlaceholderPlugin { hooks.renderModulePackage.tap( "RuntimeDiffPlugin", (moduleSource, module) => { - let cacheEntry; + let cacheEntry: unknown; let cache = caches.get(compilation); if (cache === undefined) { caches.set(compilation, (cache = new WeakMap())); diff --git a/packages/rspack-test-tools/src/processor/defaults.ts b/packages/rspack-test-tools/src/processor/defaults.ts index b988748303a..932c270092d 100644 --- a/packages/rspack-test-tools/src/processor/defaults.ts +++ b/packages/rspack-test-tools/src/processor/defaults.ts @@ -22,7 +22,7 @@ const escapedCwdRegExp = new RegExp( "g" ); const normalize = (str: string) => { - let normalizedStr; + let normalizedStr: string; if (CURRENT_CWD.startsWith("/")) { normalizedStr = str.replace( new RegExp(quoteMeta(CURRENT_CWD), "g"), @@ -70,7 +70,7 @@ export class DefaultsConfigProcessor< ) { super({ options: context => { - let res; + let res: TCompilerOptions; if (typeof _defaultsConfigOptions.options === "function") { res = _defaultsConfigOptions.options(context); } else { diff --git a/packages/rspack-test-tools/src/processor/hook.ts b/packages/rspack-test-tools/src/processor/hook.ts index f5e4b51daea..fb76aa71d15 100644 --- a/packages/rspack-test-tools/src/processor/hook.ts +++ b/packages/rspack-test-tools/src/processor/hook.ts @@ -108,7 +108,7 @@ export class HookCasesContext extends TestContext { context._addSnapshot(args, "input", group); const output = cb.apply(this, args); if (output && typeof output.then === "function") { - let resolve; + let resolve: ((value: void | PromiseLike) => void) | undefined; context.promises.push(new Promise(r => (resolve = r))); return output .then((o: unknown) => { diff --git a/packages/rspack/etc/api.md b/packages/rspack/etc/api.md index a73d8eec833..51ee7a0da6a 100644 --- a/packages/rspack/etc/api.md +++ b/packages/rspack/etc/api.md @@ -4626,14 +4626,14 @@ export const HtmlRspackPlugin: { publicPath?: string | undefined; hash?: boolean | undefined; chunks?: string[] | undefined; - template?: string | undefined; - templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; - templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; - inject?: boolean | "head" | "body" | undefined; base?: string | { target?: "_self" | "_blank" | "_parent" | "_top" | undefined; href?: string | undefined; } | undefined; + template?: string | undefined; + templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; + templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; + inject?: boolean | "head" | "body" | undefined; scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined; excludeChunks?: string[] | undefined; sri?: "sha256" | "sha384" | "sha512" | undefined; @@ -4648,14 +4648,14 @@ export const HtmlRspackPlugin: { publicPath?: string | undefined; hash?: boolean | undefined; chunks?: string[] | undefined; - template?: string | undefined; - templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; - templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; - inject?: boolean | "head" | "body" | undefined; base?: string | { target?: "_self" | "_blank" | "_parent" | "_top" | undefined; href?: string | undefined; } | undefined; + template?: string | undefined; + templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; + templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; + inject?: boolean | "head" | "body" | undefined; scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined; excludeChunks?: string[] | undefined; sri?: "sha256" | "sha384" | "sha512" | undefined; @@ -4729,14 +4729,14 @@ const htmlRspackPluginOptions: z.ZodObject<{ publicPath?: string | undefined; hash?: boolean | undefined; chunks?: string[] | undefined; - template?: string | undefined; - templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; - templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; - inject?: boolean | "head" | "body" | undefined; base?: string | { target?: "_self" | "_blank" | "_parent" | "_top" | undefined; href?: string | undefined; } | undefined; + template?: string | undefined; + templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; + templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; + inject?: boolean | "head" | "body" | undefined; scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined; excludeChunks?: string[] | undefined; sri?: "sha256" | "sha384" | "sha512" | undefined; @@ -4749,14 +4749,14 @@ const htmlRspackPluginOptions: z.ZodObject<{ publicPath?: string | undefined; hash?: boolean | undefined; chunks?: string[] | undefined; - template?: string | undefined; - templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; - templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; - inject?: boolean | "head" | "body" | undefined; base?: string | { target?: "_self" | "_blank" | "_parent" | "_top" | undefined; href?: string | undefined; } | undefined; + template?: string | undefined; + templateContent?: string | ((args_0: Record, ...args_1: unknown[]) => string | Promise) | undefined; + templateParameters?: boolean | Record | ((args_0: Record, ...args_1: unknown[]) => Record | Promise>) | undefined; + inject?: boolean | "head" | "body" | undefined; scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined; excludeChunks?: string[] | undefined; sri?: "sha256" | "sha384" | "sha512" | undefined; diff --git a/packages/rspack/src/MultiCompiler.ts b/packages/rspack/src/MultiCompiler.ts index b8377b8368a..bbca1044531 100644 --- a/packages/rspack/src/MultiCompiler.ts +++ b/packages/rspack/src/MultiCompiler.ts @@ -66,7 +66,7 @@ export class MultiCompiler { compilers: Compiler[] | Record, options?: MultiCompilerOptions ) { - let normalizedCompilers; + let normalizedCompilers: Compiler[]; if (!Array.isArray(compilers)) { normalizedCompilers = Object.entries(compilers).map( ([name, compiler]) => { diff --git a/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts b/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts index a0f6a79c243..65eeb114966 100644 --- a/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts +++ b/packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts @@ -204,7 +204,11 @@ const HtmlRspackPluginImpl = create( } const rawTemplateParameters = c.templateParameters; - let templateParameters; + let templateParameters: + | boolean + | Record + | ((params: string) => Promise) + | undefined; if (typeof rawTemplateParameters === "function") { templateParameters = async (data: string) => { const newData = await rawTemplateParameters(JSON.parse(data)); diff --git a/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts b/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts index 8ea16ed9d32..6f2e9593db4 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/hmr/hotModuleReplacement.ts @@ -74,7 +74,7 @@ function getCurrentScriptUrl(moduleId: string) { } function updateCss(el: HTMLLinkElement & Record, url?: string) { - let normalizedUrl; + let normalizedUrl: string; if (!url) { if (!el.href) { return; diff --git a/packages/rspack/src/builtin-plugin/css-extract/loader.ts b/packages/rspack/src/builtin-plugin/css-extract/loader.ts index db07f2d8ec4..e49c2eb9eb6 100644 --- a/packages/rspack/src/builtin-plugin/css-extract/loader.ts +++ b/packages/rspack/src/builtin-plugin/css-extract/loader.ts @@ -106,9 +106,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { const callback = this.async(); const filepath = this.resourcePath; - let { publicPath } = - /** @type {Compilation} */ - this._compilation!.outputOptions; + let { publicPath } = this._compilation!.outputOptions; if (typeof options.publicPath === "string") { // eslint-disable-next-line prefer-destructuring @@ -141,9 +139,8 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { | { default: Record; __esModule: true } | Record ) => { - /** @type {Locals | undefined} */ let locals: Record | undefined; - let namedExport; + let namedExport: boolean; const esModule = typeof options.esModule !== "undefined" ? options.esModule : true; @@ -167,9 +164,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { locals = {}; } - /** @type {Locals} */ locals[key] = ( - originalExports as Record - )[key]; + locals[key] = (originalExports as Record)[key]; } } } else { @@ -228,10 +223,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { const localsString = identifiers .map( - ([id, key]) => - `\nvar ${id} = ${stringifyLocal( - /** @type {Locals} */ locals![key] - )};` + ([id, key]) => `\nvar ${id} = ${stringifyLocal(locals![key])};` ) .join(""); const exportsString = `export { ${identifiers @@ -284,7 +276,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) { `${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, { layer: options.layer, - publicPath: /** @type {Filename} */ publicPathForExtract, + publicPath: publicPathForExtract, baseUri: `${BASE_URI}/` }, (error, exports) => { diff --git a/packages/rspack/src/config/adapterRuleUse.ts b/packages/rspack/src/config/adapterRuleUse.ts index 27039e3d9c1..dc03f3c9eb8 100644 --- a/packages/rspack/src/config/adapterRuleUse.ts +++ b/packages/rspack/src/config/adapterRuleUse.ts @@ -253,16 +253,16 @@ function createRawModuleRuleUsesImpl( } return uses.map((use, index) => { - let o; + let o: string | undefined; let isBuiltin = false; if (use.loader.startsWith(BUILTIN_LOADER_PREFIX)) { - o = getBuiltinLoaderOptions(use.loader, use.options, options); + const temp = getBuiltinLoaderOptions(use.loader, use.options, options); // keep json with indent so miette can show pretty error - o = isNil(o) + o = isNil(temp) ? undefined - : typeof o === "string" - ? o - : JSON.stringify(o, null, 2); + : typeof temp === "string" + ? temp + : JSON.stringify(temp, null, 2); isBuiltin = true; } diff --git a/packages/rspack/src/lib/HookWebpackError.ts b/packages/rspack/src/lib/HookWebpackError.ts index 14667ad47d0..afdd6f4c731 100644 --- a/packages/rspack/src/lib/HookWebpackError.ts +++ b/packages/rspack/src/lib/HookWebpackError.ts @@ -73,7 +73,7 @@ export const makeWebpackErrorCallback = ( * @returns the result */ export const tryRunOrWebpackError = (fn: () => T, hook: string): T => { - let r; + let r: T; try { r = fn(); } catch (err) { diff --git a/packages/rspack/src/lib/cache/getLazyHashedEtag.ts b/packages/rspack/src/lib/cache/getLazyHashedEtag.ts index 567a2658c3b..3bad643325b 100644 --- a/packages/rspack/src/lib/cache/getLazyHashedEtag.ts +++ b/packages/rspack/src/lib/cache/getLazyHashedEtag.ts @@ -67,7 +67,7 @@ export const getter = ( obj: HashableObject, hashFunction: string | HashConstructor = "md4" ): LazyHashedEtag => { - let innerMap; + let innerMap: WeakMap | undefined; if (typeof hashFunction === "string") { innerMap = mapStrings.get(hashFunction); if (innerMap === undefined) { diff --git a/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts b/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts index 10d6f014b74..84cb9d62974 100644 --- a/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts +++ b/packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts @@ -125,7 +125,7 @@ const SIMPLE_PRINTERS: Record< nameMessage && versionMessage ? `${nameMessage} (${versionMessage})` : versionMessage || nameMessage || "Rspack"; - let statusMessage; + let statusMessage: string; if (errorsMessage && warningsMessage) { statusMessage = `compiled with ${errorsMessage} and ${warningsMessage}`; } else if (errorsMessage) { diff --git a/packages/rspack/src/stats/statsFactoryUtils.ts b/packages/rspack/src/stats/statsFactoryUtils.ts index e8e0e8afe7a..212f2198724 100644 --- a/packages/rspack/src/stats/statsFactoryUtils.ts +++ b/packages/rspack/src/stats/statsFactoryUtils.ts @@ -476,7 +476,7 @@ export const spaceLimited = ( if (limit < max) { // calculate how much we are over the size limit // this allows to approach the limit faster - let oversize; + let oversize: number; // If each group would take 1 line the total would be below the maximum // collapse some groups, keep items while ( diff --git a/packages/rspack/src/util/IterableHelpers.ts b/packages/rspack/src/util/IterableHelpers.ts index 48bf381419a..b44dbd5a736 100644 --- a/packages/rspack/src/util/IterableHelpers.ts +++ b/packages/rspack/src/util/IterableHelpers.ts @@ -9,7 +9,7 @@ */ export const last = (set: Iterable): T | undefined => { - let last; + let last: T | undefined; for (const item of set) last = item; return last; }; diff --git a/packages/rspack/src/util/bindingVersionCheck.ts b/packages/rspack/src/util/bindingVersionCheck.ts index f0a3b96a359..a1ae11f19d6 100644 --- a/packages/rspack/src/util/bindingVersionCheck.ts +++ b/packages/rspack/src/util/bindingVersionCheck.ts @@ -97,7 +97,7 @@ export const checkVersion = () => { return (result = platformArchAbi); } - let ADDON_VERSION; + let ADDON_VERSION: string; try { const BINDING_PKG_DIR = path.dirname( require.resolve("@rspack/binding/package.json") diff --git a/packages/rspack/src/util/cleverMerge.ts b/packages/rspack/src/util/cleverMerge.ts index 95e8eab13f1..bcb3b51188e 100644 --- a/packages/rspack/src/util/cleverMerge.ts +++ b/packages/rspack/src/util/cleverMerge.ts @@ -420,7 +420,7 @@ const mergeEntries = ( byValues: secondEntry.byValues }; } - let newBase; + let newBase: ObjectParsedPropertyEntry["base"]; const intermediateByValues = new Map(firstEntry.byValues); for (const [key, value] of intermediateByValues) { intermediateByValues.set( diff --git a/packages/rspack/src/util/hash/wasm-hash.ts b/packages/rspack/src/util/hash/wasm-hash.ts index 0c22a5b328c..04c7775fc92 100644 --- a/packages/rspack/src/util/hash/wasm-hash.ts +++ b/packages/rspack/src/util/hash/wasm-hash.ts @@ -86,7 +86,7 @@ class WasmHash { */ _updateWithShortString(data: string, encoding?: BufferEncoding): void { const { exports, buffered, mem, chunkSize } = this; - let endPos; + let endPos: number; if (data.length < 70) { if (!encoding || encoding === "utf-8" || encoding === "utf8") { endPos = buffered; diff --git a/website/components/builtIns/Table.tsx b/website/components/builtIns/Table.tsx index 12ad2893ba9..b306e1c19c4 100644 --- a/website/components/builtIns/Table.tsx +++ b/website/components/builtIns/Table.tsx @@ -72,15 +72,18 @@ export function Table(props: TableProps) { - {compiledValue.map((item: any, index: number) => ( - - {header.map(headerItem => ( - - {item[headerItem.key]} - - ))} - - ))} + {compiledValue.map((item: any, index: number) => { + const key = `row-${index}`; + return ( + + {header.map(headerItem => ( + + {item[headerItem.key]} + + ))} + + ); + })} );