Skip to content

🐛 False positive for lint/correctness/noUnusedPrivateClassMembers when using ??= #7192

@lgarron

Description

@lgarron

Environment information

CLI:
  Version:                      2.1.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  BIOME_THREADS:                unset
  NO_COLOR:                     unset
  TERM:                         xterm-256color
  JS_RUNTIME_VERSION:           v24.5.0
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         bun/1.2.19

Biome Configuration:
  Status:                       Loaded successfully
  Path:                         biome.json
  Formatter enabled:            true
  Linter enabled:               true
  Assist enabled:               true
  VCS enabled:                  false

Workspace:
  Open Documents:               0

What happened?

Repro link: https://biomejs.dev/playground/?indentStyle=space&indentWidth=4&bracketSameLine=true&code=YwBsAGEAcwBzACAAQQBwAHAAIAB7AAoAIAAgACMAcABlAHIAcwBpAHMAdABlAG4AYwBlAFIAZQBxAHUAZQBzAHQAOgAgAFAAcgBvAG0AaQBzAGUAPABiAG8AbwBsAGUAYQBuAD4AIAB8ACAAdQBuAGQAZQBmAGkAbgBlAGQAOwAKACAAIABzAGEAdgBlAEQAYQB0AGEAKAApACAAewAKACAAIAAgACAAdABoAGkAcwAuACMAcABlAHIAcwBpAHMAdABlAG4AYwBlAFIAZQBxAHUAZQBzAHQAIAA%2FAD8APQAgAG4AYQB2AGkAZwBhAHQAbwByAC4AcwB0AG8AcgBhAGcAZQAuAHAAZQByAHMAaQBzAHQAKAApADsACgAgACAAIAAgAC8ALwAgACYgCgAgACAAfQAKAH0ACgAKAG4AZQB3ACAAQQBwAHAAKAApADsA

Code:

class App {
  #persistenceRequest: Promise<boolean> | undefined;
  saveData() {
    this.#persistenceRequest ??= navigator.storage.persist();
    // …
  }
}

new App();

This results in a lint/correctness/noUnusedPrivateClassMembers error claiming that the .#persistenceRequest is field is unused. However, it is accessed on the line with ??= to gate a call to a function with side effects.

In fact, the linter will no longer error if you change it to essentially equivalent code:

this.#persistenceRequest = this.#persistenceRequest ?? navigator.storage.persist();

Expected result

No error.

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LinterArea: linterL-JavaScriptLanguage: JavaScript and super languagesS-Bug-confirmedStatus: report has been confirmed as a valid bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions