Skip to content

Adding eslint rule to avoid forEach #16515

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const rules = {
jest: true,
},
plugins: [
"github",
// "react"
"prettier",
"jest",
Expand All @@ -191,6 +192,7 @@ const rules = {
"plugin:jest/recommended",
// "plugin:jsdoc/recommended",
"plugin:prettier/recommended",
// "plugin:github/recommended",
],
settings: {
react: {
Expand Down Expand Up @@ -263,6 +265,7 @@ const rules = {
"no-fallthrough": "warn",
"no-async-promise-executor": "warn",
"no-throw-literal": "error",
"github/array-foreach": "error",
},
};

Expand Down
4,451 changes: 3,809 additions & 642 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"concurrently": "~8.0.1",
"dotenv": "~16.0.0",
"es-check": "^7.1.1",
"eslint": "^8.11.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "~9.0.0",
"eslint-formatter-azure-devops": "^1.2.0",
"eslint-plugin-github": "^5.1.8",
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-jest": "~27.4.3",
"eslint-plugin-jsdoc": "~46.2.6",
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/addJSToCompiledFiles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable github/array-foreach */
/* eslint-disable no-console */
import * as fs from "fs";
import { globSync } from "glob";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/buildShaders.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import * as fs from "fs";
import * as path from "path";
import { checkDirectorySync, checkArgs, getHashOfFile, getHashOfContent } from "./utils.js";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/copyAssets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import { globSync } from "glob";
import * as path from "path";
import { copyFile, checkArgs } from "./utils.js";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/declarationsEs6.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable github/array-foreach */
import { checkArgs } from "./utils.js";
import * as fs from "fs";
import * as path from "path";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/devWatcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import { checkArgs, findRootDirectory } from "./utils.js";
import { spawn } from "child_process";

Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/generateDeclaration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import { globSync } from "glob";
import * as fs from "fs";
import * as path from "path";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/ltsTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import * as path from "path";
import * as ts from "typescript";
import * as fs from "fs";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/packageMapping.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable github/array-foreach */
import { kebabize } from "./utils.js";

export type BuildType = /*"lts" | */ "umd" | "esm" | "es6" | "namespace";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/prepareEs6Build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import * as path from "path";
import { globSync } from "glob";
import * as fs from "fs-extra";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/prepareSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable github/array-foreach */
import * as fs from "fs";
import { globSync } from "glob";
import * as path from "path";
Expand Down
1 change: 1 addition & 0 deletions packages/dev/buildTools/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-console */
/* eslint-disable github/array-foreach */
import * as fs from "fs";
import * as path from "path";
import * as dotenv from "dotenv";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable github/array-foreach */
import type { Nullable } from "core/types";
import type { Camera } from "../Cameras/camera";
import type { DirectionalLight } from "../Lights/directionalLight";
Expand Down
12 changes: 7 additions & 5 deletions packages/dev/core/src/Engines/Native/nativePipelineContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ export class NativePipelineContext implements IPipelineContext {
}

const effectAvailableUniforms = this._engine.getUniforms(this, uniformsNames);
effectAvailableUniforms.forEach((uniform, index) => {
for (let index = 0; index < effectAvailableUniforms.length; index++) {
const uniform = effectAvailableUniforms[index];

uniforms[uniformsNames[index]] = uniform;
});
}
this._uniforms = uniforms;

let index: number;
Expand All @@ -78,9 +80,9 @@ export class NativePipelineContext implements IPipelineContext {
}
}

samplerList.forEach((name, index) => {
samplers[name] = index;
});
for (index = 0; index < samplerList.length; index++) {
samplers[samplerList[index]] = index;
}

attributes.push(...engine.getAttributes(this, attributesNames));
}
Expand Down
13 changes: 8 additions & 5 deletions packages/dev/core/src/Engines/WebGL/webGLPipelineContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ export class WebGLPipelineContext implements IPipelineContext {
}

const effectAvailableUniforms = this.engine.getUniforms(this, uniformsNames);
effectAvailableUniforms.forEach((uniform, index) => {

for (let index = 0; index < effectAvailableUniforms.length; index++) {
const uniform = effectAvailableUniforms[index];

uniforms[uniformsNames[index]] = uniform;
});
}
this._uniforms = uniforms;

let index: number;
Expand All @@ -84,9 +87,9 @@ export class WebGLPipelineContext implements IPipelineContext {
}
}

samplerList.forEach((name, index) => {
samplers[name] = index;
});
for (index = 0; index < samplerList.length; index++) {
samplers[samplerList[index]] = index;
}

