Skip to content

[naming-convention] Allow underscore prefix for backing fields #816

@glen-84

Description

@glen-84

Edit: The description below referred to the member-naming rule, which has since been replaced by the new naming-convention rule. This issue is still relevant.


Repro

{
  "rules": {
    "@typescript-eslint/member-naming": ["error", { "private": "^(?!_)" }]
  }
}
class Example {
    private _var1; // Not a backing field, shouldn't start with an underscore.
    private _var2; // Allowed, as it's a backing field for the `var2` property.

    public get var2() {
        return this._var2;
    }
}

Expected Result

Error for _var1, but not for _var2 (because it's a backing field).

Actual Result

Error for both fields.

Additional Info

Similar TSLint issue with 33 👍.

Since this rule is different to the one in TSLint, the implementation would be different. Maybe an ignoreBackingFields: boolean option, or a way to set the naming for backing fields separately.

Versions

package version
@typescript-eslint/eslint-plugin 1.13.0
@typescript-eslint/parser 1.13.0
TypeScript 3.4.5
ESLint 6.1.0
node 10.16.0
npm 6.9.0

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 rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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