Skip to content

Commit

Permalink
address sindresorhus#161 with linkReference test; update list-item sn…
Browse files Browse the repository at this point in the history
…apshots
  • Loading branch information
WillForan committed Dec 31, 2023
1 parent dc58049 commit ae91733
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions rules/list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ function validateList(list, file) {

// Might have children like {image} {text} {link} - {descrition}
// Keep discarding elements until we find a link
if (link.type !== 'link') {
// or linkReference
if (!/link/.test(link.type)) {
for (let i = 0; i < description.length - 1; i++) {
if (description[i].type === 'link') {
if (/link/.test(description[i].type)) {
link = description[i];
description = description.slice(i + 1);
}
Expand All @@ -128,6 +129,13 @@ function validateList(list, file) {
}

function validateListItemLink(link, file) {
// NB. need remark-lint-no-undefined-references separately
// to catch if this is a valid reference. here we only care that it exists
if (link.type === 'linkReference') {
// TODO: need to test link children against listItemLinkNodeAllowList?
return true;
}

if (link.type !== 'link') {
file.message('Invalid list item link', link);
return false;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/list-item/0.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ These sub-lists use mixed indentation (spaces and tabs).
- [why-is-node-running](https://github.com/mafintosh/why-is-node-running) - Node.js is running but you don't know why?


- [gtkada] - Ada graphical toolkit based on Gtk3 components (issue #161 link reference below but checked by `remark-lint-no-undefined-references` not `rules/list-item.js`).
- [foo](https://foo.com) ![stars](https://img.shields.io/github/stars/foo/foo.svg) - Valid description.
- ![v3](img/vapor-3.png) [API Error Middleware](https://github.com/skelpo/APIErrorMiddleware) - Vapor middleware for converting thrown errors to JSON responses.
- ![v2](img/vapor-2.png) ![v3](img/vapor-3.png) [Bugsnag](https://github.com/nodes-vapor/bugsnag) - Report errors with Bugsnag.
Expand All @@ -145,3 +146,5 @@ These sub-lists use mixed indentation (spaces and tabs).
- [__Compiling machine learning programs via high-level tracing__. Roy Frostig, Matthew James Johnson, Chris Leary. _MLSys 2018_.](https://mlsys.org/Conferences/doc/2018/146.pdf) - This white paper describes an early version of JAX, detailing how computation is traced and compiled (issue #136)
-->

[gtkada]: https://github.com/AdaCore/gtkada

1 change: 1 addition & 0 deletions test/fixtures/list-item/1.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ Test description's ending punctuation.

- [foo](https://foo.com) - Quote-inducing double punctuation “end…”??!
- [foo](https://foo.com) - Quote-inducing double punctuation “end?…...”…...?
- [gtkada] - reference link with no reference
Binary file modified test/rules/snapshots/list-item.js.snap
Binary file not shown.

0 comments on commit ae91733

Please sign in to comment.