UNPKG

1.2 kBMarkdownView Raw
1# Enforces naming conventions for class members by visibility. (member-naming)
2
3It can be helpful to enforce naming conventions for `private` (and sometimes `protected`) members of an object. For example, prefixing private properties with a `_` allows them to be easily discerned when being inspected by tools that do not have knowledge of TypeScript (such as most debuggers).
4
5## Rule Details
6
7This rule allows you to enforce conventions for class property names by their visibility. By default, it enforces nothing.
8
9## Options
10
11You can specify a regular expression to test the names of properties for each visibility level: `public`, `protected`, `private`.
12
13Examples of **correct** code with `{ "private": "^_" }` specified:
14
15```ts
16class HappyClass {
17 private _foo: string;
18 private _bar = 123;
19 private _fizz() {}
20}
21```
22
23Examples of **incorrect** code with `{ "private": "^_" }` specified:
24
25```ts
26class SadClass {
27 private foo: string;
28 private bar = 123;
29 private fizz() {}
30}
31```
32
33## When Not To Use It
34
35If you do not want to enforce per-visibility naming rules for member properties.
36
37## Further Reading
38
39* ESLint's [`camelcase` rule](https://eslint.org/docs/rules/camelcase)