Skip to content

Enhancement: [naming-convention] add support for #private members #6258

@hlysine

Description

@hlysine

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=4.9.4&sourceType=module&code=MYGwhgzhAEAqCmEAu0DeBYAUNaB6X0SAFovNAJYAm8AdkuQGbnwBOMERA9gK4iXQ1OKALZgkwItAacWopDADu5YoRLQARAAduAIxDlg66MM6VGzFlhwBiTS3IA3MfABizPtAC80AIwBuK2hbeyckeABZeGJTAAoASjQAXyxEoA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6JgQwFtmBzWsgHsmAN0QtKw9GADa4bDkTRog6JAA08hVgXZIAM1VcO+aTMgBlfFTL4ACh2RkO8AMKPEkALqbde5IhItqrSkGTwjsh2KqTQRBpaupBcggAmlPqUSqgY5sSwAEaMZN6JEAC+vro6fgZGJmaQyNaUtu5cge4B3lW1AUH4IRhhEchRMUrxZWCV0zVJhtDGprmWLbYOTi5dnj7TOP2IwWrD4ZEAsoj4ABZpCX44KemZ2Y35Ra2lfrN+8wp1Swaq2aNnw7U6Hh6+ygh2OoTOY0uNzu03KiS88jR5SAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

class Test {
  // these identifiers should not match formats with the "public" modifier
  #privateField = 1;
  #privateMethod() {}
}

ESLint Config

{
  "rules": {
    "@typescript-eslint/naming-convention": [
      "error",
      {
        "format": ["StrictPascalCase"],
        "selector": "classProperty",
        "modifiers": ["public"]
      },
      {
        "format": ["strictCamelCase"],
        "selector": "classProperty"
      },
      {
        "format": ["StrictPascalCase"],
        "selector": "classMethod",
        "modifiers": ["public"]
      },
      {
        "format": ["strictCamelCase"],
        "selector": "classMethod"
      }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

I expect class members with private identifiers (those starting with #) to be considered private, so there should be no errors in the example above.

Actual Result

There are errors in line 3 and 4:
Class Property name 'privateField' must match one of the following formats: StrictPascalCase
Class Method name 'privateMethod' must match one of the following formats: StrictPascalCase

These errors are due to the rule ignoring the # sign and considering the fields as public because there are no typescript accessibility modifiers in front. Using "filter": { "regex": "^#", "match": false } to work around the issue also does not work because the # sign is ignored in the rule.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulegood first issueGood for newcomerspackage: 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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy