-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
a15d4a1
commit e0ced82
Showing
164 changed files
with
1,630 additions
and
497 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,46 @@ | ||
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. --> | ||
|
||
# eslint/no-alert <Badge type="info" text="Restriction" /> | ||
|
||
<div class="rule-meta"> | ||
</div> | ||
|
||
### What it does | ||
|
||
Disallow the use of alert, confirm, and prompt | ||
|
||
### Why is this bad? | ||
|
||
JavaScript’s alert, confirm, and prompt functions are widely considered to be obtrusive as UI elements and should be replaced by a more appropriate custom UI implementation. | ||
Furthermore, alert is often used while debugging code, which should be removed before deployment to production. | ||
|
||
### Examples | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
alert("here!"); | ||
|
||
confirm("Are you sure?"); | ||
|
||
prompt("What's your name?", "John Doe"); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
customAlert("Something happened!"); | ||
|
||
customConfirm("Are you sure?"); | ||
|
||
customPrompt("Who are you?"); | ||
|
||
function foo() { | ||
var alert = myCustomLib.customAlert; | ||
alert(); | ||
} | ||
``` | ||
|
||
## References | ||
|
||
- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_alert.rs) |
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
40 changes: 40 additions & 0 deletions
40
src/docs/guide/usage/linter/rules/eslint/no-invalid-regexp.md
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,40 @@ | ||
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. --> | ||
|
||
# eslint/no-invalid-regexp <Badge type="info" text="Correctness" /> | ||
|
||
<div class="rule-meta"> | ||
<Alert class="default-on" type="success"> | ||
<span class="emoji">✅</span> This rule is turned on by default. | ||
</Alert> | ||
</div> | ||
|
||
### What it does | ||
|
||
Disallow invalid regular expression strings in RegExp constructors. | ||
|
||
### Why is this bad? | ||
|
||
An invalid pattern in a regular expression literal is a SyntaxError when the code is parsed, | ||
but an invalid string in RegExp constructors throws a SyntaxError only when the code is executed. | ||
|
||
### Examples | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
RegExp("["); | ||
RegExp(".", "z"); | ||
new RegExp("\\"); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
RegExp("."); | ||
new RegExp(); | ||
this.RegExp("["); | ||
``` | ||
|
||
## References | ||
|
||
- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_invalid_regexp.rs) |
137 changes: 137 additions & 0 deletions
137
src/docs/guide/usage/linter/rules/eslint/no-magic-numbers.md
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,137 @@ | ||
<!-- This file is auto-generated by tasks/website/src/linter/rules/doc_page.rs. Do not edit it manually. --> | ||
|
||
# eslint/no-magic-numbers <Badge type="info" text="Style" /> | ||
|
||
<div class="rule-meta"> | ||
<Alert class="fix" type="info"> | ||
<span class="emoji">🚧</span> An auto-fix is still under development. | ||
</Alert> | ||
</div> | ||
|
||
### What it does | ||
|
||
The no-magic-numbers rule aims to make code more readable and refactoring easier by ensuring that special numbers are declared as constants to make their meaning explicit. | ||
The current implementation does not support BigInt numbers inside array indexes. | ||
|
||
### Why is this bad? | ||
|
||
‘Magic numbers’ are numbers that occur multiple times in code without an explicit meaning. They should preferably be replaced by named constants. | ||
|
||
### Examples | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```javascript | ||
var dutyFreePrice = 100; | ||
var finalPrice = dutyFreePrice + dutyFreePrice * 0.25; | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignore": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "ignore": [1] }]*/ | ||
var data = ["foo", "bar", "baz"]; | ||
var dataLast = data.length && data[data.length - 1]; | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreArrayIndexes": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "ignoreArrayIndexes": true }]*/ | ||
var item = data[2]; | ||
data[100] = a; | ||
f(data[0]); | ||
a = data[-0]; // same as data[0], -0 will be coerced to "0" | ||
a = data[0xab]; | ||
a = data[5.6e1]; | ||
a = data[4294967294]; // max array index | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreDefaultValues": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "ignoreDefaultValues": true }]*/ | ||
const { tax = 0.25 } = accountancy; | ||
function mapParallel(concurrency = 3) { | ||
/***/ | ||
} | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreClassFieldInitialValues": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "ignoreClassFieldInitialValues": true }]*/ | ||
class C { | ||
foo = 2; | ||
bar = -3; | ||
#baz = 4; | ||
static qux = 5; | ||
} | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with option "enforceConst": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "enforceConst": true }]*/ | ||
var TAX = 0.25; | ||
``` | ||
|
||
Examples of **incorrect** code for this rule with option "detectObjects": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "detectObjects": true }]*/ | ||
var magic = { | ||
tax: 0.25, | ||
}; | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "detectObjects": | ||
|
||
```javascript | ||
/*typescript no-magic-numbers: ["error", { "detectObjects": true }]*/ | ||
var TAX = 0.25; | ||
|
||
var magic = { | ||
tax: TAX, | ||
}; | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreEnums": | ||
|
||
```typescript | ||
/*typescript no-magic-numbers: ["error", { "ignoreEnums": true }]*/ | ||
enum foo { | ||
SECOND = 1000, | ||
} | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreNumericLiteralTypes": | ||
|
||
```typescript | ||
/*typescript no-magic-numbers: ["error", { "ignoreNumericLiteralTypes": true }]*/ | ||
type SmallPrimes = 2 | 3 | 5 | 7 | 11; | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreReadonlyClassProperties": | ||
|
||
```typescript | ||
/*typescript no-magic-numbers: ["error", { "ignoreReadonlyClassProperties": true }]*/ | ||
class Foo { | ||
readonly A = 1; | ||
readonly B = 2; | ||
public static readonly C = 1; | ||
static readonly D = 1; | ||
} | ||
``` | ||
|
||
Examples of **correct** code for this rule with option "ignoreTypeIndexes": | ||
|
||
```typescript | ||
/*typescript no-magic-numbers: ["error", { "ignoreTypeIndexes": true }]*/ | ||
type Foo = Bar[0]; | ||
type Baz = Parameters<Foo>[2]; | ||
``` | ||
|
||
## References | ||
|
||
- [Rule Source](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs) |
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
Oops, something went wrong.