Skip to content

Commit

Permalink
chore(infra/biome): rule noForEach
Browse files Browse the repository at this point in the history
  • Loading branch information
shulaoda committed Jul 22, 2024
1 parent 26d1cb6 commit 5c00535
Show file tree
Hide file tree
Showing 14 changed files with 1,796 additions and 1,786 deletions.
5 changes: 3 additions & 2 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"rules": {
"recommended": false,
"complexity": {
"useArrowFunction": "error"
"useArrowFunction": "error",
"noForEach": "error"
},
"style": {
"noUnusedTemplateLiteral": "error",
Expand Down Expand Up @@ -66,4 +67,4 @@
"clientKind": "git",
"useIgnoreFile": true
}
}
}
4 changes: 2 additions & 2 deletions packages/rspack-dev-server/src/ansiHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ var _closeTags: Record<
29: "</del>" // reset delete
};

[21, 22, 27, 28, 39, 49].forEach(n => {
for (const n of [21, 22, 27, 28, 39, 49]) {
_closeTags[n] = "</span>";
});
}

/**
* Normalize ';<seq>' | '<seq>' -> '<seq>'
Expand Down
20 changes: 10 additions & 10 deletions packages/rspack-dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class RspackDevServer extends WebpackDevServer {
? this.compiler.compilers
: [this.compiler];

compilers.forEach(compiler => {
for (const compiler of compilers) {
const mode = compiler.options.mode || process.env.NODE_ENV;
if (this.options.hot) {
if (mode === "production") {
Expand Down Expand Up @@ -140,15 +140,15 @@ export class RspackDevServer extends WebpackDevServer {
...compiler.options.resolve.alias
};
}
});
}

if (this.options.webSocketServer) {
compilers.forEach(compiler => {
for (const compiler of compilers) {
this.addAdditionalEntries(compiler);
new compiler.webpack.ProvidePlugin({
__webpack_dev_server_client__: this.getClientTransport()
}).apply(compiler);
});
}
}

// @ts-expect-error: `setupHooks` is private function in base class.
Expand All @@ -173,7 +173,7 @@ export class RspackDevServer extends WebpackDevServer {

let needForceShutdown = false;

signals.forEach(signal => {
for (const signal of signals) {
const listener = () => {
if (needForceShutdown) {
process.exit();
Expand All @@ -200,15 +200,15 @@ export class RspackDevServer extends WebpackDevServer {
this.listeners.push({ name: signal, listener });

process.on(signal, listener);
});
}
}

// Proxy WebSocket without the initial http request
// https://github.com/chimurai/http-proxy-middleware#external-websocket-upgrade
// @ts-expect-error: `webSocketProxies` is private function in base class.
this.webSocketProxies.forEach(webSocketProxy => {
for (const webSocketProxy of this.webSocketProxies) {
this.server.on("upgrade", webSocketProxy.upgrade);
}, this);
}
}

private override setupDevMiddleware() {
Expand All @@ -218,7 +218,7 @@ export class RspackDevServer extends WebpackDevServer {

private override setupMiddlewares() {
const middlewares: WebpackDevServer.Middleware[] = [];
middlewares.forEach(middleware => {
for (const middleware of middlewares) {
if (typeof middleware === "function") {
// @ts-expect-error
this.app.use(middleware);
Expand All @@ -229,7 +229,7 @@ export class RspackDevServer extends WebpackDevServer {
// @ts-expect-error
this.app.use(middleware.middleware);
}
});
}

// @ts-expect-error
super.setupMiddlewares();
Expand Down
10 changes: 6 additions & 4 deletions packages/rspack-plugin-react-refresh/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ class ReactRefreshRspackPlugin {
options: this.options
});

addEntries.prependEntries.forEach(entry => {
for (const entry of addEntries.prependEntries) {
new compiler.webpack.EntryPlugin(compiler.context, entry, {
name: undefined
}).apply(compiler);
});
addEntries.overlayEntries.forEach(entry => {
}

for (const entry of addEntries.overlayEntries) {
new compiler.webpack.EntryPlugin(compiler.context, entry, {
name: undefined
}).apply(compiler);
});
}

new compiler.webpack.ProvidePlugin({
$ReactRefreshRuntime$: reactRefreshPath
}).apply(compiler);
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/src/helper/legacy/copyDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const rimraf = require("rimraf");
module.exports = function copyDiff(src, dest, initial) {
fs.mkdirSync(dest, { recursive: true });
const files = fs.readdirSync(src);
files.forEach(filename => {
for (const filename of files) {
const srcFile = path.join(src, filename);
const destFile = path.join(dest, filename);
const directory = fs.statSync(srcFile).isDirectory();
Expand All @@ -30,5 +30,5 @@ module.exports = function copyDiff(src, dest, initial) {
}
}
}
});
}
};
8 changes: 5 additions & 3 deletions packages/rspack-test-tools/src/processor/normal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,20 @@ export class NormalProcessor<
.concat(testConfig.plugins || [])
.concat(function (this: TCompiler<T>) {
this.hooks.compilation.tap("TestCasesTest", compilation => {
[
const hooks: never[] = [
// CHANGE: the follwing hooks are not supported yet, so comment it out
// "optimize",
// "optimizeModules",
// "optimizeChunks",
// "afterOptimizeTree",
// "afterOptimizeAssets"
].forEach(hook => {
];

for (const hook of hooks) {
(compilation.hooks[hook] as any).tap("TestCasesTest", () =>
(compilation as any).checkConstraints()
);
});
}
});
}),
experiments: {
Expand Down
12 changes: 6 additions & 6 deletions packages/rspack-test-tools/src/processor/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export class StatsProcessor<
await super.compiler(context);
const instance = this.getCompiler(context).getCompiler()! as any;
const compilers = instance.compilers ? instance.compilers : [instance];
compilers.forEach((c: Compiler) => {
const ifs = c.inputFileSystem;
c.inputFileSystem = Object.create(ifs);
c.inputFileSystem.readFile = () => {
for (const compiler of compilers) {
const ifs = compiler.inputFileSystem;
compiler.inputFileSystem = Object.create(ifs);
compiler.inputFileSystem.readFile = () => {
const args = Array.prototype.slice.call(arguments);
const callback = args.pop();
ifs.readFile.apply(
Expand All @@ -66,7 +66,7 @@ export class StatsProcessor<
};

// CHANGE: The checkConstraints() function is currently not implemented in rspack
// c.hooks.compilation.tap("StatsTestCasesTest", compilation => {
// compiler.hooks.compilation.tap("StatsTestCasesTest", compilation => {
// [
// "optimize",
// "optimizeModules",
Expand All @@ -80,7 +80,7 @@ export class StatsProcessor<
// );
// });
// });
});
}
}

async check(env: ITestEnv, context: ITestContext) {
Expand Down
Loading

0 comments on commit 5c00535

Please sign in to comment.