sindresorhus / awesome-lint

Linter for Awesome lists
MIT License
600 stars 56 forks source link

fix: Properly detect 'Contents' header if it includes an HTML comment #174

Closed hyperupcall closed 11 months ago

hyperupcall commented 11 months ago

Given an Awesome Markdown file that includes the following:

...
## Contents  <!-- omit from toc -->

- [Official](#official)
- [Instances](#instances)
- [Statistics](#statistics)
- [People](#people)
- [Tools](#tools)
...

Linting fails because of the <!-- omit from toc --> comment.

$ pnpx awesome-lint
✖ Linting

  README.md:11:3
  ✖   1:1  Missing or invalid Table of Contents  remark-lint:awesome-toc
  ✖  11:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  12:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  13:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  14:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  15:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  16:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  17:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  18:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  19:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  20:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  21:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  22:3  Invalid list item link URL            remark-lint:awesome-list-item
  ✖  23:3  Invalid list item link URL            remark-lint:awesome-list-item

  14 errors

(This comment is useful because it tells the Markdown All in One VSCode extension to exclude it from the auto-generated table of contents, as per Awesome Rules.)

After applying this patch, no more errors are printed.

After:

$ pnpx awesome-lint
✔ Linting

Note that the toString() function does accept an option called includeHtml, but unfortunately that did not help in this case. So this regex seemed like the next best alternative.