Skip to content

Commit

Permalink
chore(infra/biome): enable more rules (#7387)
Browse files Browse the repository at this point in the history
* chore(infra/biome): enable noGlobalAssign

* chore: enable noSwitchDeclarations

* chore: enable noInvalidUseBeforeDeclaration

* chore: enable noExtraBooleanCast

* chore: enalbe noUselessEmptyExport

* chore: enable useOptionalChain

* chore: enable noUselessConstructor

* chore: enable noMultipleSpacesInRegularExpressionLiterals

* chore: enable noInnerDeclarations

* chore: enable noCommaOperator

* chore: fix code

* chore: lint js

* chore: update test snapshots

* chore: update test cases

* chore: enable useExponentiationOperator

* chore: enable useShorthandFunctionType

* chore: enable noArguments

* chore: enable noInferrableTypes

* chore: update

* chore: update snapshots

* chore: update snapshots

* chore: update snapshots

* chore: enable useSingleVarDeclarator

* chore: enable noEmptyInterface

* chore: enable noGlobalIsNan

* chore: enable noRedundantUseStrict

* chore: update test cases and snapshots

* chore: update snapshots

* chore: rebase

---------

Co-authored-by: SoonIter <sooniter@gmail.com>
  • Loading branch information
shulaoda and SoonIter authored Aug 1, 2024
1 parent bd5135f commit 6e86a14
Show file tree
Hide file tree
Showing 60 changed files with 176 additions and 280 deletions.
22 changes: 2 additions & 20 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,16 @@
"useKeyWithClickEvents": "off"
},
"complexity": {
"noMultipleSpacesInRegularExpressionLiterals": "off",
"noStaticOnlyClass": "off",
"noThisInStatic": "off",
"noUselessConstructor": "off",
"noBannedTypes": "off",
"useOptionalChain": "off",
"noUselessEmptyExport": "off",
"noExtraBooleanCast": "off"
"noBannedTypes": "off"
},
"correctness": {
"noConstructorReturn": "off",
"noSwitchDeclarations": "off",
"noInvalidUseBeforeDeclaration": "off",
"noInnerDeclarations": "off",
"noVoidTypeReturn": "off"
},
"style": {
"noCommaOperator": "off",
"useExponentiationOperator": "off",
"useShorthandFunctionType": "off",
"noArguments": "off",
"noInferrableTypes": "off",
"noParameterAssign": "off",
"useSingleVarDeclarator": "off",
"noNonNullAssertion": "off"
},
"performance": {
Expand All @@ -72,16 +58,12 @@
"noGlobalEval": "off"
},
"suspicious": {
"noEmptyInterface": "off",
"noGlobalAssign": "off",
"noGlobalIsNan": "off",
"noFallthroughSwitchClause": "off",
"noConfusingVoidType": "off",
"noPrototypeBuiltins": "off",
"noImplicitAnyLet": "off",
"noAssignInExpressions": "off",
"noArrayIndexKey": "off",
"noRedundantUseStrict": "off",
"noControlCharactersInRegex": "off",
"noExplicitAny": "off"
}
Expand All @@ -106,4 +88,4 @@
"clientKind": "git",
"useIgnoreFile": true
}
}
}
2 changes: 1 addition & 1 deletion packages/playground/cases/react/worker/src/worker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Button from "./Button";

