Skip to content

Rule proposal: prefer hash names for private members #1391

Closed
@kimamula

Description

@kimamula

TypeScript 3.8 will add support for private named instance fields. What about creating a rule for disallowing the use of the private accessibility modifier in favor of the standard hash names for private members?

Examples of incorrect code for this rule:

class MyClass {
  private foo = 1;
  constructor(private bar: string) {}
}

Examples of correct code for this rule:

class MyClass {
  #foo = 1;
  #bar: string;
  constructor(bar: string) {
    this.#bar = bar;
  }
}

Options

// Any target whose hash names are supported
// by the TypeScript version in use can be specified
type Target =
//  | 'accessors'
//  | 'constructors'
//  | 'staticMethods'
//  | 'instanceMethods'
//  | 'staticFields'
  | 'instanceFields';

type Options = Target[];

// Defaults to all the targets
const defaultOptions: Options = ['instanceFields']; // for TypeScript 3.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions