Skip to content

Commit 0bcb9a8

Browse files
fasttimenzakasmdjermanovic
authored
docs: Fix syntax errors in rule examples (#17633)
* Fix code examples in rule docs * Update `id-length` * Restore example in `id-match` under option `properties` * Update docs/src/rules/constructor-super.md Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> * Update docs/src/rules/no-useless-rename.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Nicholas C. Zakas <nicholas@humanwhocodes.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 61b9083 commit 0bcb9a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+580
-465
lines changed

docs/src/rules/arrow-body-style.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Examples of **correct** code for this rule with the `"always"` option:
4545
let foo = () => {
4646
return 0;
4747
};
48-
let foo = (retv, name) => {
48+
let bar = (retv, name) => {
4949
retv[name] = true;
5050
return retv;
5151
};
@@ -66,7 +66,7 @@ Examples of **incorrect** code for this rule with the default `"as-needed"` opti
6666
let foo = () => {
6767
return 0;
6868
};
69-
let foo = () => {
69+
let bar = () => {
7070
return {
7171
bar: {
7272
foo: 1,
@@ -86,24 +86,24 @@ Examples of **correct** code for this rule with the default `"as-needed"` option
8686
/*eslint arrow-body-style: ["error", "as-needed"]*/
8787
/*eslint-env es6*/
8888

89-
let foo = () => 0;
90-
let foo = (retv, name) => {
89+
let foo1 = () => 0;
90+
let foo2 = (retv, name) => {
9191
retv[name] = true;
9292
return retv;
9393
};
94-
let foo = () => ({
94+
let foo3 = () => ({
9595
bar: {
9696
foo: 1,
9797
bar: 2,
9898
}
9999
});
100-
let foo = () => { bar(); };
101-
let foo = () => {};
102-
let foo = () => { /* do nothing */ };
103-
let foo = () => {
100+
let foo4 = () => { bar(); };
101+
let foo5 = () => {};
102+
let foo6 = () => { /* do nothing */ };
103+
let foo7 = () => {
104104
// do nothing.
105105
};
106-
let foo = () => ({ bar: 0 });
106+
let foo8 = () => ({ bar: 0 });
107107
```
108108

109109
:::
@@ -120,7 +120,7 @@ Examples of **incorrect** code for this rule with the `{ "requireReturnForObject
120120
/*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/
121121
/*eslint-env es6*/
122122
let foo = () => ({});
123-
let foo = () => ({ bar: 0 });
123+
let bar = () => ({ bar: 0 });
124124
```
125125

126126
:::
@@ -134,7 +134,7 @@ Examples of **correct** code for this rule with the `{ "requireReturnForObjectLi
134134
/*eslint-env es6*/
135135

136136
let foo = () => {};
137-
let foo = () => { return { bar: 0 }; };
137+
let bar = () => { return { bar: 0 }; };
138138
```
139139

140140
:::
@@ -152,7 +152,7 @@ Examples of **incorrect** code for this rule with the `"never"` option:
152152
let foo = () => {
153153
return 0;
154154
};
155-
let foo = (retv, name) => {
155+
let bar = (retv, name) => {
156156
retv[name] = true;
157157
return retv;
158158
};
@@ -169,7 +169,7 @@ Examples of **correct** code for this rule with the `"never"` option:
169169
/*eslint-env es6*/
170170

171171
let foo = () => 0;
172-
let foo = () => ({ foo: 0 });
172+
let bar = () => ({ foo: 0 });
173173
```
174174

175175
:::

docs/src/rules/camelcase.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ function foo({ no_camelcased }) {
4949
// ...
5050
};
5151

52-
function foo({ isCamelcased: no_camelcased }) {
52+
function bar({ isCamelcased: no_camelcased }) {
5353
// ...
5454
}
5555

56-
function foo({ no_camelcased = 'default value' }) {
56+
function baz({ no_camelcased = 'default value' }) {
5757
// ...
5858
};
5959

@@ -63,7 +63,7 @@ var obj = {
6363

6464
var { category_id = 1 } = query;
6565

66-
var { foo: no_camelcased } = bar;
66+
var { foo: snake_cased } = bar;
6767

6868
var { foo: bar_baz = 1 } = quz;
6969
```
@@ -83,8 +83,8 @@ var myFavoriteColor = "#112C85";
8383
var _myFavoriteColor = "#112C85";
8484
var myFavoriteColor_ = "#112C85";
8585
var MY_FAVORITE_COLOR = "#112C85";
86-
var foo = bar.baz_boom;
87-
var foo = { qux: bar.baz_boom };
86+
var foo1 = bar.baz_boom;
87+
var foo2 = { qux: bar.baz_boom };
8888

8989
obj.do_something();
9090
do_something();
@@ -96,11 +96,11 @@ function foo({ isCamelCased }) {
9696
// ...
9797
};
9898

99-
function foo({ isCamelCased: isAlsoCamelCased }) {
99+
function bar({ isCamelCased: isAlsoCamelCased }) {
100100
// ...
101101
}
102102

103-
function foo({ isCamelCased = 'default value' }) {
103+
function baz({ isCamelCased = 'default value' }) {
104104
// ...
105105
};
106106

@@ -143,9 +143,9 @@ Examples of **incorrect** code for this rule with the default `{ "ignoreDestruct
143143

144144
var { category_id } = query;
145145

146-
var { category_id = 1 } = query;
146+
var { category_name = 1 } = query;
147147

148-
var { category_id: category_id } = query;
148+
var { category_id: category_title } = query;
149149

150150
var { category_id: category_alias } = query;
151151

docs/src/rules/class-methods-use-this.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ class A {
8686
}
8787
}
8888

89-
class A {
89+
class B {
9090
constructor() {
9191
// OK. constructor is exempt
9292
}
9393
}
9494

95-
class A {
95+
class C {
9696
static foo() {
9797
// OK. static methods aren't expected to use this.
9898
}

docs/src/rules/constructor-super.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ This rule checks whether or not there is a valid `super()` call.
1414

1515
This rule is aimed to flag invalid/missing `super()` calls.
1616

17+
This is a syntax error because there is no `extends` clause in the class:
18+
19+
```js
20+
class A {
21+
constructor() {
22+
super();
23+
}
24+
}
25+
```
26+
1727
Examples of **incorrect** code for this rule:
1828

1929
:::incorrect
@@ -22,24 +32,18 @@ Examples of **incorrect** code for this rule:
2232
/*eslint constructor-super: "error"*/
2333
/*eslint-env es6*/
2434

25-
class A {
26-
constructor() {
27-
super(); // This is a SyntaxError.
28-
}
29-
}
30-
3135
class A extends B {
3236
constructor() { } // Would throw a ReferenceError.
3337
}
3438

3539
// Classes which inherits from a non constructor are always problems.
36-
class A extends null {
40+
class C extends null {
3741
constructor() {
3842
super(); // Would throw a TypeError.
3943
}
4044
}
4145

42-
class A extends null {
46+
class D extends null {
4347
constructor() { } // Would throw a ReferenceError.
4448
}
4549
```
@@ -58,7 +62,7 @@ class A {
5862
constructor() { }
5963
}
6064

61-
class A extends B {
65+
class B extends C {
6266
constructor() {
6367
super();
6468
}

docs/src/rules/id-denylist.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Examples of **incorrect** code for this rule with sample `"data", "callback"` re
4646
```js
4747
/*eslint id-denylist: ["error", "data", "callback"] */
4848

49-
var data = {...};
49+
var data = { ...values };
5050

5151
function callback() {
5252
// ...
@@ -57,23 +57,23 @@ element.callback = function() {
5757
};
5858

5959
var itemSet = {
60-
data: [...]
60+
data: [...values]
6161
};
6262

6363
class Foo {
6464
data = [];
6565
}
6666

67-
class Foo {
67+
class Bar {
6868
#data = [];
6969
}
7070

71-
class Foo {
72-
callback( {);
71+
class Baz {
72+
callback() {}
7373
}
7474

75-
class Foo {
76-
#callback( {);
75+
class Qux {
76+
#callback() {}
7777
}
7878
```
7979

@@ -86,7 +86,7 @@ Examples of **correct** code for this rule with sample `"data", "callback"` rest
8686
```js
8787
/*eslint id-denylist: ["error", "data", "callback"] */
8888

89-
var encodingOptions = {...};
89+
var encodingOptions = {...values};
9090

9191
function processFileResult() {
9292
// ...
@@ -97,7 +97,7 @@ element.successHandler = function() {
9797
};
9898

9999
var itemSet = {
100-
entities: [...]
100+
entities: [...values]
101101
};
102102

103103
callback(); // all function calls are ignored
@@ -110,16 +110,16 @@ class Foo {
110110
items = [];
111111
}
112112

113-
class Foo {
113+
class Bar {
114114
#items = [];
115115
}
116116

117-
class Foo {
118-
method( {);
117+
class Baz {
118+
method() {}
119119
}
120120

121-
class Foo {
122-
#method( {);
121+
class Qux {
122+
#method() {}
123123
}
124124
```
125125

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy