Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into prefer-regexp-exec
- Loading branch information
Showing
42 changed files
with
14,672 additions
and
448 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
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,44 @@ | ||
# Disallow Magic Numbers (@typescript-eslint/no-magic-numbers) | ||
|
||
'Magic numbers' are numbers that occur multiple times in code without an explicit meaning. | ||
They should preferably be replaced by named constants. | ||
|
||
## Rule Details | ||
|
||
The `@typescript-eslint/no-magic-numbers` rule extends the `no-magic-numbers` rule from ESLint core, and adds support for handling Typescript specific code that would otherwise trigger the rule. | ||
|
||
See the [ESLint documentation](https://eslint.org/docs/rules/no-magic-numbers) for more details on the `no-magic-numbers` rule. | ||
|
||
## Rule Changes | ||
|
||
```cjson | ||
{ | ||
// note you must disable the base rule as it can report incorrect errors | ||
"no-magic-numbers": "off", | ||
"@typescript-eslint/no-magic-numbers": ["error", { "ignoreNumericLiteralTypes": true }] | ||
} | ||
``` | ||
|
||
In addition to the options supported by the `no-magic-numbers` rule in ESLint core, the rule adds the following options: | ||
|
||
### ignoreNumericLiteralTypes | ||
|
||
A boolean to specify if numbers used in Typescript numeric literal types are considered okay. `false` by default. | ||
|
||
Examples of **incorrect** code for the `{ "ignoreNumericLiteralTypes": false }` option: | ||
|
||
```ts | ||
/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreNumericLiteralTypes": false }]*/ | ||
|
||
type SmallPrimes = 2 | 3 | 5 | 7 | 11; | ||
``` | ||
|
||
Examples of **correct** code for the `{ "ignoreNumericLiteralTypes": true }` option: | ||
|
||
```ts | ||
/*eslint @typescript-eslint/no-magic-numbers: ["error", { "ignoreNumericLiteralTypes": true }]*/ | ||
|
||
type SmallPrimes = 2 | 3 | 5 | 7 | 11; | ||
``` | ||
|
||
<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-magic-numbers.md)</sup> |
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
Oops, something went wrong.