@@ -5,11 +5,11 @@ which provides a TypeScript ESLint ruleset tailored for large teams and projects
55Please see [ that project's documentation] ( https://www.npmjs.com/package/@rushstack/eslint-config )
66for details. To learn about Rush Stack, please visit: [ https://rushstack.io/ ] ( https://rushstack.io/ )
77
8- ## ` @rushstack/no-null `
8+ ### ` @rushstack/no-null `
99
10- Prevents usage of JavaScript's ` null ` keyword.
10+ Prevent usage of JavaScript's ` null ` keyword.
1111
12- ### Rule Details
12+ #### Rule Details
1313
1414Most programming languages have a "null" or "nil" value that serves several purposes:
1515
@@ -25,7 +25,7 @@ lint suppressions when interacting with these legacy APIs, this rule prohibits `
2525in type annotations. Comparisons with ` null ` are also allowed. In other words, this rule aims to tolerate
2626preexisting null values but prevents new ones from being introduced.
2727
28- ### Examples
28+ #### Examples
2929
3030The following patterns are considered problems when ` @rushstack/no-null ` is enabled:
3131
@@ -48,3 +48,45 @@ if (x === null) { // comparisons are okay
4848 x = 0 ;
4949}
5050```
51+
52+ ### ` @rushstack/no-untyped-underscore `
53+
54+ (Optional) Prevent TypeScript code from accessing legacy JavaScript members whose name has an underscore prefix.
55+
56+ #### Rule Details
57+
58+ JavaScript does not provide a straightforward way to restrict access to object members, so API names commonly
59+ use an underscore prefix to indicate a private member (e.g. ` exampleObject._privateMember ` ). However, inexperienced
60+ developers may not be aware of this convention. In TypeScript we can generally solve this problem by marking the types
61+ as ` private ` or omitting them from the typings. However, when migrating a large legacy code base to TypeScript,
62+ it may be difficult to author typings for every legacy API. For this case, you can enable the
63+ ` @rushstack/no-untyped-underscore ` rule.
64+
65+ This rule reports access to members whose name has an underscore prefix, EXCEPT in cases where:
66+
67+ - The containing object has a type which declares the member; OR
68+ - The untyped expression uses privileged names like ` this._example ` or ` that._example ` or ` super._example ` ; OR
69+
70+ #### Examples
71+
72+ The following patterns are considered problems when ` @rushstack/no-untyped-underscore ` is enabled:
73+
74+ ``` ts
75+ let x: any ;
76+ x ._privateMember = 123 ; // error
77+
78+ let x: { [key : string ]: number };
79+ x ._privateMember = 123 ; // error
80+ ```
81+
82+ The following patterns are NOT considered problems:
83+
84+ ``` ts
85+ let x: { _privateMember: any };
86+ x ._privateMember = 123 ; // okay because _privateMember is declared by x's type
87+
88+ enum E {
89+ _PrivateMember
90+ }
91+ let e: E ._PrivateMember = E ._PrivateMember ; // okay because _PrivateMember is declared by E
92+ ```
0 commit comments