10000 docs: fix correct/incorrect examples of rules (#17789) · eslint/eslint@a6d9442 · GitHub
[go: up one dir, main page]

Skip to content

Commit a6d9442

Browse files
docs: fix correct/incorrect examples of rules (#17789)
* docs: fix correct/incorrect examples of rules * docs: fix previous commit errors * docs: update previous code
1 parent 383e999 commit a6d9442

16 files changed

+67
-33
lines changed

docs/src/rules/capitalized-comments.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,12 @@ Examples of **correct** code with `ignoreConsecutiveComments` set to `true`:
216216
```js
217217
/* eslint capitalized-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */
218218

219+
foo();
219220
// This comment is valid since it has the correct capitalization.
220221
// this comment is ignored since it follows another comment,
221222
// and this one as well because it follows yet another comment.
222223

224+
bar();
223225
/* Here is a block comment which has the correct capitalization, */
224226
/* but this one is ignored due to being consecutive; */
225227
/*
@@ -236,6 +238,7 @@ Examples of **incorrect** code with `ignoreConsecutiveComments` set to `true`:
236238
```js
237239
/* eslint capitalized-comments: ["error", "always", { "ignoreConsecutiveComments": true }] */
238240

241+
foo();
239242
// this comment is invalid, but only on this line.
240243
// this comment does NOT get reported, since it is a consecutive comment.
241244
```

docs/src/rules/dot-notation.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,27 @@ class C {
8484

8585
For example, when preparing data to be sent to an external API, it is often required to use property names that include underscores. If the `camelcase` rule is in effect, these [snake case](https://en.wikipedia.org/wiki/Snake_case) properties would not be allowed. By providing an `allowPattern` to the `dot-notation` rule, these snake case properties can be accessed with bracket notation.
8686

87-
Examples of **correct** code for the sample `{ "allowPattern": "^[a-z]+(_[a-z]+)+$" }` option:
87+
Examples of **incorrect** code for the sample `{ "allowPattern": "^[a-z]+(_[a-z]+)+$" }` (pattern to find snake case named properties) option:
8888

89-
:::correct
89+
:::incorrect
9090

9191
```js
92-
/*eslint camelcase: "error"*/
9392
/*eslint dot-notation: ["error", { "allowPattern": "^[a-z]+(_[a-z]+)+$" }]*/
9493

95-
var data = {};
96-
data.foo_bar = 42;
97-
9894
var data = {};
9995
data["fooBar"] = 42;
96+
```
97+
98+
:::
99+
Examples of **correct** code for the sample `{ "allowPattern": "^[a-z]+(_[a-z]+)+$" }` (pattern to find snake case named properties) option:
100+
101+
:::correct
102+
103+
```js
104+
/*eslint dot-notation: ["error", { "allowPattern": "^[a-z]+(_[a-z]+)+$" }]*/
100105

101106
var data = {};
102-
data["foo_bar"] = 42; // no warning
107+
data["foo_bar"] = 42;
103108
```
104109

105110
:::

docs/src/rules/max-lines-per-function.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ is equivalent to
7272

7373
### code
7474

75-
Examples of **incorrect** code for this rule with a max value of `2`:
75+
Examples of **incorrect** code for this rule with a particular max value:
7676

7777
::: incorrect
7878

@@ -88,7 +88,7 @@ function foo() {
8888
::: incorrect
8989

9090
```js
91-
/*eslint max-lines-per-function: ["error", 2]*/
91+
/*eslint max-lines-per-function: ["error", 3]*/
9292
function foo() {
9393
// a comment
9494
var x = 0;
@@ -100,7 +100,7 @@ function foo() {
100100
::: incorrect
101101

102102
```js
103-
/*eslint max-lines-per-function: ["error", 2]*/
103+
/*eslint max-lines-per-function: ["error", 4]*/
104104
function foo() {
105105
// a comment followed by a blank line
106106

@@ -110,7 +110,7 @@ function foo() {
110110

111111
:::
112112

113-
Examples of **correct** code for this rule with a max value of `3`:
113+
Examples of **correct** code for this rule with a particular max value:
114114

115115
::: correct
116116

@@ -126,7 +126,7 @@ function foo() {
126126
::: correct
127127

128128
```js
129-
/*eslint max-lines-per-function: ["error", 3]*/
129+
/*eslint max-lines-per-function: ["error", 4]*/
130130
function foo() {
131131
// a comment
132132
var x = 0;
@@ -138,7 +138,7 @@ function foo() {
138138
::: correct
139139

140140
```js
141-
/*eslint max-lines-per-function: ["error", 3]*/
141+
/*eslint max-lines-per-function: ["error", 5]*/
142142
function foo() {
143143
// a comment followed by a blank line
144144

docs/src/rules/no-async-promise-executor.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Examples of **incorrect** code for this rule:
3333
::: incorrect
3434

3535
```js
36+
/*eslint no-async-promise-executor: "error"*/
37+
3638
const foo = new Promise(async (resolve, reject) => {
3739
readFile('foo.txt', function(err, result) {
3840
if (err) {
@@ -55,6 +57,8 @@ Examples of **correct** code for this rule:
5557
::: correct
5658

5759
```js
60+
/*eslint no-async-promise-executor: "error"*/
61+
5862
const foo = new Promise((resolve, reject) => {
5963
readFile('foo.txt', function(err, result) {
6064
if (err) {

docs/src/rules/no-else-return.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This rule has an object option:
2828
* `allowElseIf: true` (default) allows `else if` blocks after a return
2929
* `allowElseIf: false` disallows `else if` blocks after a return
3030

31-
### `allowElseIf: true`
31+
### allowElseIf: true
3232

3333
Examples of **incorrect** code for this rule:
3434

@@ -137,7 +137,7 @@ function foo4() {
137137

138138
:::
139139

140-
### `allowElseIf: false`
140+
### allowElseIf: false
141141

142142
Examples of **incorrect** code for this rule:
143143

docs/src/rules/no-eval.md

Lines changed: 7 additions & 5 deletions
< 65CE tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class A {
104104

105105
## Options
106106

107+
### allowIndirect
108+
107109
This rule has an option to allow indirect calls to `eval`.
108110
Indirect calls to `eval` are less dangerous than direct calls to `eval` because they cannot dynamically change the scope. Because of this, they also will not negatively impact performance to the degree of direct `eval`.
109111

@@ -118,7 +120,7 @@ Example of **incorrect** code for this rule with the `{"allowIndirect": true}` o
118120
::: incorrect
119121

120122
```js
121-
/*eslint no-eval: "error"*/
123+
/*eslint no-eval: ["error", {"allowIndirect": true} ]*/
122124

123125
var obj = { x: "foo" },
124126
key = "x",
@@ -129,10 +131,10 @@ var obj = { x: "foo" },
129131

130132
Examples of **correct** code for this rule with the `{"allowIndirect": true}` option:
131133

132-
::: correct
134+
::: correct { "sourceType": "script" }
133135

134136
```js
135-
/*eslint no-eval: "error"*/
137+
/*eslint no-eval: ["error", {"allowIndirect": true} ]*/
136138

137139
(0, eval)("var a = 0");
138140

@@ -147,7 +149,7 @@ this.eval("var a = 0");
147149
::: correct
148150

149151
```js
150-
/*eslint no-eval: "error"*/
152+
/*eslint no-eval: ["error", {"allowIndirect": true} ]*/
151153
/*eslint-env browser*/
152154

153155
window.eval("var a = 0");
@@ -158,7 +160,7 @@ window.eval("var a = 0");
158160
::: correct
159161

160162
```js
161-
/*eslint no-eval: "error"*/
163+
/*eslint no-eval: ["error", {"allowIndirect": true} ]*/
162164
/*eslint-env node*/
163165

164166
global.eval("var a = 0");

docs/src/rules/no-implicit-globals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ window.bar = function() {};
7979

8080
Examples of **correct** code for this rule with `"parserOptions": { "sourceType": "module" }` in the ESLint configuration:
8181

82-
::: correct { "sourceType": "script" }
82+
::: correct { "sourceType": "module" }
8383

8484
```js
8585
/*eslint no-implicit-globals: "error"*/

docs/src/rules/no-implied-eval.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Examples of **incorrect** code for this rule:
3535

3636
```js
3737
/*eslint no-implied-eval: "error"*/
38+
/*eslint-env browser*/
3839

3940
setTimeout("alert('Hi!');", 100);
4041

docs/src/rules/no-loop-func.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,21 @@ for (var i=10; i; i--) {
4848
(function() { return i; })();
4949
}
5050

51-
while(i) {
51+
var i = 0;
52+
while(i < 5) {
5253
var a = function() { return i; };
5354
a();
55+
56+
i++;
5457
}
5558

59+
var i = 0;
5660
do {
5761
function a() { return i; };
5862
a();
59-
} while (i);
63+
64+
i++
65+
} while (i < 5);
6066

6167
let foo = 0;
6268
for (let i = 0; i < 10; ++i) {

docs/src/rules/no-redeclare.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The `"builtinGlobals"` option will check for redeclaration of built-in globals i
7777

7878
Examples of **incorrect** code for the `{ "builtinGlobals": true }` option:
7979

80-
::: incorrect
80+
::: incorrect { "sourceType": "script" }
8181

8282
```js
8383
/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
@@ -89,7 +89,7 @@ var Object = 0;
8989

9090
Examples of **incorrect** code for the `{ "builtinGlobals": true }` option and the `browser` environment:
9191

92-
::: incorrect
92+
::: incorrect { "sourceType": "script" }
9393

9494
```js
9595
/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/

0 commit comments

Comments
 (0)
0