for (const attr of engine.getAttributes(this, attributesNames)) {
attributes.push(attr);
Expand Down
2 changes: 2 additions & 0 deletions packages/dev/core/src/Engines/webgpuEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
} else {
this._adapter = adapter!;
this._adapterSupportedExtensions = [];
// eslint-disable-next-line github/array-foreach
this._adapter.features?.forEach((feature) => {
this._adapterSupportedExtensions.push(feature as WebGPUConstants.FeatureName);
});
Expand Down Expand Up @@ -682,6 +683,7 @@ export class WebGPUEngine extends ThinWebGPUEngine {
.then((device: GPUDevice) => {
this._device = device;
this._deviceEnabledExtensions = [];
// eslint-disable-next-line github/array-foreach
this._device.features?.forEach((feature) => {
this._deviceEnabledExtensions.push(feature as WebGPUConstants.FeatureName);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class FlowGraphJsonPointerParserBlock<P extends any, O extends FlowGraphA
};
});
}
// eslint-disable-next-line github/array-foreach
accessorContainer.info.interpolation?.forEach((info, index) => {
const name = accessorContainer.info.getPropertyName?.[index](accessorContainer.object) || "Animation-interpolation-" + index;
// generate the keys based on interpolation info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask {

context.setDepthStates(this.depthTest && depthEnabled, this.depthWrite && depthEnabled);

// eslint-disable-next-line github/array-foreach
this._clearAttachmentsLayout.forEach((layout, clearType) => {
context.clearColorAttachments(clearColors[clearType], layout);
});
Expand Down Expand Up @@ -445,6 +446,7 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask {
}
}

// eslint-disable-next-line github/array-foreach
clearAttachmentsLayout.forEach((layout, clearType) => {
layout.push(clearType === geometryDescription.clearType);
});
Expand All @@ -454,6 +456,7 @@ export class FrameGraphGeometryRendererTask extends FrameGraphTask {

this._clearAttachmentsLayout = new Map();

// eslint-disable-next-line github/array-foreach
clearAttachmentsLayout.forEach((layout, clearType) => {
this._clearAttachmentsLayout.set(clearType, this._engine.buildTextureLayout(layout));
});
Expand Down
6 changes: 6 additions & 0 deletions packages/dev/core/src/FrameGraph/frameGraphTextureManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ export class FrameGraphTextureManager {
public computeTotalTextureSize(optimizedSize: boolean, outputWidth: number, outputHeight: number) {
let totalSize = 0;

// eslint-disable-next-line github/array-foreach
this._textures.forEach((entry, handle) => {
if (handle === backbufferColorTextureHandle || handle === backbufferDepthStencilTextureHandle || entry.refHandle !== undefined) {
return;
Expand Down Expand Up @@ -446,6 +447,7 @@ export class FrameGraphTextureManager {
this._optimizeTextureAllocation(tasks);
}

// eslint-disable-next-line github/array-foreach
this._textures.forEach((entry) => {
if (!entry.texture) {
if (entry.refHandle !== undefined) {
Expand Down Expand Up @@ -510,6 +512,7 @@ export class FrameGraphTextureManager {
}
});

// eslint-disable-next-line github/array-foreach
this._historyTextures.forEach((entry) => {
for (let i = 0; i < entry.handles.length; i++) {
entry.textures[i] = this._textures.get(entry.handles[i])!.texture;
Expand All @@ -519,6 +522,7 @@ export class FrameGraphTextureManager {

/** @internal */
public _releaseTextures(releaseAll = true): void {
// eslint-disable-next-line github/array-foreach
this._textures.forEach((entry, handle) => {
if (entry.lifespan) {
entry.lifespan.firstTask = Number.MAX_VALUE;
Expand All @@ -544,6 +548,7 @@ export class FrameGraphTextureManager {
}
});

// eslint-disable-next-line github/array-foreach
this._historyTextures.forEach((entry) => {
for (let i = 0; i < entry.handles.length; i++) {
entry.textures[i] = null;
Expand All @@ -559,6 +564,7 @@ export class FrameGraphTextureManager {

/** @internal */
public _updateHistoryTextures(): void {
// eslint-disable-next-line github/array-foreach
this._historyTextures.forEach((entry) => {
entry.index = entry.index ^ 1;
const currentTexture = entry.textures[entry.index];
Expand Down
3 changes: 3 additions & 0 deletions packages/dev/core/src/Gizmos/gizmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ export class Gizmo implements IGizmo {
if (forcePointerUp || pointerInfo.type === PointerEventTypes.POINTERUP) {
// On Mouse Up

// eslint-disable-next-line github/array-foreach
gizmoAxisCache.forEach((cache) => {
cache.active = false;
dragging = false;
Expand All @@ -635,6 +636,7 @@ export class Gizmo implements IGizmo {
if (dragging) {
return;
}
// eslint-disable-next-line github/array-foreach
gizmoAxisCache.forEach((cache) => {
if (cache.colliderMeshes && cache.gizmoMeshes) {
const isHovered = cache.colliderMeshes?.indexOf(pointerInfo?.pickInfo?.pickedMesh as Mesh) != -1;
Expand All @@ -655,6 +657,7 @@ export class Gizmo implements IGizmo {
activeDragButton = pointerInfo.event.button;
const statusMap = gizmoAxisCache.get(pointerInfo.pickInfo.pickedMesh?.parent as Mesh);
statusMap!.active = true;
// eslint-disable-next-line github/array-foreach
gizmoAxisCache.forEach((cache) => {
const isHovered = cache.colliderMeshes?.indexOf(pointerInfo?.pickInfo?.pickedMesh as Mesh) != -1;
const material = (isHovered || cache.active) && cache.dragBehavior.enabled ? cache.hoverMaterial : cache.disableMaterial;
Expand Down
1 change: 1 addition & 0 deletions packages/dev/core/src/Gizmos/gizmoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ export class GizmoManager implements IDisposable {
*/
public addToAxisCache(gizmoAxisCache: Map<Mesh, GizmoAxisCache>) {
if (gizmoAxisCache.size > 0) {
// eslint-disable-next-line github/array-foreach
gizmoAxisCache.forEach((v, k) => {
this._gizmoAxisCache.set(k, v);
});
Expand Down
5 changes: 5 additions & 0 deletions packages/dev/core/src/Loading/loadingScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export class DefaultLoadingScreen implements ILoadingScreen {
this._resizeLoadingUI();
});

// eslint-disable-next-line github/array-foreach
this._loadingDivToRenderingCanvasMap.forEach((_, loadingDiv) => {
document.body.appendChild(loadingDiv);
});
Expand Down Expand Up @@ -250,6 +251,7 @@ export class DefaultLoadingScreen implements ILoadingScreen {
}
};

// eslint-disable-next-line github/array-foreach
this._loadingDivToRenderingCanvasMap.forEach((_, loadingDiv) => {
loadingDiv.style.opacity = "0";
});
Expand All @@ -264,6 +266,7 @@ export class DefaultLoadingScreen implements ILoadingScreen {
this._loadingText = text;

if (this._loadingTextDiv) {
// eslint-disable-next-line github/array-foreach
this._loadingDivToRenderingCanvasMap.forEach((_, loadingDiv) => {
// set loadingTextDiv of current loadingDiv
loadingDiv.children[0].innerHTML = this._loadingText;
Expand All @@ -289,6 +292,7 @@ export class DefaultLoadingScreen implements ILoadingScreen {
return;
}

// eslint-disable-next-line github/array-foreach
this._loadingDivToRenderingCanvasMap.forEach((_, loadingDiv) => {
loadingDiv.style.backgroundColor = this._loadingDivBackgroundColor;
});
Expand Down Expand Up @@ -326,6 +330,7 @@ export class DefaultLoadingScreen implements ILoadingScreen {
return;
}

// eslint-disable-next-line github/array-foreach
this._loadingDivToRenderingCanvasMap.forEach(([canvas, previousCanvasRect], loadingDiv) => {
const currentCanvasRect = canvas.getBoundingClientRect();
if (this._isCanvasLayoutChanged(previousCanvasRect, currentCanvasRect)) {
Expand Down
1 change: 1 addition & 0 deletions packages/dev/core/src/Materials/shadowDepthWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export class ShadowDepthWrapper {
const depthWrapperEntries = this._subMeshToDepthWrapper.mm.get(subMesh);
if (depthWrapperEntries) {
// find and release the previous depth effect
// eslint-disable-next-line github/array-foreach
depthWrapperEntries.forEach((depthWrapper) => {
depthWrapper.mainDrawWrapper.effect?.dispose();
});
Expand Down
1 change: 1 addition & 0 deletions packages/dev/core/src/Meshes/geometry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class Geometry implements IGetSetVerticesData {
buffers.add(this._vertexBuffers[key].getWrapperBuffer());
}

// eslint-disable-next-line github/array-foreach
buffers.forEach((buffer) => {
buffer._rebuild();
});
Expand Down
1 change: 1 addition & 0 deletions packages/dev/core/src/Meshes/mesh.vertexData.subdivide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ function smooth(vertexData: VertexData, options: ISubdivideOptions): VertexData
if (options.preserveEdges) {
const edgeSet = existingEdges[positionHash];
let hasPair = true;
// eslint-disable-next-line github/array-foreach
edgeSet.forEach((edgeHash) => {
if (flatOpposites[edgeHash] && flatOpposites[edgeHash].length % 2 !== 0) {
hasPair = false;
Expand Down
3 changes: 3 additions & 0 deletions packages/dev/core/src/Meshes/meshUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export function computeMaxExtents(
const perBoneCorners = new Map<number, Array<Vector3>>();
skinnedMeshCorners.set(mesh.uniqueId, perBoneCorners);

// eslint-disable-next-line github/array-foreach
perBoneExtents.forEach((extent, boneIndex) => {
const corners = getExtentCorners(extent);

Expand Down Expand Up @@ -184,6 +185,7 @@ export function computeMaxExtents(

const bones = skeleton.bones;
const perBoneCorners = skinnedMeshCorners.get(mesh.uniqueId)!;
// eslint-disable-next-line github/array-foreach
perBoneCorners.forEach((corners, boneIndex) => {
// Transform the per-bone corners into world space and update the max extent for each corner.
for (const corner of corners) {
Expand Down Expand Up @@ -238,6 +240,7 @@ export function RemoveUnreferencedVerticesData(meshes: readonly Mesh[]) {
}
}

// eslint-disable-next-line github/array-foreach
unreferencedUVSets.forEach((unreferencedUVSet) => {
if (mesh.isVerticesDataPresent(unreferencedUVSet)) {
mesh.removeVerticesData(unreferencedUVSet);
Expand Down
Loading