`noInvalidUseBeforeDeclaration` misses class declaration heritage, static members and computed keys
Environment information
CLI:
Version: 2.5.14
Platform:
CPU Architecture: x86_64
OS: linux
Environment:
BIOME_DISTRIBUTION: npm
JS_RUNTIME_NAME: nodeRule name
correctness/noInvalidUseBeforeDeclaration
Playground link
export function run() {
class A extends B {} // ReferenceError at runtime, not reported
class C { static p = B; } // not reported
class D { [B.name]() {} } // not reported
class E { static { B; } } // not reported
const e = new B(); // reported
class B {}
return [A, C, D, E, e];
}Only new B() is reported. The other four references are evaluated when the class declaration runs, before B is initialized, and each throws ReferenceError: Cannot access 'B' before initialization in Node. ESLint's no-use-before-define reports class A extends B {}.
The same references in a class expression (const A = class extends B {}) are reported, so this is specific to declarations. It looks like it came from #8157 (the fix for #8148). That PR treats the whole JsClassDeclaration and JsStaticInitializationBlockClassMember as running later, which is only true for method, accessor and constructor bodies and for instance field initializers.
Reproduced with the 2.5.14 CLI and in the playground (f74eb38).
Expected result
References in extends, computed member names, static field initializers, static blocks and decorators of a class declaration are reported like any other eager use. Instance fields and member bodies stay exempt, as fixed in #8148.
Code of Conduct
- I agree to follow Biome's Code of Conduct
Tool Use Disclaimer: Claude Code using Anthropic Opus 5.5 helped build the reproduction.
Source: biomejs/biome