Skip to content

Commit

Permalink
chore(infra/biome): enable noImplicitAnyLet and noArrayIndexKey r…
Browse files Browse the repository at this point in the history
…ules (#7843)

* chore(infra/biome): enable noImplicitAny and react/no-array-index-key rules

* chore: update api.md
  • Loading branch information
shulaoda authored Sep 10, 2024
1 parent 5aa2f24 commit be2ee96
Show file tree
Hide file tree
Showing 23 changed files with 66 additions and 75 deletions.
4 changes: 1 addition & 3 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
"noFallthroughSwitchClause": "off",
"noConfusingVoidType": "off",
"noPrototypeBuiltins": "off",
"noImplicitAnyLet": "off",
"noAssignInExpressions": "off",
"noArrayIndexKey": "off",
"noControlCharactersInRegex": "off",
"noExplicitAny": "off"
}
Expand All @@ -78,4 +76,4 @@
"clientKind": "git",
"useIgnoreFile": true
}
}
}
10 changes: 2 additions & 8 deletions packages/rspack-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/src/ansiHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/compare/format-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()));
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/processor/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -70,7 +70,7 @@ export class DefaultsConfigProcessor<
) {
super({
options: context => {
let res;
let res: TCompilerOptions<T>;
if (typeof _defaultsConfigOptions.options === "function") {
res = _defaultsConfigOptions.options(context);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>) => void) | undefined;
context.promises.push(new Promise(r => (resolve = r)));
return output
.then((o: unknown) => {
Expand Down
32 changes: 16 additions & 16 deletions packages/rspack/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4626,14 +4626,14 @@ export const HtmlRspackPlugin: {
publicPath?: string | undefined;
hash?: boolean | undefined;
chunks?: string[] | undefined;
template?: string | undefined;
templateContent?: string | ((args_0: Record<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | 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<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
inject?: boolean | "head" | "body" | undefined;
scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined;
excludeChunks?: string[] | undefined;
sri?: "sha256" | "sha384" | "sha512" | undefined;
Expand All @@ -4648,14 +4648,14 @@ export const HtmlRspackPlugin: {
publicPath?: string | undefined;
hash?: boolean | undefined;
chunks?: string[] | undefined;
template?: string | undefined;
templateContent?: string | ((args_0: Record<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | 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<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
inject?: boolean | "head" | "body" | undefined;
scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined;
excludeChunks?: string[] | undefined;
sri?: "sha256" | "sha384" | "sha512" | undefined;
Expand Down Expand Up @@ -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<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | 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<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
inject?: boolean | "head" | "body" | undefined;
scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined;
excludeChunks?: string[] | undefined;
sri?: "sha256" | "sha384" | "sha512" | undefined;
Expand All @@ -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<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | 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<string, any>, ...args_1: unknown[]) => string | Promise<string>) | undefined;
templateParameters?: boolean | Record<string, string> | ((args_0: Record<string, any>, ...args_1: unknown[]) => Record<string, any> | Promise<Record<string, any>>) | undefined;
inject?: boolean | "head" | "body" | undefined;
scriptLoading?: "module" | "blocking" | "defer" | "systemjs-module" | undefined;
excludeChunks?: string[] | undefined;
sri?: "sha256" | "sha384" | "sha512" | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/MultiCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class MultiCompiler {
compilers: Compiler[] | Record<string, Compiler>,
options?: MultiCompilerOptions
) {
let normalizedCompilers;
let normalizedCompilers: Compiler[];
if (!Array.isArray(compilers)) {
normalizedCompilers = Object.entries(compilers).map(
([name, compiler]) => {
Expand Down
6 changes: 5 additions & 1 deletion packages/rspack/src/builtin-plugin/HtmlRspackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ const HtmlRspackPluginImpl = create(
}

const rawTemplateParameters = c.templateParameters;
let templateParameters;
let templateParameters:
| boolean
| Record<string, any>
| ((params: string) => Promise<string>)
| undefined;
if (typeof rawTemplateParameters === "function") {
templateParameters = async (data: string) => {
const newData = await rawTemplateParameters(JSON.parse(data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function getCurrentScriptUrl(moduleId: string) {
}

function updateCss(el: HTMLLinkElement & Record<string, any>, url?: string) {
let normalizedUrl;
let normalizedUrl: string;
if (!url) {
if (!el.href) {
return;
Expand Down
18 changes: 5 additions & 13 deletions packages/rspack/src/builtin-plugin/css-extract/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -141,9 +139,8 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) {
| { default: Record<string, any>; __esModule: true }
| Record<string, any>
) => {
/** @type {Locals | undefined} */
let locals: Record<string, string> | undefined;
let namedExport;
let namedExport: boolean;

const esModule =
typeof options.esModule !== "undefined" ? options.esModule : true;
Expand All @@ -167,9 +164,7 @@ export const pitch: LoaderDefinition["pitch"] = function (request, _, data) {
locals = {};
}

/** @type {Locals} */ locals[key] = (
originalExports as Record<string, string>
)[key];
locals[key] = (originalExports as Record<string, string>)[key];
}
}
} else {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) => {
Expand Down
12 changes: 6 additions & 6 deletions packages/rspack/src/config/adapterRuleUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/lib/HookWebpackError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const makeWebpackErrorCallback = <T>(
* @returns the result
*/
export const tryRunOrWebpackError = <T>(fn: () => T, hook: string): T => {
let r;
let r: T;
try {
r = fn();
} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/lib/cache/getLazyHashedEtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const getter = (
obj: HashableObject,
hashFunction: string | HashConstructor = "md4"
): LazyHashedEtag => {
let innerMap;
let innerMap: WeakMap<HashableObject, LazyHashedEtag> | undefined;
if (typeof hashFunction === "string") {
innerMap = mapStrings.get(hashFunction);
if (innerMap === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/stats/DefaultStatsPrinterPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/stats/statsFactoryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/util/IterableHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

export const last = <T>(set: Iterable<T>): T | undefined => {
let last;
let last: T | undefined;
for (const item of set) last = item;
return last;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/util/bindingVersionCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/util/cleverMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/util/hash/wasm-hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 12 additions & 9 deletions website/components/builtIns/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ export function Table(props: TableProps) {
</ModernTableRow>
</thead>
<tbody>
{compiledValue.map((item: any, index: number) => (
<ModernTableRow key={index}>
{header.map(headerItem => (
<ModernTableData key={headerItem.key}>
{item[headerItem.key]}
</ModernTableData>
))}
</ModernTableRow>
))}
{compiledValue.map((item: any, index: number) => {
const key = `row-${index}`;
return (
<ModernTableRow key={key}>
{header.map(headerItem => (
<ModernTableData key={headerItem.key}>
{item[headerItem.key]}
</ModernTableData>
))}
</ModernTableRow>
);
})}
</tbody>
</ModernTable>
);
Expand Down

2 comments on commit be2ee96

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-09-10 8134f86) Current Change
10000_development-mode + exec 2.2 s ± 26 ms 2.22 s ± 29 ms +0.83 %
10000_development-mode_hmr + exec 689 ms ± 14 ms 698 ms ± 13 ms +1.32 %
10000_production-mode + exec 2.86 s ± 43 ms 2.81 s ± 30 ms -1.54 %
arco-pro_development-mode + exec 1.88 s ± 74 ms 1.87 s ± 73 ms -0.35 %
arco-pro_development-mode_hmr + exec 434 ms ± 2.5 ms 434 ms ± 1.3 ms +0.03 %
arco-pro_production-mode + exec 3.24 s ± 123 ms 3.28 s ± 67 ms +1.06 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.31 s ± 86 ms 3.35 s ± 60 ms +1.11 %
threejs_development-mode_10x + exec 1.69 s ± 16 ms 1.69 s ± 19 ms +0.08 %
threejs_development-mode_10x_hmr + exec 808 ms ± 13 ms 807 ms ± 12 ms -0.09 %
threejs_production-mode_10x + exec 5.18 s ± 34 ms 5.18 s ± 29 ms +0.10 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success

Please sign in to comment.