Skip to content

Commit

Permalink
maximum-line-length: refactor long link algo a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 17, 2024
1 parent 159d927 commit 8481a05
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 13 deletions.
53 changes: 44 additions & 9 deletions packages/remark-lint-maximum-line-length/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@
*
* <div>Mercury mercury mercury mercury mercury mercury mercury mercury mercury</div>
*
* Mercury
* <http://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury>
* mercury mercury.
*
* [foo]: http://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury
*
* @example
Expand Down Expand Up @@ -105,6 +101,47 @@
* 20:43: Unexpected `42` character line, expected at most `20` characters, remove `22` characters
*
* @example
* {"config": 20, "name": "long-autolinks-ok.md", "positionless": true}
*
* <http://localhost/mercury/>
*
* <http://localhost/mercury/>
* mercury.
*
* Mercury
* <http://localhost/mercury/>.
*
* Mercury
* <http://localhost/mercury/>
* mercury.
*
* Mercury
* <http://localhost/mercury/>
* mercury mercury.
*
* Mercury mercury
* <http://localhost/mercury/>
* mercury mercury.
*
* @example
* {"config": 20, "label": "input", "name": "long-autolinks-nok.md", "positionless": true}
*
* <http://localhost/mercury/> mercury.
*
* Mercury <http://localhost/mercury/>.
*
* Mercury
* <http://localhost/mercury/> mercury.
*
* Mercury <http://localhost/mercury/>
* mercury.
* @example
* {"config": 20, "label": "output", "name": "long-autolinks-nok.md"}
*
* 1:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters
* 6:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters
*
* @example
* {"config": 20, "frontmatter": true, "name": "ok.md", "positionless": true}
*
* ---
Expand Down Expand Up @@ -242,19 +279,17 @@ const remarkLintMaximumLineLength = lintRule(

const next = parent.children[index + 1]
const nextStart = pointStart(next)
const nextEnd = pointEnd(next)

// Not allowing when there’s a following child.
// Not allowing when there’s a following child with a break
// opportunity on the line.
if (
next &&
nextStart &&
nextStart.line === start.line &&
nextEnd &&
nextEnd.line === start.line &&
// Either something with children:
(!('value' in next) ||
// Or with whitespace:
/[ \t]/.test(next.value))
/^([^\r\n]*)[ \t]/.test(next.value))
) {
return
}
Expand Down
61 changes: 57 additions & 4 deletions packages/remark-lint-maximum-line-length/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ Mercury mercury mercury mercury mercury mercury mercury mercury mercury ![mercur

<div>Mercury mercury mercury mercury mercury mercury mercury mercury mercury</div>

Mercury
<http://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury>
mercury mercury.

[foo]: http://localhost/mercury/mercury/mercury/mercury/mercury/mercury/mercury/mercury
```

Expand Down Expand Up @@ -220,6 +216,63 @@ Mercury mercury ![m](example.com) mercury.
20:43: Unexpected `42` character line, expected at most `20` characters, remove `22` characters
```

##### `long-autolinks-ok.md`

When configured with `20`.

###### In

```markdown
<http://localhost/mercury/>

<http://localhost/mercury/>
mercury.

Mercury
<http://localhost/mercury/>.

Mercury
<http://localhost/mercury/>
mercury.

Mercury
<http://localhost/mercury/>
mercury mercury.

Mercury mercury
<http://localhost/mercury/>
mercury mercury.
```

###### Out

No messages.

##### `long-autolinks-nok.md`

When configured with `20`.

###### In

```markdown
<http://localhost/mercury/> mercury.

Mercury <http://localhost/mercury/>.

Mercury
<http://localhost/mercury/> mercury.

Mercury <http://localhost/mercury/>
mercury.
```

###### Out

```text
1:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters
6:37: Unexpected `36` character line, expected at most `20` characters, remove `16` characters
```

##### `ok.md`

When configured with `20`.
Expand Down

0 comments on commit 8481a05

Please sign in to comment.