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

local custom lint rules for markdownlint are not found #396

Closed
ayyjohn opened this issue Apr 2, 2021 · 3 comments
Closed

local custom lint rules for markdownlint are not found #396

ayyjohn opened this issue Apr 2, 2021 · 3 comments
Labels
question Further information is requested

Comments

@ayyjohn
Copy link
Contributor

ayyjohn commented Apr 2, 2021

in the main directory of my project I created a test file test_rule.js that just throws a lint error on the first line of every linted file

const { forEachLine, getLineMetadata } = require('markdownlint-rule-helpers');

module.exports = {
  "names": [ "first-line" ],
  "description": "Rule that reports an error for the first line",
  "tags": [ "test" ],
  "function": function rule(params, onError) {
    // Unconditionally report an error for line 1
    onError({
      "lineNumber": 1
    });
  }
};

for the purpose of getting custom rules set up and verifying they're working.

After adding

MARKDOWN_MARKDOWNLINT_ARGUMENTS: -r "./test_rule.js"

to my .mega-linter.yml the following error is produced

--Error detail:
Cannot load custom rule ./test_rule.js: No such rule

which comes from here in markdownlint-cli

I tried a bunch of different versions, adding/dropping quotes, changing relativity, and messing with formatting to make sure I wasn't specifying the path wrong or something.

I installed markdownlint-cli via brew and was able to successfully see the custom rule executed by

markdownlint -r "test_rule.js" .

Does this have to do with the dockerization of markdownlint, and is there an option for me to push custom rules into the container so that they can be found?

@ayyjohn ayyjohn added the question Further information is requested label Apr 2, 2021
@tpansino
Copy link
Contributor

Does this have to do with the dockerization of markdownlint

I think yes @ayyjohn. I've played around with the Docker images directly and the source code to be linted gets mounted under /tmp/lint. I'll bet your ./test_rule.js isn't found because the linter is running in a different dir.

Try setting:

MARKDOWN_MARKDOWNLINT_ARGUMENTS: "-r /tmp/lint/test_rule.js"

FWIW you can also customize where the source code gets mounted by changing DEFAULT_WORKSPACE in your .mega-linter.yml. Might have to play around with that if you want to use a relative path, otherwise a full path either to the rule or its parent dir should work.

@nvuillam
Copy link
Member

nvuillam commented Apr 12, 2021

I think tpansino's answer will work

Another mead not tested yet... did you try "-r ${DEFAULT_WORKSPACE}/test_rule.js" , or "-r ${GITHUB_WORKSPACE}/test_rule.js" ? :)

@ayyjohn
Copy link
Contributor Author

ayyjohn commented Apr 14, 2021

Tom's version did work!

I tried MARKDOWN_MARKDOWNLINT_ARGUMENTS: -r "${DEFAULT_WORKSPACE}/custom_lint_rules" and it tried to interpret it literally Cannot load custom rule ${DEFAULT_WORKSPACE}/custom_lint_rules: No such rule

I think I'm okay with this as is though, now that I know everything goes through tmp/lint
thanks both!!

@ayyjohn ayyjohn closed this as completed Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants