From a1966b3a78a6e79d456c26be511ef8870eb5c1c7 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Tue, 10 Oct 2023 22:12:58 +0200 Subject: [PATCH 1/2] Remove trailing newline from Playground links --- docs/.eleventy.js | 4 ++- docs/src/rules/eol-last.md | 3 ++- docs/src/rules/no-multiple-empty-lines.md | 31 ++++++----------------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index 68c6604cf8d0..33e61f226406 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -207,7 +207,9 @@ module.exports = function(eleventyConfig) { // See https://github.com/eslint/eslint.org/blob/ac38ab41f99b89a8798d374f74e2cce01171be8b/src/playground/App.js#L44 const parserOptionsJSON = tokens[index].info?.split("correct ")[1]?.trim(); const parserOptions = { sourceType: "module", ...(parserOptionsJSON && JSON.parse(parserOptionsJSON)) }; - const { content } = tokens[index + 1]; + + // Remove the trailing newline (https://github.com/eslint/eslint/issues/17627): + const content = tokens[index + 1].content.replace(/\n$/u, ""); const state = encodeToBase64( JSON.stringify({ options: { parserOptions }, diff --git a/docs/src/rules/eol-last.md b/docs/src/rules/eol-last.md index 4c9d837c5c32..2a8de22258b5 100644 --- a/docs/src/rules/eol-last.md +++ b/docs/src/rules/eol-last.md @@ -42,7 +42,8 @@ Examples of **correct** code for this rule: function doSomething() { var foo = 2; -}\n +} + ``` ::: diff --git a/docs/src/rules/no-multiple-empty-lines.md b/docs/src/rules/no-multiple-empty-lines.md index 5457c54c1f0b..89f9ad5a9b09 100644 --- a/docs/src/rules/no-multiple-empty-lines.md +++ b/docs/src/rules/no-multiple-empty-lines.md @@ -88,34 +88,17 @@ 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**: +**Correct**: -::: incorrect +::: correct ```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ -⏎ -var foo = 5;⏎ -⏎ -⏎ -var bar = 3;⏎ -⏎ - -``` - -::: +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/ -**Correct**: +var foo = 5; -::: correct -```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ -⏎ -var foo = 5;⏎ -⏎ -⏎ -var bar = 3;⏎ +var bar = 3; ``` @@ -128,9 +111,10 @@ 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 }]*/ +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1 }]*/ + var foo = 5; @@ -144,6 +128,7 @@ Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` opti ::: correct ```js + /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/ var foo = 5; From 3d275449ee6b75a1d3f794ba7c6c93919aad87f3 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Thu, 12 Oct 2023 21:13:18 +0200 Subject: [PATCH 2/2] Update as per discussion --- docs/.eleventy.js | 6 ++-- docs/src/rules/no-multiple-empty-lines.md | 40 +++++++++++------------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index 33e61f226406..12237c43bd58 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -208,8 +208,10 @@ module.exports = function(eleventyConfig) { const parserOptionsJSON = tokens[index].info?.split("correct ")[1]?.trim(); const parserOptions = { sourceType: "module", ...(parserOptionsJSON && JSON.parse(parserOptionsJSON)) }; - // Remove the trailing newline (https://github.com/eslint/eslint/issues/17627): - const content = tokens[index + 1].content.replace(/\n$/u, ""); + // Remove trailing newline and presentational `⏎` characters (https://github.com/eslint/eslint/issues/17627): + const content = tokens[index + 1].content + .replace(/\n$/u, "") + .replace(/⏎(?=\n)/gu, ""); const state = encodeToBase64( JSON.stringify({ options: { parserOptions }, diff --git a/docs/src/rules/no-multiple-empty-lines.md b/docs/src/rules/no-multiple-empty-lines.md index 89f9ad5a9b09..fbb9363485b6 100644 --- a/docs/src/rules/no-multiple-empty-lines.md +++ b/docs/src/rules/no-multiple-empty-lines.md @@ -59,13 +59,13 @@ Examples of **incorrect** code for this rule with the `{ max: 2, maxEOF: 0 }` op ::: incorrect ```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/ - -var foo = 5; - - -var bar = 3; - +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ +⏎ +var foo = 5;⏎ +⏎ +⏎ +var bar = 3;⏎ +⏎ ``` @@ -76,11 +76,11 @@ Examples of **correct** code for this rule with the `{ max: 2, maxEOF: 0 }` opti ::: correct ```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/ - -var foo = 5; - - +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ +⏎ +var foo = 5;⏎ +⏎ +⏎ var bar = 3; ``` @@ -93,12 +93,12 @@ var bar = 3; ::: correct ```js -/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/ - -var foo = 5; - - -var bar = 3; +/*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ +⏎ +var foo = 5;⏎ +⏎ +⏎ +var bar = 3;⏎ ``` @@ -111,10 +111,9 @@ 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 }]*/ + var foo = 5; @@ -128,7 +127,6 @@ Examples of **correct** code for this rule with the `{ max: 2, maxBOF: 1 }` opti ::: correct ```js - /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxBOF": 1}]*/ var foo = 5;