onmessage = e => {
window.onmessage = () => {
Button.add();
postMessage(Button.get());
};
2 changes: 1 addition & 1 deletion packages/rspack-cli/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class BuildCommand implements RspackCommand {
logger.error(error);
process.exit(2);
}
if (stats && stats.hasErrors()) {
if (stats?.hasErrors()) {
process.exitCode = 1;
}
if (!compiler || !stats) {
Expand Down
23 changes: 11 additions & 12 deletions packages/rspack-dev-server/src/ansiHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ const _openTags: Record<string, string | ((m: Match) => Option<string>)> = {
// color
const mode = _colorMode[match[0]];
if (mode === "rgb") {
const r = match[1],
g = match[2],
b = match[3];
const r = match[1];
const g = match[2];
const b = match[3];
match.advance(4);
return `color: rgb(${r},${g},${b})`;
}
Expand All @@ -73,9 +73,9 @@ const _openTags: Record<string, string | ((m: Match) => Option<string>)> = {
// background color
const mode = _colorMode[match[0]];
if (mode === "rgb") {
const r = match[1],
g = match[2],
b = match[3];
const r = match[1];
const g = match[2];
const b = match[3];
match.advance(4);
return `background-color: rgb(${r},${g},${b})`;
}
Expand All @@ -95,8 +95,8 @@ const _closeTags: Record<
0: ansiCodes => {
if (!ansiCodes) return "</span>";
if (!ansiCodes.length) return "";
let code: Option<string>,
ret = "";
let code: Option<string>;
let ret = "";
while ((code = ansiCodes.pop())) {
const closeTag = _openTagToCloseTag[code];
if (closeTag) {
Expand Down Expand Up @@ -147,8 +147,8 @@ export default function ansiHTML(text: string) {
this.splice(0, count);
}
});
let seq,
rep = "";
let seq;
let rep = "";
while ((seq = match[0])) {
match.advance(1);
rep += applySeq(seq);
Expand All @@ -169,8 +169,7 @@ export default function ansiHTML(text: string) {
)(ansiCodes);
}
// If current sequence has been opened, close it.
if (!!~ansiCodes.indexOf(seq)) {
// eslint-disable-line no-extra-boolean-cast
if (ansiCodes.indexOf(seq) !== -1) {
ansiCodes.pop();
return "</span>";
}
Expand Down
9 changes: 6 additions & 3 deletions packages/rspack-lite-tapable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ export class SyncHook<
queried: QueriedHook<T, R, AdditionalOptions>,
...args: AsArray<T>
): R {
let result, error;
let result;
let error;
this.callAsyncStageRange(
queried,
// @ts-expect-error
Expand Down Expand Up @@ -514,7 +515,8 @@ export class SyncBailHook<
queried: QueriedHook<T, R, AdditionalOptions>,
...args: AsArray<T>
): R {
let result, error;
let result;
let error;
this.callAsyncStageRange(
queried,
// @ts-expect-error
Expand Down Expand Up @@ -593,7 +595,8 @@ export class SyncWaterfallHook<
queried: QueriedHook<T, AsArray<T>[0], AdditionalOptions>,
...args: AsArray<T>
): AsArray<T>[0] {
let result, error;
let result;
let error;
this.callAsyncStageRange(
queried,
// @ts-expect-error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function getAdditionalEntries({
devServer: any;
options: NormalizedPluginOptions;
}): AdditionalEntries {
/** @type {Record<string, string | number>} */
const resourceQuery: Record<string, string | number> = {};

if (devServer) {
Expand Down Expand Up @@ -78,12 +77,8 @@ export function getAdditionalEntries({
undefined,
undefined,
{
/**
* @param {string} string
* @returns {string}
*/
encodeURIComponent(string) {
return string;
encodeURIComponent(str: string): string {
return str;
}
}
);
Expand All @@ -95,8 +90,8 @@ export function getAdditionalEntries({

const overlayEntries = [
// Error overlay runtime
options.overlay &&
options.overlay.entry &&
options.overlay !== false &&
options.overlay?.entry &&
`${require.resolve(options.overlay.entry)}${queryString ? `?${queryString}` : ""}`
].filter(Boolean) as string[];

Expand Down
1 change: 0 additions & 1 deletion packages/rspack-test-tools/etc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,6 @@ export class WebpackDiffConfigPlugin {

// @public (undocumented)
export class WebpackModulePlaceholderPlugin {
constructor();
// (undocumented)
apply(compiler: any): void;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class TestCompilerManager<T extends ECompilerType>
});
}

watch(timeout: number = 1000) {
watch(timeout = 1000) {
if (!this.compilerInstance)
throw new Error("Compiler should be created before watch");
this.compilerInstance!.watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,63 +94,56 @@ module.exports = function checkArrayExpectation(
const diff = diffItems(array, expected, kind);

if (expected.length < array.length) {
return (
done(
new Error(
`More ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`
)
),
true
done(
new Error(
`More ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`
)
);

return true;
}
if (expected.length > array.length) {
return (
done(
new Error(
`Less ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`
)
),
true
done(
new Error(
`Less ${kind}s (${array.length} instead of ${expected.length}) while compiling than expected:\n\n${diff}\n\nCheck expected ${kind}s: ${expectedFilename}`
)
);
return true;
}
for (let i = 0; i < array.length; i++) {
if (Array.isArray(expected[i])) {
for (let j = 0; j < expected[i].length; j++) {
if (!check(expected[i][j], array[i])) {
return (
done(
new Error(
`${upperCaseKind} ${i}: ${explain(
array[i]
)} doesn't match ${explain(expected[i][j])}`
)
),
true
done(
new Error(
`${upperCaseKind} ${i}: ${explain(
array[i]
)} doesn't match ${explain(expected[i][j])}`
)
);

return true;
}
}
} else if (!check(expected[i], array[i]))
return (
done(
new Error(
`${upperCaseKind} ${i}: ${explain(
array[i]
)} doesn't match ${explain(expected[i])}`
)
),
true
} else if (!check(expected[i], array[i])) {
done(
new Error(
`${upperCaseKind} ${i}: ${explain(
array[i]
)} doesn't match ${explain(expected[i])}`
)
);
return true;
}
}
} else if (array.length > 0) {
return (
done(
new Error(
`${upperCaseKind}s while compiling:\n\n${array
.map(explain)
.join("\n\n")}`
)
),
true
done(
new Error(
`${upperCaseKind}s while compiling:\n\n${array
.map(explain)
.join("\n\n")}`
)
);
return true;
}
};
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/helper/legacy/copyDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function copyDiff(src, dest, initial) {
if (directory) {
copyDiff(srcFile, destFile, initial);
} else {
var content = fs.readFileSync(srcFile);
const content = fs.readFileSync(srcFile);
if (/^DELETE\s*$/.test(content.toString("utf-8"))) {
fs.unlinkSync(destFile);
} else if (/^DELETE_DIRECTORY\s*$/.test(content.toString("utf-8"))) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/helper/setup-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (process.env.DEBUG_INFO) {
process.stdout.write(`START1 ${name}\n`);
try {
const promise = fn();
if (promise && promise.then) {
if (promise?.then) {
return promise.then(
r => {
process.stdout.write(`DONE OK ${name}\n`);
Expand Down
6 changes: 2 additions & 4 deletions packages/rspack-test-tools/src/helper/util/identifier.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// @ts-nocheck
/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/

"use strict";
* MIT License http://www.opensource.org/licenses/mit-license.php
*/

const path = require("node:path");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function createRenderRuntimeModulesFn(Template) {
const caches = new WeakMap();

export class WebpackModulePlaceholderPlugin {
constructor() {}
apply(compiler) {
const { webpack } = compiler;
const {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ConfigProcessor<
options.output?.path &&
fs.existsSync(path.join(options.output.path!, `bundle${index}${ext}`))
) {
if (options.experiments && options.experiments.css) {
if (options.experiments?.css) {
const cssOutputPath = path.join(
options.output.path!,
(typeof options.output?.cssFilename === "string" &&
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 @@ -78,7 +78,7 @@ const serialize = (val: unknown, indent = 2, formatOverrides = {}) =>

export class HookCasesContext extends TestContext {
protected promises: Promise<void>[] = [];
protected count: number = 0;
protected count = 0;
protected snapshots: Record<
string | number,
Array<[string | Buffer, string]>
Expand Down
7 changes: 2 additions & 5 deletions packages/rspack-test-tools/src/processor/stats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-control-regex */

import fs from "node:fs";
import path from "node:path";
import type { Compiler, Stats } from "@rspack/core";
Expand Down Expand Up @@ -51,8 +49,7 @@ export class StatsProcessor<
for (const compiler of compilers) {
const ifs = compiler.inputFileSystem;
compiler.inputFileSystem = Object.create(ifs);
compiler.inputFileSystem.readFile = () => {
const args = Array.prototype.slice.call(arguments);
compiler.inputFileSystem.readFile = (...args: any[]) => {
const callback = args.pop();
ifs.readFile.apply(
ifs,
Expand Down Expand Up @@ -171,7 +168,7 @@ export class StatsProcessor<
actual = actual
.replace(/\r\n?/g, "\n")
// CHANGE: Remove potential line break and "|" caused by long text
.replace(/((ERROR|WARNING)([\s\S](?!|))*?)(\n )/g, "$1")
.replace(/((ERROR|WARNING)([\s\S](?!|))*?)(\n {2} )/g, "$1")
// CHANGE: Update the regular expression to replace the 'Rspack' version string
.replace(/Rspack [^ )]+(\)?) compiled/g, "Rspack x.x.x$1 compiled")
.replace(
Expand Down
Loading

2 comments on commit 6e86a14

@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-08-01 2f6696e) Current Change
10000_development-mode + exec 2.24 s ± 26 ms 2.26 s ± 45 ms +1.00 %
10000_development-mode_hmr + exec 699 ms ± 9.2 ms 721 ms ± 12 ms +3.12 %
10000_production-mode + exec 2.79 s ± 22 ms 2.8 s ± 30 ms +0.62 %
arco-pro_development-mode + exec 1.9 s ± 77 ms 1.89 s ± 77 ms -0.66 %
arco-pro_development-mode_hmr + exec 432 ms ± 3 ms 432 ms ± 2.8 ms -0.05 %
arco-pro_production-mode + exec 3.39 s ± 64 ms 3.43 s ± 79 ms +1.04 %
threejs_development-mode_10x + exec 1.77 s ± 19 ms 1.76 s ± 18 ms -0.27 %
threejs_development-mode_10x_hmr + exec 878 ms ± 10 ms 879 ms ± 6.8 ms +0.10 %
threejs_production-mode_10x + exec 5.49 s ± 37 ms 5.53 s ± 43 ms +0.62 %

@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 ❌ failure
_selftest ✅ success
nx ❌ failure
rspress ✅ success
rsbuild ✅ success
examples ✅ success

Please sign in to comment.