From 1ee3c42ceeee56b650bcc4206ed783b795f65643 Mon Sep 17 00:00:00 2001 From: Arthur Dias Date: Thu, 11 Jun 2020 15:16:59 -0300 Subject: [PATCH] Docs: On maxEOF with eol-last (fixes #12742) (#13374) * Docs: On maxEOF with eol-last (fixes #12742) Added an explanation on how and why maxEOF should be set to 0 to work with the eol-last rule. * Docs: On maxEOF with eol-last (fixes #12742) Added an explanation on how and why maxEOF should be set to 0 to work with the eol-last rule. * Docs: On maxEOF with eol-last (fixes #12742) Added an explanation on how and why maxEOF should be set to 0 to work with the eol-last rule. * Docs: On maxEOF with eol-last (fixes #12742) Added an explanation on how and why maxEOF should be set to 0 to work with the eol-last rule. * Docs: On maxEOF with eol-last (fixes #12742) Added an explanation on how and why maxEOF should be set to 0 to work with the eol-last rule. * Docs: On maxEOF with eol-last (fixes #12742) Added an explanation on how and why maxEOF should be set to 0 to work with the eol-last rule. --- docs/rules/no-multiple-empty-lines.md | 50 ++++++++++++++++++--------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/docs/rules/no-multiple-empty-lines.md b/docs/rules/no-multiple-empty-lines.md index 87b2425e010..836cb18e471 100644 --- a/docs/rules/no-multiple-empty-lines.md +++ b/docs/rules/no-multiple-empty-lines.md @@ -10,9 +10,9 @@ This rule aims to reduce the scrolling required when reading through your code. This rule has an object option: -* `"max"` (default: `2`) enforces a maximum number of consecutive empty lines. -* `"maxEOF"` enforces a maximum number of consecutive empty lines at the end of files. -* `"maxBOF"` enforces a maximum number of consecutive empty lines at the beginning of files. +- `"max"` (default: `2`) enforces a maximum number of consecutive empty lines. +- `"maxEOF"` enforces a maximum number of consecutive empty lines at the end of files. +- `"maxBOF"` enforces a maximum number of consecutive empty lines at the beginning of files. ### max @@ -23,8 +23,6 @@ Examples of **incorrect** code for this rule with the default `{ "max": 2 }` opt var foo = 5; - - var bar = 3; ``` @@ -35,35 +33,56 @@ Examples of **correct** code for this rule with the default `{ "max": 2 }` optio var foo = 5; - var bar = 3; ``` ### maxEOF -Examples of **incorrect** code for this rule with the `{ max: 2, maxEOF: 1 }` options: +Examples of **incorrect** code for this rule with the `{ max: 2, maxEOF: 0 }` options: ```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 1 }]*/ +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/ var foo = 5; - var bar = 3; - - ``` -Examples of **correct** code for this rule with the `{ max: 2, maxEOF: 1 }` options: +Examples of **correct** code for this rule with the `{ max: 2, maxEOF: 0 }` options: ```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 1 }]*/ +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/ var foo = 5; - var bar = 3; +``` + +**Note**: Although this ensures zero empty lines at the EOF, most editors will still show one empty line at the end if the file ends with a line break, as illustrated below. There is no empty line at the end of a file after the last `\n`, although editors may show an additional line. A true additional line would be represented by `\n\n`. +**Incorrect**: + +``` +1 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ +2 ⏎ +3 var foo = 5;⏎ +4 ⏎ +5 ⏎ +6 var bar = 3;⏎ +7 ⏎ +8 +``` + +**Correct**: + +``` +1 /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ +2 ⏎ +3 var foo = 5;⏎ +4 ⏎ +5 ⏎ +6 var bar = 3;⏎ +7 ``` ### maxBOF @@ -73,10 +92,8 @@ Examples of **incorrect** code for this rule with the `{ max: 2, maxBOF: 1 }` op ```js /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/ - var foo = 5; - var bar = 3; ``` @@ -87,7 +104,6 @@ Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` opti var foo = 5; - var bar = 3; ```