Skip to content

Commit

Permalink
docs: remove /* eslint-env */ comments from rule examples (#18249)
Browse files Browse the repository at this point in the history
* docs: remove `/* eslint-env */` comments from rule examples

* also disallow empty eslint-env comments

Co-authored-by: Francesco Trotta <github@fasttime.org>

* add test case

---------

Co-authored-by: Francesco Trotta <github@fasttime.org>
  • Loading branch information
mdjermanovic and fasttime committed Apr 2, 2024
1 parent 950c4f1 commit 651ec91
Show file tree
Hide file tree
Showing 76 changed files with 49 additions and 405 deletions.
6 changes: 0 additions & 6 deletions docs/src/rules/array-bracket-spacing.md
Expand Up @@ -13,8 +13,6 @@ A number of style guides require or disallow spaces between array brackets and o
applies to both array literals and destructuring assignments (ECMAScript 6).

```js
/*eslint-env es6*/

var arr = [ 'foo', 'bar' ];
var [ x, y ] = z;

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

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

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

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

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

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

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

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

var arr = [];
var arr = [ 'foo', 'bar', 'baz' ];
Expand Down
9 changes: 1 addition & 8 deletions docs/src/rules/arrow-body-style.md
Expand Up @@ -31,7 +31,6 @@ Examples of **incorrect** code for this rule with the `"always"` option:

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

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

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

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

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

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

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

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

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

let foo = () => ({});
let bar = () => ({ bar: 0 });
```
Expand All @@ -135,7 +131,6 @@ Examples of **correct** code for this rule with the `{ "requireReturnForObjectLi

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

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

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

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

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

let foo = () => 0;
let bar = () => ({ foo: 0 });
Expand Down
20 changes: 0 additions & 20 deletions docs/src/rules/arrow-parens.md
Expand Up @@ -15,8 +15,6 @@ be wrapped in parentheses. This rule enforces the consistent use of parentheses
This rule enforces parentheses around arrow function parameters regardless of arity. For example:

```js
/*eslint-env es6*/

// Bad
a => {}

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

```js
/*eslint-env es6*/

// Bad
if (a => 2) {
}
Expand All @@ -42,8 +38,6 @@ if (a >= 2) {
The rule can also be configured to discourage the use of parens when they are not required:

```js
/*eslint-env es6*/

// Bad
(a) => {}

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

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

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

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

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

```js
/*eslint-env es6*/

var a = 1;
var b = 2;
// ...
Expand All @@ -125,8 +115,6 @@ The contents of the `if` statement is an arrow function, not a comparison.
If the arrow function is intentional, it should be wrapped in parens to remove ambiguity.

```js
/*eslint-env es6*/

var a = 1;
var b = 0;
// ...
Expand All @@ -141,8 +129,6 @@ if ((a) => b) {
The following is another example of this behavior:

```js
/*eslint-env es6*/

var a = 1, b = 2, c = 3, d = 4;
var f = a => b ? c: d;
// f = ?
Expand All @@ -153,8 +139,6 @@ var f = a => b ? c: d;
This should be rewritten like so:

```js
/*eslint-env es6*/

var a = 1, b = 2, c = 3, d = 4;
var f = (a) => b ? c: d;
```
Expand All @@ -167,7 +151,6 @@ Examples of **incorrect** code for this rule with the `"as-needed"` option:

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

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

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

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

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

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

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

(a) => {};
(a) => {'\n'};
Expand Down
8 changes: 0 additions & 8 deletions docs/src/rules/arrow-spacing.md
Expand Up @@ -8,8 +8,6 @@ This rule was **deprecated** in ESLint v8.53.0. Please use the [corresponding ru
This rule normalize style of spacing before/after an arrow function's arrow(`=>`).

```js
/*eslint-env es6*/

// { "before": true, "after": true }
(a) => {}

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

```js
/*eslint arrow-spacing: "error"*/
/*eslint-env es6*/

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

```js
/*eslint arrow-spacing: "error"*/
/*eslint-env es6*/

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

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

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

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

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

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

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

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

()=> {};
(a)=> {};
Expand Down
2 changes: 0 additions & 2 deletions docs/src/rules/capitalized-comments.md
Expand Up @@ -42,7 +42,6 @@ Examples of **correct** code for this rule:
// 丈 Non-Latin character at beginning of comment

/* eslint semi:off */
/* eslint-env node */
/* eslint-disable */
/* eslint-enable */
/* istanbul ignore next */
Expand Down Expand Up @@ -118,7 +117,6 @@ Examples of **correct** code for this rule:
// 丈 Non-Latin character at beginning of comment

/* eslint semi:off */
/* eslint-env node */
/* eslint-disable */
/* eslint-enable */
/* istanbul ignore next */
Expand Down
3 changes: 1 addition & 2 deletions docs/src/rules/class-methods-use-this.md
Expand Up @@ -62,7 +62,6 @@ Examples of **incorrect** code for this rule:

```js
/*eslint class-methods-use-this: "error"*/
/*eslint-env es6*/

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

```js
/*eslint class-methods-use-this: "error"*/
/*eslint-env es6*/

class A {
foo() {
this.bar = "Hello World"; // OK, this is used
Expand Down
9 changes: 0 additions & 9 deletions docs/src/rules/computed-property-spacing.md
Expand Up @@ -13,8 +13,6 @@ While formatting preferences are very personal, a number of style guides require
or disallow spaces between computed properties in the following situations:

```js
/*eslint-env es6*/

var obj = { prop: "value" };
var a = "prop";
var x = obj[a]; // computed property in object member expression
Expand Down Expand Up @@ -57,7 +55,6 @@ Examples of **incorrect** code for this rule with the default `"never"` option:

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

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

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

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

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

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

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

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

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

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

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

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

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

class Foo {
[a ]() {}
Expand Down
2 changes: 0 additions & 2 deletions docs/src/rules/constructor-super.md
Expand Up @@ -30,7 +30,6 @@ Examples of **incorrect** code for this rule:

```js
/*eslint constructor-super: "error"*/
/*eslint-env es6*/

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

```js
/*eslint constructor-super: "error"*/
/*eslint-env es6*/

class A {
constructor() { }
Expand Down
1 change: 0 additions & 1 deletion docs/src/rules/func-name-matching.md
Expand Up @@ -100,7 +100,6 @@ module['exports'] = function foo(name) {};

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

var foo = function bar() {};
var foo = function() {};
Expand Down

0 comments on commit 651ec91

Please sign in to comment.