Skip to content

Commit

Permalink
docs: fix linebreak-style examples (#18262)
Browse files Browse the repository at this point in the history
fix `linebreak-style` examples
  • Loading branch information
fasttime committed Apr 10, 2024
1 parent 113f51e commit e1e305d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions docs/src/rules/linebreak-style.md
Expand Up @@ -52,6 +52,7 @@ var a = 'a', // \n
function foo(params) { // \n
// do stuff \n
}// \n

```

:::
Expand All @@ -66,6 +67,7 @@ Examples of **incorrect** code for this rule with the `"windows"` option:
/*eslint linebreak-style: ["error", "windows"]*/

var a = 'a'; // \n

```

:::
Expand All @@ -75,14 +77,15 @@ Examples of **correct** code for this rule with the `"windows"` option:
::: correct

```js
/*eslint linebreak-style: ["error", "windows"]*/

/*eslint linebreak-style: ["error", "windows"]*/ // \r\n
// \r\n
var a = 'a', // \r\n
b = 'b'; // \r\n
// \r\n
function foo(params) { // \r\n
// do stuff \r\n
} // \r\n

```

:::
Expand Down
11 changes: 7 additions & 4 deletions docs/tools/code-block-utils.js
Expand Up @@ -14,11 +14,14 @@
function docsExampleCodeToParsableCode(code) {
return code

// Remove trailing newline and presentational `⏎` characters
.replace(/⏎(?=\n)/gu, "")
// Code blocks always contain an extra line break at the end, so remove it.
.replace(/\n$/u, "")

// Code blocks always contain extra line breaks, so remove them.
.replace(/\n$/u, "");
// Replace LF line breaks with CRLF after `\r\n` sequences.
.replace(/(?<=\\r\\n)\n/gu, "\r\n")

// Remove presentational `⏎` characters at the end of lines.
.replace(/⏎(?=\n)/gu, "");
}

module.exports = {
Expand Down

0 comments on commit e1e305d

Please sign in to comment.