Skip to content

Bug: [class-methods-use-this] Cannot detect a problematic case for private/protected members if ignoreClassesThatImplementAnInterface option is true #7704

Closed
@tetsuharuohzeki

Description

@tetsuharuohzeki

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.2&showAST=es&fileType=.ts&code=JYOwLgpgTgZghgYwgAgEJysg3sgUM5OACgEoAuZANwHtgATAblwF9dcEAbOAZ2%2BQEFkwALYAHDhGERwfdJhz5CpCjXrZkrAqKjBKcSMgBGyqrTrZWzIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6M%2BAQ2WVoFtE%2BABYB7ACa9YyRLWGVUGANqQA7p2hNIAGkzhsEVqyiUA5kxHREAeQBuiaFTGIAsoNET0YfHERa9%2ByFNzSwBhLh4UABUhTnwAST5iJAEWAEEmOJZ7ADNOMkRPb1hEfzAAXwBdPTKQMqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

interface Bar { 
  a(): void;
}

class A implements Bar { 
  a(): void { }
  private b(): void {}
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/class-methods-use-this": ["warn", {
      "ignoreClassesThatImplementAnInterface": true
    }]
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

I think the rule should warn about the implementation of A.b() in the above code.
Because TypeScript's interface feature does not have any private/protected member as a part of it.

So the rule enabling ignoreClassesThatImplementAnInterface=true should warn the case of that the implementation is not a part of interface.

Actual Result

In the above code, the rule does not warn about implementation of A.b().

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions