noctcore-three/explicit-shadow-map-type
noctcore-three/explicit-shadow-map-type
- Package
- three v0.1.0
- Preset
- none opt-in
- Severity
- off
- Autofix
- No
- Suggestions
- No
- Options
- Optional
- Type info
- Not needed
No deprecated PCFSoftShadowMap, named or picked by <Canvas shadows>.
three.js r182 made PCFShadowMap filter softly and deprecated PCFSoftShadowMap for
WebGLRenderer (migration guide, 181 to 182: “Use PCFShadowMap which is now soft as well”).
From r183 that renderer logs “PCFSoftShadowMap has been deprecated. Using PCFShadowMap instead.”
and swaps the type itself. WebGPURenderer kept its own soft filter until r186 (migration guide,
185 to 186), which removed it, warns the same way and marked the constant @deprecated. Code that
still asks for the soft type gets a console warning and the other filter.
// rule options: {"threeVersion":182}import { PCFSoftShadowMap, WebGLRenderer } from 'three';
const renderer = new WebGLRenderer({ antialias: true });renderer.shadowMap.enabled = true;renderer.shadowMap.type = PCFSoftShadowMap;// rule options: {"threeVersion":182}import { PCFShadowMap, WebGLRenderer } from 'three';
const renderer = new WebGLRenderer({ antialias: true });renderer.shadowMap.enabled = true;renderer.shadowMap.type = PCFShadowMap;React Three Fiber hides the same choice behind a shorthand. Up to 9.x, <Canvas shadows> sets
gl.shadowMap.type = PCFSoftShadowMap, and so do shadows={true} and shadows="soft". The
shortest way to turn shadows on therefore asks for the deprecated type. Name the type instead:
// rule options: {"threeVersion":186,"fiberVersion":9}import { Canvas } from '@react-three/fiber';
export const App = () => ( <Canvas shadows> <Scene /> </Canvas>);// rule options: {"threeVersion":186,"fiberVersion":9}import { Canvas } from '@react-three/fiber';
export const App = () => ( <Canvas shadows="percentage"> <Scene /> </Canvas>);What it flags
Section titled “What it flags”From the release that deprecated the type for the renderer the file uses:
- every use of
PCFSoftShadowMapimported fromthreeorthree/webgpu(named, renamed, or asTHREE.PCFSoftShadowMapthroughimport * as THREE), wherever it is used: an assignment toshadowMap.type, a comparison, the object form<Canvas shadows={{ type: PCFSoftShadowMap }}>; - when the project is known to run React Three Fiber below 10, the
shadowsprop of<Canvas>(imported from@react-three/fiber) written asshadows,shadows={true}orshadows="soft".
Which release that is depends on the renderer, read from the file’s imports:
| The file imports | Reported from |
|---|---|
three/webgpu or three/tsl (the WebGPU build), or one of extraModules (a re-export that may be either build) |
r186 |
anything else (three, add-ons, @react-three/*) |
r182 |
React Three Fiber 10 (checked at 10.0.0-alpha.6) maps shadows, shadows={true} and
shadows="soft" to PCFShadowMap, so there the shorthand is fine and only the constant is
reported. Every release up to 9.8.2 maps them to PCFSoftShadowMap.
The three.js version is read in this order:
- the
threeVersionoption, when set; - the
threerange in the nearestpackage.jsonthat declares it. The lowest version the range allows counts:^0.182.0is r182, and>=0.170.0is r170 even when r187 is installed, so a library that still supports an older release is not told to drop a type that release needs; - the installed copy under
node_modules, when no manifest declares a range the rule can read (acatalog:orworkspace:protocol, a tag such aslatest, a URL).
“Below 10” for React Three Fiber is read the other way round, because there an open range must
not be taken for its lowest version: the fiberVersion option when set; else the
@react-three/fiber range, when every version it allows is below 10 (^9.8.2, >=8 <10); else,
for a range that is open upwards (>=9, *) or is not a version range, the installed copy.
Both lookups walk from the linted file’s directory up to the workspace root (the directory with a
lockfile or .git). Without a workspace root they stop at the first directory that has a
package.json, and with no package.json above the file either nothing is read and the
version is unknown.
// rule options: {"threeVersion":186,"fiberVersion":9}import * as THREE from 'three';import { Canvas } from '@react-three/fiber';
export const Preview = () => <Canvas shadows="soft" />;export const Stage = () => <Canvas shadows={{ type: THREE.PCFSoftShadowMap }} />;// rule options: {"threeVersion":186,"fiberVersion":9}import * as THREE from 'three';import { Canvas } from '@react-three/fiber';
export const Preview = () => <Canvas shadows="percentage" />;export const Stage = () => <Canvas shadows={{ type: THREE.PCFShadowMap }} />;Reads package.json
Section titled “Reads package.json”Without the two options, the verdict depends on package.json files and on node_modules.
ESLint’s --cache does not see an edit to either, so after an upgrade a cached file keeps its old
result until it changes; see
rules that read other files.
What it does not flag
Section titled “What it does not flag”- Files that import neither
three(or athree/*subpath),three-stdlib, an@react-three/*package nor one ofextraModules: the rule only runs in three.js code, so another engine’s API with the same names (a Phaser or Babylon camera) is never read as three.js. Only staticimportdeclarations count: a file that loads three.js only throughimport()orrequire()is skipped, which can hide a report but never adds one. - Any project below r182, and any project whose three.js version cannot be read (no option, no
manifest that declares
three, no installed copy): an unknown version reports nothing. - A file that renders through
WebGPURendererwithout importingthree/webgpuorthree/tslitself (the renderer is created elsewhere): it is read asWebGLRenderercode, and reported from r182. <Canvas shadows>when the project is not known to run React Three Fiber below 10: version 10 or later, a range that can reach 10 with no installed copy below it, or no version at all. The constant is still reported there.PCFSoftShadowMapon r182 to r185 in a file that importsthree/webgpu,three/tslor one ofextraModules:WebGPURendererstill has its own soft filter on those releases.shadows="basic",shadows="percentage",shadows="variance",shadows={false}, and a value the rule cannot read (shadows={quality.shadows}).- A
shadowsprop on anything that is not React Three Fiber’sCanvas, and aPCFSoftShadowMapthat is not three.js’s (a local constant, a property of another object). - An import of
PCFSoftShadowMapthat is never used. - A renderer that never sets a type: three.js defaults to
PCFShadowMap.
// rule options: {"threeVersion":181,"fiberVersion":9}import { Canvas } from '@react-three/fiber';
export const App = () => ( <Canvas shadows> <Scene /> </Canvas>);Options
Section titled “Options”| Option | Type | Default | Meaning |
|---|---|---|---|
threeVersion |
integer |
read from disk | The three.js revision the project uses (182 for r182, published as 0.182.x). Overrides the version read from package.json and node_modules. |
fiberVersion |
integer |
read from disk | The React Three Fiber major the project uses (9 for 9.x). Overrides what is read from package.json and node_modules. |
allowIn |
string[] (globs) |
[] |
Files the rule skips, matched against the absolute path and the path relative to the working directory or workspace root. |
extraModules |
string[] |
[] |
More module specifiers that mark a file as three.js code (a project module that re-exports three.js, such as @acme/engine); subpaths match too, and their imports count as three.js classes and R3F hooks. |
'noctcore-three/explicit-shadow-map-type': ['error', { threeVersion: 186, fiberVersion: 9 }]Set the options when the versions on disk are not the ones that ship: a monorepo whose lint runs
from a directory with no three in reach, or a range kept wide for other reasons.
When not to use it
Section titled “When not to use it”A library that supports three.js releases older than r182 and declares that range in
peerDependencies is already left alone: the lowest version of the range decides, and on r181
PCFSoftShadowMap is a filter of its own. Leave the rule off if the console warning does not
bother you. It is opt-in because the deprecated type still renders (as PCFShadowMap), so when to
rename it is the project’s call.
Checked against three.js r181 (no deprecation), r182 (deprecated for WebGLRenderer), r183, r185
(WebGPURenderer still has its soft filter), r186 (removed there) and r187, and against React
Three Fiber 8.18.0, 9.0.0 to 9.8.2, and 10.0.0-alpha.6.
Related
Section titled “Related”no-deprecated-clock: the other rule that depends on the installed three.js version.shadow-map-size-cap: the cost side of shadows, a map size above a budget.