Skip to content

Commit 43597cc

Browse files
committed
Update docs
1 parent b179b8b commit 43597cc

3 files changed

Lines changed: 52 additions & 9 deletions

File tree

stack/eslint-plugin/README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ which provides a TypeScript ESLint ruleset tailored for large teams and projects
55
Please see [that project's documentation](https://www.npmjs.com/package/@rushstack/eslint-config)
66
for 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

1414
Most 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 `
2525
in type annotations. Comparisons with `null` are also allowed. In other words, this rule aims to tolerate
2626
preexisting null values but prevents new ones from being introduced.
2727

28-
### Examples
28+
#### Examples
2929

3030
The 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+
```

stack/eslint-plugin/src/no-null.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const noNullRule: TSESLint.RuleModule<MessageIds,Options> = {
1818
},
1919
schema: [ ],
2020
docs: {
21-
description: 'Prevents usage of JavaScript\'s "null" keyword.',
21+
description: 'Prevent usage of JavaScript\'s "null" keyword',
2222
category: 'Stylistic Issues',
2323
recommended: "error",
24-
url: 'https://www.npmjs.com/package/@rushstack/eslint-config'
24+
url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin'
2525
}
2626
},
2727
create: (context: TSESLint.RuleContext<MessageIds, Options>) => {

stack/eslint-plugin/src/no-untyped-underscore.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ const noUntypedUnderscoreRule: TSESLint.RuleModule<MessageIds,Options> = {
2121
},
2222
schema: [ ],
2323
docs: {
24-
description: 'Prevents usage of JavaScript\'s "null" keyword.',
24+
description: 'Prevent TypeScript code from accessing legacy JavaScript members'
25+
+ ' whose name has an underscore prefix',
2526
category: 'Stylistic Issues',
26-
recommended: "error",
27-
url: 'https://www.npmjs.com/package/@rushstack/eslint-config'
27+
recommended: false,
28+
url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin'
2829
}
2930
},
3031
create: (context: TSESLint.RuleContext<MessageIds, Options>) => {

0 commit comments

Comments
 (0)