Skip to content
Esc

@noctcore/eslint-plugin-three

v0.1.011 rules7 recommended4 opt-innamespace noctcore-three

A bad fit for code that never touches three.js, and it matches by syntax: a mesh handed to your own disposal helper is trusted to be disposed there.

three.js and React Three Fiber performance and leaks: capped pixel ratios, disposed GPU resources, camera projections that update, and frame loops that neither allocate nor re-render.

A 3D scene fails slowly. An uncapped pixel ratio, a geometry that is never disposed, a new Vector3() in the frame loop or a React state update on every frame all pass review and every test, then show up as dropped frames, a hot phone and GPU memory that climbs each time a component remounts. Neither TypeScript nor a generic linter knows what a frame loop or a GPU resource is; these rules do, without type information. They run only in files that import three, a three/* subpath, three-stdlib or an @react-three/* package (or a module you name in extraModules), so another engine’s camera.fov is left alone.

It will yell at you about setPixelRatio(window.devicePixelRatio) and a <Canvas dpr> above 2, geometries, materials and textures an effect creates and never disposes, the same resources built in a component body, new Vector3() and friends inside useFrame, state setters called on every frame, camera.fov changed without updateProjectionMatrix() and setMatrixAt() without instanceMatrix.needsUpdate. Four opt-in rules cover WebGL support checks that pass on software renderers, shadow maps above a size budget, and PCFSoftShadowMap and new Clock() on a three.js release that has deprecated them (the version is read from your package.json). It is a bad fit for code that never touches three.js, and it matches by syntax: a mesh handed to your own disposal helper is trusted to be disposed there.

Install
npm install --save-dev @noctcore/eslint-plugin-three @typescript-eslint/parser
# or: bun add -D / pnpm add -D @noctcore/eslint-plugin-three @typescript-eslint/parser

The recommended preset enables 7 of 11 rules. The rules board below builds the flat config: start from a preset, switch single rules between error and off, and copy the result.

Each rule links to its page, with the options it takes and Incorrect and Correct examples. A good first read is require-dispose.

7 of 11 at error

--fixsuggestionsneeds optionstype infoEach switch sets a rule to error or off.

capability-probe-performance-caveat
Require failIfMajorPerformanceCaveat: true on a WebGL getContext() call whose result is only tested, so a support check says no on software renderers.
opt-in
explicit-shadow-map-type
Disallow the deprecated PCFSoftShadowMap, named directly or selected through R3F <Canvas shadows>, from the three.js release that deprecated it (r182, or r186 for the WebGPU build).
opt-in
instanced-mesh-needs-update
Require instanceMatrix.needsUpdate (or instanceColor.needsUpdate) to be set in the function that calls setMatrixAt() (or setColorAt()) on an InstancedMesh.
recommended
no-allocation-in-frame-loop
Disallow constructing three.js math objects or GPU resources, or cloning an object's transform fields, inside a frame loop (useFrame, setAnimationLoop, a self-scheduling requestAnimationFrame function).
recommended
no-deprecated-clock
Disallow constructing the deprecated three.js Clock on three.js r183 or later, where Timer replaces it.
opt-in
no-react-state-in-frame-loop
Disallow calling a React state setter unconditionally inside a frame loop (useFrame, setAnimationLoop, a self-scheduling requestAnimationFrame function).
recommended
no-resource-creation-in-render
Disallow constructing three.js geometries, materials, textures, render targets or loaders directly in a React component body, where every render makes a new one.
recommended
renderer-dpr-cap
Disallow a renderer pixel ratio taken straight from devicePixelRatio or set above a cap, in setPixelRatio() and R3F <Canvas dpr>.
recommended
require-dispose
Require dispose() for three.js geometries, materials, textures and render targets that a React effect creates and puts in the scene.
recommended
shadow-map-size-cap
Disallow a light shadow.mapSize above a cap, set in code or through R3F shadow-mapSize props.
opt-in
update-projection-matrix-after-camera-change
Require camera.updateProjectionMatrix() after assigning a projection field (fov, aspect, near, far, zoom, orthographic bounds) in the same function.
recommended