remark-lint: `no-undefined-references`: support regex in `allow` option

Initial checklist

Problem

The Markdown I’m linting contains undefined references because they are implicitly resolved by the documentation library I’m using (in my case the MkDocs extension mkdocstrings via its cross-references feature). I would like to support allowing undefined references according to a regex pattern, typically something like ^mylib\. (which is a Python root package prefix in my case).

Solution

For this to work, the allow option would need to be extended to support regex patterns.

I imagine the options object could be extended to this type (TS syntax):

type Options = {
  allow: Array<string | { pattern: string }>
}

If this proposal gets accepted, I’d be happy to submit a PR.

Alternatives

Without supporting a regex pattern, I can only disable the linter:

<!-- lint disable no-undefined-references -->
[`Object 1`][full.path.object1]
<!-- lint enable no-undefined-references -->

But that’s a bit tedious to do everywhere in the docs.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 25 (23 by maintainers)

Commits related to this issue

Most upvoted comments

I think it’s a good-to-have feature personally. 👍

can used directly withou

Yes, that is my main point. regexes are in most cases fine with unicode.

would be useful to ignore all emojis in definitions

I agree that it could be useful, but for now I’d say: let’s first wait for people that need this, for an actual use case!

I think the first is good, and we can go with case-insensitive always. If needed, we can add a caseSensitive?: bool field later, or add a flags field?

I am not sure about the name. Perhaps source? The benefit of this is that a regex also has a source, so it mimics that: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source.

So, what’s the syntax then?

  1. type Options = {
      allow: Array<string | RegExp | { pattern: string }>
    }
    
  2. type Options = {
      allow: Array<string | RegExp | [pattern: string, flags?: string]>
    }
    

Regex flags means i, g, u, etc.

And RegExp type is not allowed in JSON.

So maybe

type Options = {
  allow: Array<string | [pattern: string, flags: string]>
}