-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b563057
commit a6c11eb
Showing
12 changed files
with
138 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Disallow non-null assertions after an optional chain expression | ||
|
||
`?.` optional chain expressions provide undefined if an object is `null` or | ||
`undefined`. Using a `!` non-null assertion to assert the result of an `?.` | ||
optional chain expression is non-nullable is likely wrong. | ||
|
||
### Invalid: | ||
|
||
```typescript | ||
foo?.bar!; | ||
foo?.bar()!; | ||
``` | ||
|
||
### Valid: | ||
|
||
```typescript | ||
foo?.bar; | ||
foo?.bar(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Disallow non-null assertions using the `!` postfix operator | ||
|
||
TypeScript's `!` non-null assertion operator asserts to the type system that an | ||
expression is non-nullable, as in not `null` or `undefined`. Using assertions to | ||
tell the type system new information is often a sign that code is not fully | ||
type-safe. It's generally better to structure program logic so that TypeScript | ||
understands when values may be nullable. | ||
|
||
### Invalid: | ||
|
||
```typescript | ||
interface Example { | ||
property?: string; | ||
} | ||
declare const example: Example; | ||
|
||
const includes = example.property!.includes("foo"); | ||
``` | ||
|
||
### Valid: | ||
|
||
```typescript | ||
interface Example { | ||
property?: string; | ||
} | ||
declare const example: Example; | ||
|
||
const includes = example.property?.includes("foo") ?? false; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Disallow throwing literals as exceptions | ||
|
||
It is considered good practice to only `throw` the `Error` object itself or an | ||
object using the `Error` object as base objects for user-defined exceptions. The | ||
fundamental benefit of `Error` objects is that they automatically keep track of | ||
where they were built and originated. | ||
|
||
### Invalid: | ||
|
||
```typescript | ||
throw "error"; | ||
throw 0; | ||
throw undefined; | ||
throw null; | ||
``` | ||
|
||
### Valid: | ||
|
||
```typescript | ||
throw new Error("error"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Disallow the use of undeclared variables | ||
|
||
### Invalid: | ||
|
||
```typescript | ||
const foo = someFunction(); | ||
const bar = a + 1; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Disallows multiple variable definitions in the same declaration statement | ||
|
||
### Invalid: | ||
|
||
```typescript | ||
const foo = 1, bar = "2"; | ||
``` | ||
|
||
### Valid: | ||
|
||
```typescript | ||
const foo = 1; | ||
const bar = "2"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Disallow certain triple slash directives in favor of ES6-style import | ||
declarations | ||
|
||
TypeScript's `///` triple-slash references are a way to indicate that types from | ||
another module are available in a file. Use of triple-slash reference type | ||
directives is generally discouraged in favor of ECMAScript Module imports. This | ||
rule reports on the use of `/// <reference path="..." />`, | ||
`/// <reference types="..." />`, or `/// <reference lib="..." />` directives. | ||
|
||
### Invalid: | ||
|
||
```typescript | ||
/// <reference types="foo" /> | ||
import * as foo from "foo"; | ||
``` | ||
|
||
### Valid: | ||
|
||
```typescript | ||
import * as foo from "foo"; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters