denoland / deno_lint

Blazing fast linter for JavaScript and TypeScript written in Rust
https://lint.deno.land/
MIT License
1.51k stars 163 forks source link

Class marked as unused when used in a static block #1259

Open nicolo-ribaudo opened 3 months ago

nicolo-ribaudo commented 3 months ago
let BluethootDevice_create;
class BluethootDevice {
  #id!: string;

  static #allowConstruct = false;

  private constructor() {
    if (!BluethootDevice.#allowConstruct) {
      throw new Error("You cannot instantiate this class directly");
    }
  }

  static {
    BluethootDevice_create = (id: string) => {
      BluethootDevice.#allowConstruct = true;
      const device = new BluethootDevice();
      BluethootDevice.#allowConstruct = false;
      device.#id = id;
      return device;
    };
  }

  get id() {
    return this.#id;
  }
}

BluethootDevice_create("aa");

deno_lint marks BluethootDevice as unused and tells me to rename it to _BluethootDevice, but it's used by the BluethootDevice_create.