From 179929bd46892f18f2aef0c159d5cc361cb69987 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Fri, 13 Oct 2023 10:19:12 +0200 Subject: [PATCH] docs: Remove trailing newline from the code of Playground links (#17641) * Remove trailing newline from Playground links * Update as per discussion --- docs/.eleventy.js | 6 +++- docs/src/rules/eol-last.md | 3 +- docs/src/rules/no-multiple-empty-lines.md | 37 ++++++----------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index a2a0b71c17b..75a372d3d5e 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -208,7 +208,11 @@ 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 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/eol-last.md b/docs/src/rules/eol-last.md index 4c9d837c5c3..2a8de22258b 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 5457c54c1f0..fbb9363485b 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;⏎ +⏎ ``` @@ -75,36 +75,19 @@ 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; - - -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**: - -::: incorrect - ```js /*eslint no-multiple-empty-lines: ["error", { "max": 2, "maxEOF": 0 }]*/⏎ ⏎ var foo = 5;⏎ ⏎ ⏎ -var bar = 3;⏎ -⏎ - +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`. + **Correct**: ::: correct