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 lint for a link reference without a corresponding link definition (or vice versa) #456
Comments
|
Yes, agreed with this completely. A friend and I were working on a small standalone Markdown linter for writing purposes and this was actually our first feature! So strange that it's not in there. |
|
@jasonsnell, I think I listen to your podcasts sometimes. :) Yes, there is a set of link-based rules in the queue I just haven't got to yet. |
|
I usually use https://www.npmjs.com/package/markdown-link-check since when you start to link check outside of the same document, you need to have a concept of a layout and replacements |
|
Just tried markdown-link-check with the snippets from above: echo 'See [Docs][] for more info.
<!-- Should have a link definition below like:
[docs]: https://example.com
-->' > ref_without_def.md
docker run -v ${PWD}:/tmp:ro --rm -i ghcr.io/tcort/markdown-link-check:stable /tmp/ref_without_def.md
echo 'See [New Docs][] for more info.
<!-- None of the link definitions match the link reference above. -->
[docs]: https://example.com' > def_without_ref.md
docker run -v ${PWD}:/tmp:ro --rm -i ghcr.io/tcort/markdown-link-check:stable /tmp/def_without_ref.mdOutput (0 exit code): so doesn't actually seem like it catches this case, possibly because it considers having extra refs/defs to be an okay thing to do (whereas for me it's nearly always copy-pasta, or someone forgetting how the defs/refs actually work. |
|
Right, I missread this, but it looks like a duplicate of #144 |
|
Agree, I'll probably try to add this for the next (not pending) release. |
|
Here is the remark-lint version of this rule https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-no-undefined-references to see if they have any edge case code that might be needed |
|
FWIW, speaking as a professional writer who writes exclusively in markdown, forgetting a link reference either way happens way more than you'd think!
… On Dec 24, 2021, at 3:15 AM, Gibson Fahnestock ***@***.***> wrote:
Just tried markdown-link-check with the snippets from above:
echo 'See [Docs][] for more info.
<!-- Should have a link definition below like:
[docs]: https://example.com
-->' > ref_without_def.md
docker run -v ${PWD}:/tmp:ro --rm -i ghcr.io/tcort/markdown-link-check:stable /tmp/ref_without_def.md
echo 'See [New Docs][] for more info.
<!-- None of the link definitions match the link reference above. -->
[docs]: https://example.com' > def_without_ref.md
docker run -v ${PWD}:/tmp:ro --rm -i ghcr.io/tcort/markdown-link-check:stable /tmp/def_without_ref.md
Output:
FILE: /tmp/ref_without_def.md
No hyperlinks found!
0 links checked.
FILE: /tmp/def_without_ref.md
No hyperlinks found!
0 links checked.
so doesn't actually seem like it catches this case, possibly because it considers having extra refs/defs to be an okay thing to do (whereas for me it's nearly always copy-pasta, or someone forgetting how the defs/refs actually work.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you were mentioned.
|
Ahh, good point, failed to find that in the issue search. |
|
Two new rules will be available in the next release of the library:
They will report errors for:
The latter two scenarios can be automatically fixed by the library (by deleting the unneeded reference definition). /cc @jasonsnell |
|
thank you @DavidAnson ! My friend might have invented Markdown? ;-) |
|
@jasonsnell Hopefully the idea of a Markdown linter does not offend him too much. |
|
He's working on a little one of his own for person writing use, much less comprehensive than this one. I think he likes the idea! But I don't want to speak for him. |
|
@jasonsnell Cool. If there's anything ya'll think I should be doing here to make it more compelling (other than adding more rules), please let me know. For example: editor integration. I happen to think the VS Code integration is pretty good (because I wrote it), but maybe you have a different favorite editor. https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint |
Often (especially when refactoring) links using the definition/reference style will get broken. It would be useful for markdownlint to catch this.
Two examples are:
Link Ref without Def
Link Def without Ref
The text was updated successfully, but these errors were encountered: