From a58aa200fccedae7e2e9b6129246f2cedab14f8d Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 13 Oct 2023 16:46:08 +0200 Subject: [PATCH] docs: fix examples for several rules (#17645) --- docs/src/rules/arrow-body-style.md | 4 + docs/src/rules/function-paren-newline.md | 12 +- docs/src/rules/id-match.md | 2 +- docs/src/rules/indent.md | 4 +- docs/src/rules/lines-around-directive.md | 166 +++++++++++++++------- docs/src/rules/max-statements-per-line.md | 2 +- docs/src/rules/max-statements.md | 10 +- docs/src/rules/no-multiple-empty-lines.md | 16 +++ docs/src/rules/one-var.md | 10 +- 9 files changed, 157 insertions(+), 69 deletions(-) diff --git a/docs/src/rules/arrow-body-style.md b/docs/src/rules/arrow-body-style.md index 1bfdb5a7308..1dc6fcc36e8 100644 --- a/docs/src/rules/arrow-body-style.md +++ b/docs/src/rules/arrow-body-style.md @@ -32,6 +32,7 @@ Examples of **incorrect** code for this rule with the `"always"` option: ```js /*eslint arrow-body-style: ["error", "always"]*/ /*eslint-env es6*/ + let foo = () => 0; ``` @@ -42,6 +43,9 @@ Examples of **correct** code for this rule with the `"always"` option: :::correct ```js +/*eslint arrow-body-style: ["error", "always"]*/ +/*eslint-env es6*/ + let foo = () => { return 0; }; diff --git a/docs/src/rules/function-paren-newline.md b/docs/src/rules/function-paren-newline.md index e6a067cf5f2..ad44aaec365 100644 --- a/docs/src/rules/function-paren-newline.md +++ b/docs/src/rules/function-paren-newline.md @@ -339,11 +339,15 @@ var barbaz = function( bar, baz ) {}; -var barbaz = (bar, - baz) => {}; +var barbaz = ( + bar, + baz +) => {}; -foo(bar, - baz); +foo( + bar, + baz +); ``` ::: diff --git a/docs/src/rules/id-match.md b/docs/src/rules/id-match.md index 6d15d19e859..59954fc2a48 100644 --- a/docs/src/rules/id-match.md +++ b/docs/src/rules/id-match.md @@ -143,7 +143,7 @@ Examples of **correct** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", { ```js /*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/ -do_something(__dirname); +foo = __dirname; ``` ::: diff --git a/docs/src/rules/indent.md b/docs/src/rules/indent.md index e53a1f9a6e1..72efad26568 100644 --- a/docs/src/rules/indent.md +++ b/docs/src/rules/indent.md @@ -192,7 +192,7 @@ Examples of **correct** code for this rule with the `4, { "ignoredNodes": ["Call foo(); bar(); -}) +})(); ``` ::: @@ -403,7 +403,7 @@ function foo(x) { })(); if (y) { - console.log('foo'); + console.log('foo'); } ``` diff --git a/docs/src/rules/lines-around-directive.md b/docs/src/rules/lines-around-directive.md index 8a83df1afd7..7c18b517446 100644 --- a/docs/src/rules/lines-around-directive.md +++ b/docs/src/rules/lines-around-directive.md @@ -65,14 +65,8 @@ Examples of **incorrect** code for this rule with the `"always"` option: ```js /* eslint lines-around-directive: ["error", "always"] */ -/* Top of file */ -"use strict"; -var foo; - -/* Top of file */ // comment "use strict"; -"use asm"; var foo; function foo() { @@ -90,23 +84,29 @@ function foo() { ::: -Examples of **correct** code for this rule with the `"always"` option: - -::: correct { "sourceType": "script" } +::: incorrect { "sourceType": "script" } ```js /* eslint lines-around-directive: ["error", "always"] */ -/* Top of file */ +// comment "use strict"; - +"use asm"; var foo; +``` + +::: + +Examples of **correct** code for this rule with the `"always"` option: + +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", "always"] */ -/* Top of file */ // comment "use strict"; -"use asm"; var foo; @@ -128,6 +128,21 @@ function foo() { ::: +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", "always"] */ + +// comment + +"use strict"; +"use asm"; + +var foo; +``` + +::: + ### never Examples of **incorrect** code for this rule with the `"never"` option: @@ -137,17 +152,9 @@ Examples of **incorrect** code for this rule with the `"never"` option: ```js /* eslint lines-around-directive: ["error", "never"] */ -/* Top of file */ - -"use strict"; - -var foo; - -/* Top of file */ // comment "use strict"; -"use asm"; var foo; @@ -169,21 +176,30 @@ function foo() { ::: -Examples of **correct** code for this rule with the `"never"` option: - -::: correct { "sourceType": "script" } +::: incorrect { "sourceType": "script" } ```js /* eslint lines-around-directive: ["error", "never"] */ -/* Top of file */ +// comment + "use strict"; +"use asm"; + var foo; +``` + +::: + +Examples of **correct** code for this rule with the `"never"` option: + +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", "never"] */ -/* Top of file */ // comment "use strict"; -"use asm"; var foo; function foo() { @@ -201,6 +217,19 @@ function foo() { ::: +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", "never"] */ + +// comment +"use strict"; +"use asm"; +var foo; +``` + +::: + ### before & after Examples of **incorrect** code for this rule with the `{ "before": "never", "after": "always" }` option: @@ -210,16 +239,9 @@ Examples of **incorrect** code for this rule with the `{ "before": "never", "aft ```js /* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */ -/* Top of file */ - -"use strict"; -var foo; - -/* Top of file */ // comment "use strict"; -"use asm"; var foo; function foo() { @@ -238,22 +260,29 @@ function foo() { ::: -Examples of **correct** code for this rule with the `{ "before": "never", "after": "always" }` option: - -::: correct { "sourceType": "script" } +::: incorrect { "sourceType": "script" } ```js /* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */ -/* Top of file */ -"use strict"; +// comment +"use strict"; +"use asm"; var foo; +``` + +::: + +Examples of **correct** code for this rule with the `{ "before": "never", "after": "always" }` option: + +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */ -/* Top of file */ // comment "use strict"; -"use asm"; var foo; @@ -274,22 +303,29 @@ function foo() { ::: -Examples of **incorrect** code for this rule with the `{ "before": "always", "after": "never" }` option: - -::: incorrect { "sourceType": "script" } +::: correct { "sourceType": "script" } ```js -/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */ +/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */ -/* Top of file */ +// comment "use strict"; +"use asm"; var foo; +``` + +::: + +Examples of **incorrect** code for this rule with the `{ "before": "always", "after": "never" }` option: + +::: incorrect { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */ -/* Top of file */ // comment "use strict"; -"use asm"; var foo; @@ -310,22 +346,30 @@ function foo() { ::: -Examples of **correct** code for this rule with the `{ "before": "always", "after": "never" }` option: - -::: correct { "sourceType": "script" } +::: incorrect { "sourceType": "script" } ```js /* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */ -/* Top of file */ +// comment "use strict"; +"use asm"; + var foo; +``` + +::: + +Examples of **correct** code for this rule with the `{ "before": "always", "after": "never" }` option: + +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */ -/* Top of file */ // comment "use strict"; -"use asm"; var foo; function foo() { @@ -344,6 +388,20 @@ function foo() { ::: +::: correct { "sourceType": "script" } + +```js +/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */ + +// comment + +"use strict"; +"use asm"; +var foo; +``` + +::: + ## When Not To Use It You can safely disable this rule if you do not have any strict conventions about whether or not directive prologues should have blank newlines before or after them. diff --git a/docs/src/rules/max-statements-per-line.md b/docs/src/rules/max-statements-per-line.md index 76a49e3a09b..d42d2ef55c1 100644 --- a/docs/src/rules/max-statements-per-line.md +++ b/docs/src/rules/max-statements-per-line.md @@ -76,7 +76,7 @@ if (condition) { bar = 1; } else { baz = 2; } for (var i = 0; i < length; ++i) { bar = 1; baz = 2; } switch (discriminant) { case 'test': break; default: break; } function foo() { bar = 1; baz = 2; } -var qux = function qux() { bar = 1; }; +var qux = function qux() { bar = 1; baz = 2; }; (function foo() { bar = 1; baz = 2; })(); ``` diff --git a/docs/src/rules/max-statements.md b/docs/src/rules/max-statements.md index 4462011db74..5bdc7e8c2f4 100644 --- a/docs/src/rules/max-statements.md +++ b/docs/src/rules/max-statements.md @@ -99,12 +99,13 @@ function foo() { var foo7 = 7; var foo8 = 8; var foo9 = 9; - var foo10 = 10; - return function () { + return function () { // 10 // The number of statements in the inner function does not count toward the // statement maximum. + var bar; + var baz; return 42; }; } @@ -119,12 +120,13 @@ let bar = () => { var foo7 = 7; var foo8 = 8; var foo9 = 9; - var foo10 = 10; - return function () { + return function () { // 10 // The number of statements in the inner function does not count toward the // statement maximum. + var bar; + var baz; return 42; }; } diff --git a/docs/src/rules/no-multiple-empty-lines.md b/docs/src/rules/no-multiple-empty-lines.md index fbb9363485b..e3d7327c2e4 100644 --- a/docs/src/rules/no-multiple-empty-lines.md +++ b/docs/src/rules/no-multiple-empty-lines.md @@ -111,6 +111,8 @@ Examples of **incorrect** code for this rule with the `{ max: 2, maxBOF: 1 }` op ::: incorrect ```js + + /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/ @@ -132,6 +134,20 @@ Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` opti var foo = 5; +var bar = 3; +``` + +::: + +::: correct + +```js + +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/ + +var foo = 5; + + var bar = 3; ``` diff --git a/docs/src/rules/one-var.md b/docs/src/rules/one-var.md index b44c583dd35..cb3bc09b955 100644 --- a/docs/src/rules/one-var.md +++ b/docs/src/rules/one-var.md @@ -416,12 +416,16 @@ Examples of **correct** code for this rule with the `{ var: "never" }` option: /*eslint-env es6*/ function foo() { - var bar, - baz; - const foobar = 1; // `const` and `let` declarations are ignored if they are not specified + var bar; + var baz; + + // `const` and `let` declarations are ignored if they are not specified + const foobar = 1; const foobaz = 2; + const barfoo = 1, bazfoo = 2; let qux; let norf; + let fooqux, foonorf; } ```