Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(infra/biome): enable more rules #7387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
97f2dce
chore(infra/biome): enable noGlobalAssign
shulaoda Jul 31, 2024
87b315f
chore: enable noSwitchDeclarations
shulaoda Jul 31, 2024
102a06c
chore: enable noInvalidUseBeforeDeclaration
shulaoda Jul 31, 2024
3df1d50
chore: enable noExtraBooleanCast
shulaoda Jul 31, 2024
75103ea
chore: enalbe noUselessEmptyExport
shulaoda Jul 31, 2024
564e602
chore: enable useOptionalChain
shulaoda Jul 31, 2024
741d574
chore: enable noUselessConstructor
shulaoda Jul 31, 2024
cf6bab3
chore: enable noMultipleSpacesInRegularExpressionLiterals
shulaoda Jul 31, 2024
f612dd3
chore: enable noInnerDeclarations
shulaoda Jul 31, 2024
986307c
chore: enable noCommaOperator
shulaoda Jul 31, 2024
4483c0a
chore: fix code
shulaoda Jul 31, 2024
e021cfb
chore: lint js
shulaoda Jul 31, 2024
51c5e7f
chore: update test snapshots
shulaoda Jul 31, 2024
6e781c1
chore: update test cases
shulaoda Jul 31, 2024
1abc8a2
chore: enable useExponentiationOperator
shulaoda Jul 31, 2024
1eb9060
chore: enable useShorthandFunctionType
shulaoda Jul 31, 2024
7a24a11
chore: enable noArguments
shulaoda Jul 31, 2024
8b44cff
chore: enable noInferrableTypes
shulaoda Jul 31, 2024
5aa2ed9
chore: update
shulaoda Jul 31, 2024
9a234e2
chore: update snapshots
shulaoda Jul 31, 2024
3e9de40
chore: update snapshots
shulaoda Jul 31, 2024
916b646
chore: update snapshots
shulaoda Jul 31, 2024
b9c5ec4
chore: enable useSingleVarDeclarator
shulaoda Jul 31, 2024
855d283
chore: enable noEmptyInterface
shulaoda Jul 31, 2024
8e0c68e
chore: enable noGlobalIsNan
shulaoda Jul 31, 2024
f991aa6
chore: enable noRedundantUseStrict
shulaoda Jul 31, 2024
39d3f76
chore: update test cases and snapshots
shulaoda Jul 31, 2024
578d46c
chore: update snapshots
shulaoda Aug 1, 2024
06376fd
chore: rebase
SoonIter Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
SoonIter marked this conversation as resolved.
Show resolved Hide resolved
.replace(/Rspack [^ )]+(\)?) compiled/g, "Rspack x.x.x$1 compiled")
.replace(
Expand Down
Loading
Loading