Skip to content

Commit

Permalink
chore: enable noForEach rule of Biome (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Mar 14, 2024
1 parent a8912a9 commit 0337d69
Show file tree
Hide file tree
Showing 55 changed files with 229 additions and 203 deletions.
3 changes: 0 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"noExplicitAny": "off",
"noConfusingVoidType": "off"
},
"complexity": {
"noForEach": "off"
},
"performance": {
"noDelete": "off"
}
Expand Down
8 changes: 4 additions & 4 deletions e2e/cases/filename-hash/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ rspackOnlyTest('should allow to set hash format to fullhash', async () => {
const files = await rsbuild.unwrapOutputJSON();
const filenames = Object.keys(files);

let firstHash: string;
let firstHash = '';

filenames.forEach((filename) => {
for (const filename of filenames) {
if (!filename.includes('static')) {
return;
continue;
}

const hash = filename.match(/[a-f0-9]{12}\.js/)![0];
Expand All @@ -22,5 +22,5 @@ rspackOnlyTest('should allow to set hash format to fullhash', async () => {
} else {
expect(hash).toEqual(firstHash);
}
});
}
});
12 changes: 6 additions & 6 deletions e2e/cases/output/assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ const cases = [
},
];

cases.forEach((_case) => {
test(_case.name, async ({ page }) => {
for (const item of cases) {
test(item.name, async ({ page }) => {
const rsbuild = await build({
cwd: _case.cwd,
cwd: item.cwd,
runServer: true,
plugins: [pluginReact()],
rsbuildConfig: _case.config || {},
rsbuildConfig: item.config || {},
});

await gotoPage(page, rsbuild);

if (_case.expected === 'url') {
if (item.expected === 'url') {
await expect(
page.evaluate(
`document.getElementById('test-img').src.includes('static/image/icon')`,
Expand All @@ -94,4 +94,4 @@ cases.forEach((_case) => {

await rsbuild.close();
});
});
}
4 changes: 2 additions & 2 deletions e2e/cases/performance/remove-console/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const expectConsoleType = async (
)!;
const content = files[indexFile];

Object.entries(consoleType).forEach(([key, value]) => {
for (const [key, value] of Object.entries(consoleType)) {
expect(content.includes(`test-console-${key}`)).toEqual(value);
});
}
};

test('should remove specified console correctly', async () => {
Expand Down
4 changes: 2 additions & 2 deletions e2e/cases/server/custom-server/scripts/pure-server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export async function startDevServerPure(fixtures) {
res.end('Hello World!');
});

middlewares.forEach((item) => {
for (const item of middlewares) {
if (Array.isArray(item)) {
app.use(...item);
} else {
app.use(item);
}
});
}

app.get('/bbb', (_req, res) => {
res.end('Hello Express!');
Expand Down
4 changes: 2 additions & 2 deletions e2e/cases/server/custom-server/scripts/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ export async function startDevServer(fixtures) {
res.end('Hello World!');
});

middlewares.forEach((item) => {
for (const item of middlewares) {
if (Array.isArray(item)) {
app.use(...item);
} else {
app.use(item);
}
});
}

app.get('/bbb', (_req, res) => {
res.end('Hello Express!');
Expand Down
4 changes: 2 additions & 2 deletions e2e/cases/solid/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ rspackOnlyTest(
);

// test cases for css preprocessors
['less', 'scss', 'stylus'].forEach((name) => {
for (const name of ['less', 'scss', 'stylus']) {
rspackOnlyTest(
`should build solid component with ${name}`,
async ({ page }) => {
Expand All @@ -74,4 +74,4 @@ rspackOnlyTest(
rsbuild.close();
},
);
});
}
4 changes: 2 additions & 2 deletions e2e/cases/source/plugin-import/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('should import with template config', async () => {
expect(files[entry]).toContain('transformImport test succeed');
});

cases.forEach((c) => {
for (const c of cases) {
const [name, entry, config] = c;
shareTest(`${name}-rspack`, entry, config);
});
}
4 changes: 2 additions & 2 deletions e2e/cases/svelte/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ rspackOnlyTest(
);

// test cases for css preprocessors
['less', 'scss', 'stylus'].forEach((name) => {
for (const name of ['less', 'scss', 'stylus']) {
rspackOnlyTest(
`should build svelte component with ${name}`,
async ({ page }) => {
Expand All @@ -118,4 +118,4 @@ rspackOnlyTest(
rsbuild.close();
},
);
});
}
8 changes: 5 additions & 3 deletions e2e/scripts/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const proxyConsole = (
const logs: string[] = [];
const restores: Array<() => void> = [];

castArray(types).forEach((type) => {
for (const type of castArray(types)) {
const method = console[type];

restores.push(() => {
Expand All @@ -80,12 +80,14 @@ export const proxyConsole = (
console[type] = (log) => {
logs.push(log);
};
});
}

return {
logs,
restore: () => {
restores.forEach((restore) => restore());
for (const restore of restores) {
restore();
}
},
};
};
4 changes: 2 additions & 2 deletions packages/babel-preset/src/pluginLockCorejsVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getCoreJsVersion = () => {
export default (_: any) => {
return {
post({ path }: any) {
path.node.body.forEach((node: t.Node) => {
for (const node of path.node.body as t.Node[]) {
// import
if (t.isImportDeclaration(node)) {
const key = matchedKey(node.source.value);
Expand Down Expand Up @@ -55,7 +55,7 @@ export default (_: any) => {
}
}
}
});
}
},
};
};
10 changes: 5 additions & 5 deletions packages/compat/webpack/src/core/devMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const applyHMREntry = (

// apply dev server to client compiler, add hmr client to entry.
if (isMultiCompiler(compiler)) {
compiler.compilers.forEach((target) => {
for (const target of compiler.compilers) {
applyEntry(clientPath, target);
});
}
} else {
applyEntry(clientPath, compiler);
}
Expand All @@ -41,9 +41,9 @@ const setupHooks = (
hookCallbacks: IHookCallbacks,
) => {
if (isMultiCompiler(compiler)) {
compiler.compilers.forEach((compiler) =>
setupServerHooks(compiler, hookCallbacks),
);
for (const target of compiler.compilers) {
setupServerHooks(target, hookCallbacks);
}
} else {
setupServerHooks(compiler, hookCallbacks);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/webpack/src/core/webpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async function modifyWebpackChain(
);

if (context.config.tools?.webpackChain) {
castArray(context.config.tools.webpackChain).forEach((item) => {
for (const item of castArray(context.config.tools.webpackChain)) {
item(modifiedChain, utils);
});
}
}

debug('modify webpack chain done');
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/webpack/src/plugins/less.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export function pluginLess(): RsbuildPlugin {
.rule(utils.CHAIN_ID.RULE.LESS)
.test(LESS_REGEX);

excludes.forEach((item) => {
for (const item of excludes) {
rule.exclude.add(item);
});
}

await applyBaseCSSRule({
rule,
Expand Down
4 changes: 2 additions & 2 deletions packages/compat/webpack/src/plugins/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export function pluginSass(): RsbuildPlugin {
.rule(utils.CHAIN_ID.RULE.SASS)
.test(SASS_REGEX);

excludes.forEach((item) => {
for (const item of excludes) {
rule.exclude.add(item);
});
}

await applyBaseCSSRule({
rule,
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/loadEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,38 +55,38 @@ export function loadEnv({

const parsed: Record<string, string> = {};

filePaths.forEach((envPath) => {
for (const envPath of filePaths) {
Object.assign(parsed, parse(fs.readFileSync(envPath)));
});
}

expand({ parsed });

const publicVars: Record<string, string> = {};

Object.keys(process.env).forEach((key) => {
for (const key of Object.keys(process.env)) {
const val = process.env[key];
if (val && prefixes.some((prefix) => key.startsWith(prefix))) {
publicVars[`process.env.${key}`] = JSON.stringify(val);
}
});
}

let cleaned = false;
const cleanup = () => {
if (cleaned) {
return;
}

Object.keys(parsed).forEach((key) => {
for (const key of Object.keys(parsed)) {
// do not cleanup NODE_ENV,
// otherwise the .env.${mode} file will not be loaded
if (key === 'NODE_ENV') {
return;
continue;
}

if (process.env[key] === parsed[key]) {
delete process.env[key];
}
});
}

cleaned = true;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/mergeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ const merge = (x: unknown, y: unknown, path = '') => {
const merged: Record<string, unknown> = {};
const keys = new Set([...Object.keys(x), ...Object.keys(y)]);

keys.forEach((key) => {
for (const key of keys) {
const childPath = path ? `${path}.${key}` : key;
merged[key] = merge(x[key], y[key], childPath);
});
}

return merged;
};
Expand Down
34 changes: 19 additions & 15 deletions packages/core/src/pluginManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export function createPluginManager(): PluginManager {
) => {
const { before } = options || {};

newPlugins.forEach((newPlugin) => {
for (const newPlugin of newPlugins) {
if (!newPlugin) {
return;
continue;
}

validatePlugin(newPlugin);
Expand All @@ -81,7 +81,7 @@ export function createPluginManager(): PluginManager {
} else {
plugins.push(newPlugin);
}
});
}
};

const removePlugins = (pluginNames: string[]) => {
Expand Down Expand Up @@ -112,19 +112,23 @@ export const pluginDagSort = (plugins: RsbuildPlugin[]): RsbuildPlugin[] => {
return target;
}

plugins.forEach((plugin) => {
plugin.pre?.forEach((pre) => {
if (pre && plugins.some((item) => item.name === pre)) {
allLines.push([pre, plugin.name]);
for (const plugin of plugins) {
if (plugin.pre) {
for (const pre of plugin.pre) {
if (pre && plugins.some((item) => item.name === pre)) {
allLines.push([pre, plugin.name]);
}
}
});
}

plugin.post?.forEach((post) => {
if (post && plugins.some((item) => item.name === post)) {
allLines.push([plugin.name, post]);
if (plugin.post) {
for (const post of plugin.post) {
if (post && plugins.some((item) => item.name === post)) {
allLines.push([plugin.name, post]);
}
}
});
});
}
}

// search the zero input plugin
let zeroEndPoints = plugins.filter(
Expand All @@ -149,10 +153,10 @@ export const pluginDagSort = (plugins: RsbuildPlugin[]): RsbuildPlugin[] => {
// if has ring, throw error
if (allLines.length) {
const restInRingPoints: Record<string, boolean> = {};
allLines.forEach((l) => {
for (const l of allLines) {
restInRingPoints[l[0]] = true;
restInRingPoints[l[1]] = true;
});
}

throw new Error(
`plugins dependencies has loop: ${Object.keys(restInRingPoints).join(
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const pluginEntry = (): RsbuildPlugin => ({
const injectCoreJsEntry =
config.output.polyfill === 'entry' && !isServer && !isServiceWorker;

Object.keys(entry).forEach((entryName) => {
for (const entryName of Object.keys(entry)) {
const entryPoint = chain.entry(entryName);
const addEntry = (item: string | EntryDescription) => {
entryPoint.add(item);
Expand All @@ -52,7 +52,7 @@ export const pluginEntry = (): RsbuildPlugin => ({
}

castArray(entry[entryName]).forEach(addEntry);
});
}
},
);

Expand Down
Loading

0 comments on commit 0337d69

Please sign in to comment.