markdownlint-cli2 icon indicating copy to clipboard operation
markdownlint-cli2 copied to clipboard

How-to use `markdownItPlugins` in YAML?

Open vorburger opened this issue 1 year ago • 3 comments

I use this great project (Thank You!) on https://github.com/enola-dev/enola,

via https://github.com/DavidAnson/vscode-markdownlint and (more importantly) through https://github.com/DavidAnson/markdownlint-cli2#pre-commit for https://pre-commit.com.

I currently use the https://github.com/DavidAnson/markdownlint-cli2#markdownlintyaml-or-markdownlintyml way to configure it, with a .markdownlint.yaml file, which seems to used both by Pre-Commit and VSC - that's great! (And seems better than e.g. configuring only VSC via https://github.com/DavidAnson/vscode-markdownlint#markdownlintcustomrules.)

https://github.com/DavidAnson/markdownlint/issues/121 made me discover https://github.com/theoludwig/markdownlint-rule-relative-links from @theoludwig and I would like to use it - but I can't seem to figure out how to configure plugins in YAML. I've tried adding this, for an "array of array" (with no options):

markdownItPlugins:
  - - markdownlint-rule-relative-links

but it looks like that's just ignored? If I change a link to break it, git add . and then run pre-commit run --all-files it doesn't flag it.

https://github.com/DavidAnson/markdownlint/blob/main/README.md#optionsmarkdownitplugins mentions require but I suspect that's not required in YAML?

@DavidAnson @theoludwig @igor-tsiglyar perhaps you have a suggestion? (I can raise a PR to clarify the doc, once I got it working.)

vorburger avatar Jan 29 '24 01:01 vorburger

Your syntax seems correct. Here is an example with everything set: https://github.com/DavidAnson/markdownlint-cli2/blob/main/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml

Why do you think it isn't working?

DavidAnson avatar Jan 29 '24 02:01 DavidAnson

Oh, wait, it looks like you may be confusing the two types of configuration files. The fourth bullet point here explains that: https://github.com/DavidAnson/markdownlint-cli2#configuration

DavidAnson avatar Jan 29 '24 02:01 DavidAnson

@DavidAnson I am using only .markdownlint-cli2.yaml and tweaked .pre-commit-config as follows

- repo: https://github.com/DavidAnson/markdownlint-cli2
  rev: v0.12.1
  hooks:
    - id: markdownlint-cli2
      additional_dependencies:
        - markdownlint-rule-relative-links

and I am getting the error


TypeError: plugin.apply is not a function
    at MarkdownIt.use (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdown-it/dist/index.cjs.js:5432:10)
    at lintInput (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/markdownlint.js:908:8)
    at markdownlint (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/markdownlint.js:1003:10)
    at node:internal/util:430:21
    at new Promise (<anonymous>)
    at markdownlint (node:internal/util:416:12)
    at markdownlintPromise (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/node_modules/markdownlint/lib/markdownlint.js:1016:10)
    at lintFiles (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/markdownlint-cli2.js:783:16)
    at main (/Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/markdownlint-cli2.js:1011:29)
    at async /Users/foo/.cache/pre-commit/repos6uzlyzr/node_env-default/lib/node_modules/markdownlint-cli2/markdownlint-cli2.js:1053:26

Is the error related to markdownlint-cli2?

Since you have mentioned node version https://github.com/DavidAnson/markdownlint-cli2/blob/82c791e94c2e2ab2119437d61c722c8e0c20d6c9/README.md?plain=1#L404-L405

I have NodeJS already installed https://github.com/pre-commit/pre-commit/blob/73848383f2f4d0fc97b2a769afb6da35610672a8/pre_commit/languages/node.py#L31-L32

$ node --version
v20.11.0

Which is compatible with https://github.com/theoludwig/markdownlint-rule-relative-links/blob/146f904866e30a14faafdf77af1246e54b50792d/README.md?plain=1#L69

electriquo avatar Jan 29 '24 14:01 electriquo

@vorburger, markdownlint-rule-relative-links is a custom rule, not a markdown-it plugin. It can be configured like so in .markdownlint-cli2.yaml:

customRules:
  - markdownlint-rule-relative-links

You link to a .markdownlint.yaml file, so also make sure you're not editing that file per my earlier comment.

@electriquo, you don't show the configuration you're using, so I can't tell what's going on, but the error above suggests you're making the same mistake.

DavidAnson avatar Jan 30 '24 05:01 DavidAnson

@DavidAnson You're awesome. After your explanation it works for me. Thank you.

electriquo avatar Jan 30 '24 06:01 electriquo