Skip to content

Commit 651ec91

Browse files
docs: remove /* eslint-env */ comments from rule examples (#18249)
* docs: remove `/* eslint-env */` comments from rule examples * also disallow empty eslint-env comments Co-authored-by: Francesco Trotta <[email protected]> * add test case --------- Co-authored-by: Francesco Trotta <[email protected]>
1 parent 950c4f1 commit 651ec91

File tree

76 files changed

+49
-405
lines changed

Some content is hidden

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

76 files changed

+49
-405
lines changed

docs/src/rules/array-bracket-spacing.md

-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ A number of style guides require or disallow spaces between array brackets and o
1313
applies to both array literals and destructuring assignments (ECMAScript 6).
1414

1515
```js
16-
/*eslint-env es6*/
17-
1816
var arr = [ 'foo', 'bar' ];
1917
var [ x, y ] = z;
2018

@@ -58,7 +56,6 @@ Examples of **incorrect** code for this rule with the default `"never"` option:
5856

5957
```js
6058
/*eslint array-bracket-spacing: ["error", "never"]*/
61-
/*eslint-env es6*/
6259

6360
var arr = [ 'foo', 'bar' ];
6461
var arr = ['foo', 'bar' ];
@@ -81,7 +78,6 @@ Examples of **correct** code for this rule with the default `"never"` option:
8178

8279
```js
8380
/*eslint array-bracket-spacing: ["error", "never"]*/
84-
/*eslint-env es6*/
8581

8682
var arr = [];
8783
var arr = ['foo', 'bar', 'baz'];
@@ -114,7 +110,6 @@ Examples of **incorrect** code for this rule with the `"always"` option:
114110

115111
```js
116112
/*eslint array-bracket-spacing: ["error", "always"]*/
117-
/*eslint-env es6*/
118113

119114
var arr = ['foo', 'bar'];
120115
var arr = ['foo', 'bar' ];
@@ -140,7 +135,6 @@ Examples of **correct** code for this rule with the `"always"` option:
140135

141136
```js
142137
/*eslint array-bracket-spacing: ["error", "always"]*/
143-
/*eslint-env es6*/
144138

145139
var arr = [];
146140
var arr = [ 'foo', 'bar', 'baz' ];

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Examples of **incorrect** code for this rule with the `"always"` option:
3131

3232
```js
3333
/*eslint arrow-body-style: ["error", "always"]*/
34-
/*eslint-env es6*/
3534

3635
let foo = () => 0;
3736
```
@@ -44,7 +43,6 @@ Examples of **correct** code for this rule with the `"always"` option:
4443

4544
```js
4645
/*eslint arrow-body-style: ["error", "always"]*/
47-
/*eslint-env es6*/
4846

4947
let foo = () => {
5048
return 0;
@@ -65,7 +63,6 @@ Examples of **incorrect** code for this rule with the default `"as-needed"` opti
6563

6664
```js
6765
/*eslint arrow-body-style: ["error", "as-needed"]*/
68-
/*eslint-env es6*/
6966

7067
let foo = () => {
7168
return 0;
@@ -88,7 +85,6 @@ Examples of **correct** code for this rule with the default `"as-needed"` option
8885

8986
```js
9087
/*eslint arrow-body-style: ["error", "as-needed"]*/
91-
/*eslint-env es6*/
9288

9389
let foo1 = () => 0;
9490
let foo2 = (retv, name) => {
@@ -122,7 +118,7 @@ Examples of **incorrect** code for this rule with the `{ "requireReturnForObject
122118

123119
```js
124120
/*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/
125-
/*eslint-env es6*/
121+
126122
let foo = () => ({});
127123
let bar = () => ({ bar: 0 });
128124
```
@@ -135,7 +131,6 @@ Examples of **correct** code for this rule with the `{ "requireReturnForObjectLi
135131

136132
```js
137133
/*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/
138-
/*eslint-env es6*/
139134

140135
let foo = () => {};
141136
let bar = () => { return { bar: 0 }; };
@@ -151,7 +146,6 @@ Examples of **incorrect** code for this rule with the `"never"` option:
151146

152147
```js
153148
/*eslint arrow-body-style: ["error", "never"]*/
154-
/*eslint-env es6*/
155149

156150
let foo = () => {
157151
return 0;
@@ -170,7 +164,6 @@ Examples of **correct** code for this rule with the `"never"` option:
170164

171165
```js
172166
/*eslint arrow-body-style: ["error", "never"]*/
173-
/*eslint-env es6*/
174167

175168
let foo = () => 0;
176169
let bar = () => ({ foo: 0 });

docs/src/rules/arrow-parens.md

-20
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ be wrapped in parentheses. This rule enforces the consistent use of parentheses
1515
This rule enforces parentheses around arrow function parameters regardless of arity. For example:
1616

1717
```js
18-
/*eslint-env es6*/
19-
2018
// Bad
2119
a => {}
2220

@@ -28,8 +26,6 @@ Following this style will help you find arrow functions (`=>`) which may be mist
2826
when a comparison such as `>=` was the intent.
2927

3028
```js
31-
/*eslint-env es6*/
32-
3329
// Bad
3430
if (a => 2) {
3531
}
@@ -42,8 +38,6 @@ if (a >= 2) {
4238
The rule can also be configured to discourage the use of parens when they are not required:
4339

4440
```js
45-
/*eslint-env es6*/
46-
4741
// Bad
4842
(a) => {}
4943

@@ -72,7 +66,6 @@ Examples of **incorrect** code for this rule with the default `"always"` option:
7266

7367
```js
7468
/*eslint arrow-parens: ["error", "always"]*/
75-
/*eslint-env es6*/
7669

7770
a => {};
7871
a => a;
@@ -90,7 +83,6 @@ Examples of **correct** code for this rule with the default `"always"` option:
9083

9184
```js
9285
/*eslint arrow-parens: ["error", "always"]*/
93-
/*eslint-env es6*/
9486

9587
() => {};
9688
(a) => {};
@@ -107,8 +99,6 @@ a.then((foo) => { if (true) {} });
10799
One of the benefits of this option is that it prevents the incorrect use of arrow functions in conditionals:
108100

109101
```js
110-
/*eslint-env es6*/
111-
112102
var a = 1;
113103
var b = 2;
114104
// ...
@@ -125,8 +115,6 @@ The contents of the `if` statement is an arrow function, not a comparison.
125115
If the arrow function is intentional, it should be wrapped in parens to remove ambiguity.
126116

127117
```js
128-
/*eslint-env es6*/
129-
130118
var a = 1;
131119
var b = 0;
132120
// ...
@@ -141,8 +129,6 @@ if ((a) => b) {
141129
The following is another example of this behavior:
142130

143131
```js
144-
/*eslint-env es6*/
145-
146132
var a = 1, b = 2, c = 3, d = 4;
147133
var f = a => b ? c: d;
148134
// f = ?
@@ -153,8 +139,6 @@ var f = a => b ? c: d;
153139
This should be rewritten like so:
154140

155141
```js
156-
/*eslint-env es6*/
157-
158142
var a = 1, b = 2, c = 3, d = 4;
159143
var f = (a) => b ? c: d;
160144
```
@@ -167,7 +151,6 @@ Examples of **incorrect** code for this rule with the `"as-needed"` option:
167151

168152
```js
169153
/*eslint arrow-parens: ["error", "as-needed"]*/
170-
/*eslint-env es6*/
171154

172155
(a) => {};
173156
(a) => a;
@@ -188,7 +171,6 @@ Examples of **correct** code for this rule with the `"as-needed"` option:
188171

189172
```js
190173
/*eslint arrow-parens: ["error", "as-needed"]*/
191-
/*eslint-env es6*/
192174

193175
() => {};
194176
a => {};
@@ -215,7 +197,6 @@ Examples of **incorrect** code for the `{ "requireForBlockBody": true }` option:
215197

216198
```js
217199
/*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/
218-
/*eslint-env es6*/
219200

220201
(a) => a;
221202
a => {};
@@ -235,7 +216,6 @@ Examples of **correct** code for the `{ "requireForBlockBody": true }` option:
235216

236217
```js
237218
/*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/
238-
/*eslint-env es6*/
239219

240220
(a) => {};
241221
(a) => {'\n'};

docs/src/rules/arrow-spacing.md

-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding ru
88
This rule normalize style of spacing before/after an arrow function's arrow(`=>`).
99

1010
```js
11-
/*eslint-env es6*/
12-
1311
// { "before": true, "after": true }
1412
(a) => {}
1513

@@ -31,7 +29,6 @@ Examples of **incorrect** code for this rule with the default `{ "before": true,
3129

3230
```js
3331
/*eslint arrow-spacing: "error"*/
34-
/*eslint-env es6*/
3532

3633
()=> {};
3734
() =>{};
@@ -51,7 +48,6 @@ Examples of **correct** code for this rule with the default `{ "before": true, "
5148

5249
```js
5350
/*eslint arrow-spacing: "error"*/
54-
/*eslint-env es6*/
5551

5652
() => {};
5753
(a) => {};
@@ -67,7 +63,6 @@ Examples of **incorrect** code for this rule with the `{ "before": false, "after
6763

6864
```js
6965
/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/
70-
/*eslint-env es6*/
7166

7267
() =>{};
7368
(a) => {};
@@ -82,7 +77,6 @@ Examples of **correct** code for this rule with the `{ "before": false, "after":
8277

8378
```js
8479
/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/
85-
/*eslint-env es6*/
8680

8781
()=>{};
8882
(a)=>{};
@@ -97,7 +91,6 @@ Examples of **incorrect** code for this rule with the `{ "before": false, "after
9791

9892
```js
9993
/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/
100-
/*eslint-env es6*/
10194

10295
() =>{};
10396
(a) => {};
@@ -112,7 +105,6 @@ Examples of **correct** code for this rule with the `{ "before": false, "after":
112105

113106
```js
114107
/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/
115-
/*eslint-env es6*/
116108

117109
()=> {};
118110
(a)=> {};

docs/src/rules/capitalized-comments.md

-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Examples of **correct** code for this rule:
4242
// 丈 Non-Latin character at beginning of comment
4343

4444
/* eslint semi:off */
45-
/* eslint-env node */
4645
/* eslint-disable */
4746
/* eslint-enable */
4847
/* istanbul ignore next */
@@ -118,7 +117,6 @@ Examples of **correct** code for this rule:
118117
// 丈 Non-Latin character at beginning of comment
119118

120119
/* eslint semi:off */
121-
/* eslint-env node */
122120
/* eslint-disable */
123121
/* eslint-enable */
124122
/* istanbul ignore next */

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ Examples of **incorrect** code for this rule:
6262

6363
```js
6464
/*eslint class-methods-use-this: "error"*/
65-
/*eslint-env es6*/
6665

6766
class A {
6867
foo() {
@@ -79,7 +78,7 @@ Examples of **correct** code for this rule:
7978

8079
```js
8180
/*eslint class-methods-use-this: "error"*/
82-
/*eslint-env es6*/
81+
8382
class A {
8483
foo() {
8584
this.bar = "Hello World"; // OK, this is used

docs/src/rules/computed-property-spacing.md

-9
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ While formatting preferences are very personal, a number of style guides require
1313
or disallow spaces between computed properties in the following situations:
1414

1515
```js
16-
/*eslint-env es6*/
17-
1816
var obj = { prop: "value" };
1917
var a = "prop";
2018
var x = obj[a]; // computed property in object member expression
@@ -57,7 +55,6 @@ Examples of **incorrect** code for this rule with the default `"never"` option:
5755

5856
```js
5957
/*eslint computed-property-spacing: ["error", "never"]*/
60-
/*eslint-env es6*/
6158

6259
obj[foo ]
6360
obj[ 'foo']
@@ -76,7 +73,6 @@ Examples of **correct** code for this rule with the default `"never"` option:
7673

7774
```js
7875
/*eslint computed-property-spacing: ["error", "never"]*/
79-
/*eslint-env es6*/
8076

8177
obj[foo]
8278
obj['foo']
@@ -97,7 +93,6 @@ Examples of **incorrect** code for this rule with the `"always"` option:
9793

9894
```js
9995
/*eslint computed-property-spacing: ["error", "always"]*/
100-
/*eslint-env es6*/
10196

10297
obj[foo]
10398
var x = {[b]: a}
@@ -117,7 +112,6 @@ Examples of **correct** code for this rule with the `"always"` option:
117112

118113
```js
119114
/*eslint computed-property-spacing: ["error", "always"]*/
120-
/*eslint-env es6*/
121115

122116
obj[ foo ]
123117
obj[ 'foo' ]
@@ -139,7 +133,6 @@ Examples of **incorrect** code for this rule with `"never"` and `{ "enforceForCl
139133

140134
```js
141135
/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/
142-
/*eslint-env es6*/
143136

144137
class Foo {
145138
[a ]() {}
@@ -163,7 +156,6 @@ Examples of **correct** code for this rule with `"never"` and `{ "enforceForClas
163156

164157
```js
165158
/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": true }]*/
166-
/*eslint-env es6*/
167159

168160
class Foo {
169161
[a]() {}
@@ -187,7 +179,6 @@ Examples of **correct** code for this rule with `"never"` and `{ "enforceForClas
187179

188180
```js
189181
/*eslint computed-property-spacing: ["error", "never", { "enforceForClassMembers": false }]*/
190-
/*eslint-env es6*/
191182

192183
class Foo {
193184
[a ]() {}

docs/src/rules/constructor-super.md

-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Examples of **incorrect** code for this rule:
3030

3131
```js
3232
/*eslint constructor-super: "error"*/
33-
/*eslint-env es6*/
3433

3534
class A extends B {
3635
constructor() { } // Would throw a ReferenceError.
@@ -56,7 +55,6 @@ Examples of **correct** code for this rule:
5655

5756
```js
5857
/*eslint constructor-super: "error"*/
59-
/*eslint-env es6*/
6058

6159
class A {
6260
constructor() { }

docs/src/rules/func-name-matching.md

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ module['exports'] = function foo(name) {};
100100

101101
```js
102102
/*eslint func-name-matching: ["error", "never"] */
103-
/*eslint-env es6*/
104103

105104
var foo = function bar() {};
106105
var foo = function() {};

0 commit comments

Comments
 (0)