Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more flexibility to hyphen separated check; explicit em-dash check #185

Merged
merged 10 commits into from Jan 2, 2024

Conversation

WillForan
Copy link
Contributor

@WillForan WillForan commented Dec 31, 2023

test to confirm #146 and #49 are resolved (though I think at least 146 was already making it through without getting flagged)

The big kludge in this pull request is allowing description text matching " - " to pass through instead of getting hit with "link and description must be separated with a dash."

I also un-commented the TODO list-items fixture that had want-to-be valid image-before-link entries.
They had em-dash separators instead of standard hyphens. I updated lint message to complain about that in addition to en-dashes.

Fixes #146
Fixes #49

rules/list-item.js Outdated Show resolved Hide resolved
rules/list-item.js Outdated Show resolved Hide resolved
continue;
}

let [link, ...description] = paragraph.children;

// Might have children like {image} {text} {link} - {descrition}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

// Might have children like {image} {text} {link} - {descrition}
// Keep discarding elements until we find a link
// or linkReference
if (!/link/.test(link.type)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare explicitly. Doesn't make sense to use regex here.

Copy link
Contributor Author

@WillForan WillForan Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides linkReference and link, I'm not sure if there are other link items in markdown -- figured any type matching "link" should get to pass
link.type !== 'linkReference' && link.type !== 'link' is a mouth full :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use Array#includes.


besides linkReference and link, I'm not sure if there are other link items in markdown

Look at the docs for the Markdown parser.

// Keep discarding elements until we find a link
// or linkReference
if (!/link/.test(link.type)) {
for (let i = 0; i < description.length - 1; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a for-of loop.

Copy link
Contributor Author

@WillForan WillForan Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worse, I don't think I need to test link's type twice. while loop is probably better? (in recent commit)

Comment on lines 112 to 113
// Keep discarding elements until we find a link
// or linkReference
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Keep discarding elements until we find a link
// or linkReference
// Keep discarding elements until we find a `link` or `linkReference`.

rules/list-item.js Outdated Show resolved Hide resolved
// NB. We 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?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be resolved.

@sindresorhus sindresorhus merged commit 6343a75 into sindresorhus:main Jan 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error caused by two dashes in item Allow github star badges
2 participants