Skip to content

Commit

Permalink
chore(biome): useNumberNamespace and useConst (#7160)
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter authored Jul 15, 2024
1 parent f02a01f commit 123524d
Show file tree
Hide file tree
Showing 63 changed files with 174 additions and 157 deletions.
3 changes: 3 additions & 0 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"useArrowFunction": "error"
},
"style": {
"noNonNullAssertion": "off",
"useNumberNamespace": "error",
"useConst": "error",
"useImportType": "error",
"useExportType": "error"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/cases/file/missing-files/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test("missing files should be able to recover if being added back", async ({
page,
fileAction
}) => {
let overlay = page.frameLocator("#webpack-dev-server-client-overlay");
const overlay = page.frameLocator("#webpack-dev-server-client-overlay");
await expect(
overlay.getByText("Can't resolve './missing-file-1'")
).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/fixtures/pathInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function calcPathInfo(

export const pathInfoFixtures: Fixtures<PathInfoFixtures> = {
pathInfo: async ({}, use, { file, workerIndex }) => {
let pathInfo: PathInfo = await calcPathInfo(file, String(workerIndex));
const pathInfo: PathInfo = await calcPathInfo(file, String(workerIndex));
await use(pathInfo);
await fs.remove(pathInfo.tempProjectDir);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class RspackCLI {
process.env.RSPACK_CONFIG_VALIDATE = "loose";
process.env.WATCHPACK_WATCHER_LIMIT =
process.env.WATCHPACK_WATCHER_LIMIT || "20";
let nodeEnv = process?.env?.NODE_ENV;
let rspackCommandDefaultEnv =
const nodeEnv = process?.env?.NODE_ENV;
const rspackCommandDefaultEnv =
rspackCommand === "build" ? "production" : "development";
if (typeof options.nodeEnv === "string") {
process.env.NODE_ENV = nodeEnv || options.nodeEnv;
Expand Down Expand Up @@ -182,7 +182,7 @@ export class RspackCLI {
item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
}
if (isServe) {
let installed = (item.plugins ||= []).find(
const installed = (item.plugins ||= []).find(
item => item instanceof rspackCore.ProgressPlugin
);
if (!installed) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/src/ansiHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function _setTags(colors) {
var color = _styles[code];
var oriColor = colors[color] || "000";
_openTags[code] = "color:#" + oriColor;
code = parseInt(code);
code = Number.parseInt(code);
_openTags[(code + 10).toString()] = "background:#" + oriColor;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-dev-server/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function applyDevServerPatch() {
// @ts-expect-error
...args
) {
let stats = args[1];
const stats = args[1];

if (!stats) {
return;
Expand Down
14 changes: 7 additions & 7 deletions packages/rspack-lite-tapable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ export class HookBase<T, R, AdditionalOptions = UnsetAdditionalOptions>
}

export type StageRange = readonly [number, number];
export const minStage = -Infinity;
export const maxStage = Infinity;
export const minStage = Number.NEGATIVE_INFINITY;
export const maxStage = Number.POSITIVE_INFINITY;
const allStageRange = [minStage, maxStage] as const;
const i32MIN = -(2 ** 31);
const i32MAX = 2 ** 31 - 1;
Expand All @@ -346,7 +346,7 @@ export class QueriedHook<T, R, AdditionalOptions = UnsetAdditionalOptions> {
constructor(stageRange: StageRange, hook: HookBase<T, R, AdditionalOptions>) {
const tapsInRange: typeof hook.taps = [];
const [from, to] = stageRange;
for (let tap of hook.taps) {
for (const tap of hook.taps) {
const stage = tap.stage ?? 0;
if (from <= stage && stage < to) {
tapsInRange.push(tap);
Expand Down Expand Up @@ -417,7 +417,7 @@ export class SyncHook<
if (from === minStage) {
this._runCallInterceptors(...args2);
}
for (let tap of tapsInRange) {
for (const tap of tapsInRange) {
this._runTapInterceptors(tap);
try {
tap.fn(...args2);
Expand Down Expand Up @@ -485,7 +485,7 @@ export class SyncBailHook<
if (from === minStage) {
this._runCallInterceptors(...args2);
}
for (let tap of tapsInRange) {
for (const tap of tapsInRange) {
this._runTapInterceptors(tap);
let r = undefined;
try {
Expand Down Expand Up @@ -566,7 +566,7 @@ export class SyncWaterfallHook<
if (from === minStage) {
this._runCallInterceptors(...args2);
}
for (let tap of tapsInRange) {
for (const tap of tapsInRange) {
this._runTapInterceptors(tap);
try {
const r = tap.fn(...args2);
Expand Down Expand Up @@ -646,7 +646,7 @@ export class AsyncParallelHook<
};
if (tapsInRange.length === 0) return done();
let counter = tapsInRange.length;
for (let tap of tapsInRange) {
for (const tap of tapsInRange) {
this._runTapInterceptors(tap);
if (tap.type === "promise") {
const promise = tap.fn(...args2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function getSocketUrlParts(
}

/** @type {SocketUrlParts} */
let urlParts: SocketUrlParts = {} as SocketUrlParts;
const urlParts: SocketUrlParts = {} as SocketUrlParts;

// If the resource query is available,
// parse it and ignore everything we received from the script host.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function getAdditionalEntries({
options: NormalizedPluginOptions;
}): AdditionalEntries {
/** @type {Record<string, string | number>} */
let resourceQuery: Record<string, string | number> = {};
const resourceQuery: Record<string, string | number> = {};

if (devServer) {
const { client, https, http2, sockHost, sockPath, sockPort } = devServer;
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack-test-tools/src/case/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function createDiffCase(name: string, src: string, dist: string) {
compareMap.clear();
await tester.check(env);
});
for (let file of caseConfig.files!) {
for (const file of caseConfig.files!) {
describe(`Comparing "${file}"`, () => {
let moduleResults: TModuleCompareResult[] = [];
let runtimeResults: TModuleCompareResult[] = [];
Expand Down Expand Up @@ -137,7 +137,7 @@ function createDiffProcessor(config: IDiffProcessorOptions) {

function checkBundleFiles(name: string, dist: string, files: string[]) {
describe(`Checking ${name} dist files`, () => {
for (let file of files) {
for (const file of files) {
it(`${name}: ${file} should be generated`, () => {
expect(fs.existsSync(path.join(dist, file))).toBeTruthy();
});
Expand Down Expand Up @@ -172,7 +172,7 @@ function checkCompareResults(
).toEqual([]);
});
it(`all modules should be the same`, () => {
for (let result of getResults().filter(
for (const result of getResults().filter(
i => i.type === ECompareResultType.Different
)) {
console.log(`${result.name}:\n${result.detail}`);
Expand Down
8 changes: 4 additions & 4 deletions packages/rspack-test-tools/src/compare/comparator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface IDiffComparatorOptions {
export class DiffComparator {
constructor(private options: IDiffComparatorOptions) {}
async compare() {
for (let file of this.options.files!) {
for (const file of this.options.files!) {
try {
const result = compareFile(
path.join(this.options.rspackDist, file),
Expand All @@ -46,15 +46,15 @@ export class DiffComparator {
bootstrap: this.options.bootstrap
}
);
for (let reporter of this.options.reporters) {
for (const reporter of this.options.reporters) {
reporter.increment(file, result.modules["modules"] || []);
}
for (let reporter of this.options.reporters) {
for (const reporter of this.options.reporters) {
reporter.increment(file, result.modules["runtimeModules"] || []);
}
} catch (e) {
console.error(e);
for (let reporter of this.options.reporters) {
for (const reporter of this.options.reporters) {
reporter.failure(file);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/compare/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function compareFile(
bootstrap: compareOptions.bootstrap
});

for (let type of ["modules", "runtimeModules"]) {
for (const type of ["modules", "runtimeModules"]) {
const t = type as "modules" | "runtimeModules";
let moduleList: string[] = [];
if (compareOptions[t] === true) {
Expand Down Expand Up @@ -99,7 +99,7 @@ export function compareModules(
compareOptions: ICompareOptions
) {
const compareResults: TModuleCompareResult[] = [];
for (let name of modules) {
for (const name of modules) {
const renamed = replaceRuntimeModuleName(name);
const sourceContent =
sourceModules.has(renamed) &&
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 @@ -163,7 +163,7 @@ export function formatCode(
},
ObjectExpression(path) {
if (options.ignoreObjectPropertySequence) {
let result = [];
const result = [];
let safe = [];
while (path.node.properties.length || safe.length) {
const cur = path.node.properties.shift()!;
Expand Down Expand Up @@ -210,7 +210,7 @@ export function formatCode(
}

if (options.replacements) {
for (let { from, to } of options.replacements) {
for (const { from, to } of options.replacements) {
result = result.replaceAll(from, to);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const RUNTIME_MODULE_PARAM_REGEX = {
};

export function replaceRuntimeModuleName(raw: string) {
for (let [rspackName, webpackName] of Object.entries(
for (const [rspackName, webpackName] of Object.entries(
RUNTIME_MODULE_NAME_MAPPING
)) {
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/helper/directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function describeByWalk(
path.join(testId, caseName).split(".").shift()!
);
describeFn(name, () => {
let source = path.join(sourceBase, caseName);
const source = path.join(sourceBase, caseName);
let dist = "";
if (absoluteDist) {
dist = path.join(distBase, caseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class FakeDocument {

_onElementRemoved(element) {
const type = element._type;
let list = this._elementsByTagName.get(type);
const list = this._elementsByTagName.get(type);
const idx = list.indexOf(element);
list.splice(idx, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
describe("warmup", () => {
it("should warmup webpack", done => {
let webpack = require("@rspack/core");
let END = new Error("end warmup");
const END = new Error("end warmup");
webpack(
{
entry: "data:text/javascript,import 'data:text/javascript,'",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function checkSourceMap(
const path = require("path");

const sources = JSON.parse(outCodeMap).sources;
for (let source of sources) {
for (const source of sources) {
if (sources.filter(s => s === source).length > 1) {
throw new Error(
`Duplicate source ${JSON.stringify(source)} found in source map`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-nocheck
module.exports = () => {
let warnings = [];
const warnings = [];
let oldWarn;

beforeEach(done => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function createRenderRuntimeModulesFn(Template) {
runtimeSource = codeGenResult.sources.get("runtime");
}
if (runtimeSource) {
let identifier = module.identifier();
const identifier = module.identifier();
source.add(Template.toNormalComment(`start::${identifier}`) + "\n");
if (!module.shouldIsolate()) {
source.add(runtimeSource);
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/src/processor/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class BasicProcessor<T extends ECompilerType> implements ITestProcessor {
return;
}

for (let bundle of bundles!) {
for (const bundle of bundles!) {
const runnerFactory = context.getRunnerFactory(this._options.name);
if (!runnerFactory) {
throw new Error(`Test case ${this._options.name} is not runable`);
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/processor/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class BuiltinProcessor<
defaultOptions as TCompilerOptions<ECompilerType.Rspack>;
const testConfigFile = context.getSource("rspack.config.js");
if (fs.existsSync(testConfigFile)) {
let caseOptions = require(testConfigFile);
const caseOptions = require(testConfigFile);
if (caseOptions.entry) {
delete rspackDefaultOptions.entry;
}
Expand All @@ -166,7 +166,7 @@ export class BuiltinProcessor<
const htmlOptions = (rspackDefaultOptions as any).builtins?.html;
if (htmlOptions) {
if (Array.isArray(htmlOptions)) {
for (let item of htmlOptions) {
for (const item of htmlOptions) {
rspackDefaultOptions.plugins!.push(
new rspack.HtmlRspackPlugin(item)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/processor/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class DiffProcessor implements ITestProcessor {
}

const dist = context.getDist();
for (let file of this.options.files!) {
for (const file of this.options.files!) {
const rspackDist = path.join(dist, ECompilerType.Rspack, file);
const webpackDist = path.join(dist, ECompilerType.Webpack, file);
const result = compareFile(rspackDist, webpackDist, {
Expand Down Expand Up @@ -173,7 +173,7 @@ export class DiffProcessor implements ITestProcessor {
ignoreCssFilePath: this.options.ignoreCssFilePath,
replacements: this.options.replacements || []
};
for (let hash of this.hashes) {
for (const hash of this.hashes) {
formatOptions.replacements!.push({ from: hash, to: "fullhash" });
}
return formatOptions;
Expand Down
12 changes: 6 additions & 6 deletions packages/rspack-test-tools/src/processor/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export class HookCasesContext extends TestContext {
*/
snapped(cb: (...args: unknown[]) => Promise<unknown>, prefix = "") {
// eslint-disable-next-line
let context = this;
const context = this;
return function SNAPPED_HOOK(this: any, ...args: unknown[]) {
let group = prefix ? prefix : context.count++;
const group = prefix ? prefix : context.count++;
context._addSnapshot(args, "input", group);
let output = cb.apply(this, args);
const output = cb.apply(this, args);
if (output && typeof output.then === "function") {
let resolve;
context.promises.push(new Promise(r => (resolve = r)));
Expand Down Expand Up @@ -157,11 +157,11 @@ export class HookCasesContext extends TestContext {
await Promise.allSettled(this.promises);
if (!this.snapshotsList.length) return;

let snapshots = this.snapshotsList.reduce((acc, group, index) => {
let block = this.snapshots[group || index].reduce(
const snapshots = this.snapshotsList.reduce((acc, group, index) => {
const block = this.snapshots[group || index].reduce(
(acc, [content, name]) => {
name = `## ${name || `test: ${index}`}\n\n`;
let block = "```javascript\n" + content + "\n```\n";
const block = "```javascript\n" + content + "\n```\n";
return (acc += name + block + "\n");
},
""
Expand Down
Loading

2 comments on commit 123524d

@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 ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@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-07-15 7540e88) Current Change
10000_development-mode + exec 2.23 s ± 9.2 ms 2.25 s ± 20 ms +0.80 %
10000_development-mode_hmr + exec 698 ms ± 6.9 ms 696 ms ± 5.4 ms -0.25 %
10000_production-mode + exec 2.79 s ± 30 ms 2.84 s ± 31 ms +1.78 %
arco-pro_development-mode + exec 1.89 s ± 68 ms 1.91 s ± 66 ms +0.83 %
arco-pro_development-mode_hmr + exec 435 ms ± 1.7 ms 435 ms ± 3.1 ms -0.08 %
arco-pro_production-mode + exec 3.46 s ± 59 ms 3.45 s ± 84 ms -0.16 %
threejs_development-mode_10x + exec 1.69 s ± 17 ms 1.75 s ± 25 ms +3.82 %
threejs_development-mode_10x_hmr + exec 858 ms ± 16 ms 863 ms ± 7.8 ms +0.56 %
threejs_production-mode_10x + exec 5.66 s ± 39 ms 5.74 s ± 28 ms +1.37 %

Please sign in to comment.