Skip to content

linter: no-unused-private-class-members reported even though it's used in an expression #19989

@linkej-autodesk

Description

@linkej-autodesk

What version of Oxlint are you using?

1.51.0

What command did you run?

oxlint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

no config

What happened?

If a member #flag is used in an expression like this.#flag && console.log('spam');, that correctly reports no-unused-expressions but also incorrectly reports no-unused-private-class-members on #flag.

If we fixed no-unused-expressions, the no-unused-private-class-members would also disappear, but we're disabling no-unused-expressions since it's an old codebase with ~1k instances of that and we're used to that pattern.

More elaborate demonstration:

class Ok {
    #flag = false; // ok
    foo() {
        if (this.#flag) console.log('spam'); // ok
    }
    baz() {
      const x = false; // ok, does not report no-unused-var
      x && console.log('foo'); // ok, reports no-unused-expressions
    }
}

class Bug {
    #flag = false; // bug: reports no-unused-private-class-members
    foo() {
        this.#flag && console.log('spam'); // ok, reports no-unused-expressions
    }
}

export {Bug, Ok}

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions