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

Inconsistent behavior on invalid config #105

Closed
arvigeus opened this issue Jul 14, 2020 · 3 comments · Fixed by #228
Closed

Inconsistent behavior on invalid config #105

arvigeus opened this issue Jul 14, 2020 · 3 comments · Fixed by #228

Comments

@arvigeus
Copy link

.markdownlint.json

{
  "extends": "this-file-does-not-exist.json"
}

Running markdownlint --fix '**/*.md' silently fails to load invalid file and goes to default config.

Running markdownlint --fix '**/*.md' --config .markdownlint.json displays an error message that this-file-does-not-exist.json is missing.

In my case I was trying to load a valid file that was missing, and it took me some time to realize that the problem is me, not markdownlint being lazy not loading .markdownlint.json. I think it should complain in this case, instead of straight up loading default config.

@victoriadrake
Copy link

victoriadrake commented Jul 28, 2020

Continuation of: a1f9a15#r40919702

I also experienced markdownlint (markdownlint-cli) silently using a default config when I had it run as a pre-commit hook (pre-commit framework). I had passed in a non-existent file path to --config by mistake. Here’s what the hook looks like in .pre-commit-config.yaml:

  - repo: local
    hooks:
      - id: markdownlint
        name: markdownlint
        description: "Lint Markdown files"
        entry: markdownlint '**/*.md' --fix --ignore node_modules --config "./.markdownlint.json"
        language: node
        types: [markdown]

In this scenario, .markdownlint.json did not exist in the project root. I had also tried it with a YAML formatted config file before realizing the erroneous file path.

Expected behavior: an error is raised when the config file does not exist, ie:

Config file not found. Using default config...

@janosh
Copy link
Contributor

janosh commented Oct 26, 2021

@DavidAnson As a fix, do you prefer a custom error message or just bubble up whatever error is thrown when one of these lines fails?

      const userConfig = jsConfigFile ?
        // Evaluate .js configuration file as code
        require(path.resolve(processCwd, userConfigFile)) :
        // Load JSON/YAML configuration as data
        markdownlint.readConfigSync(userConfigFile, configFileParsers);
      config = require('deep-extend')(config, userConfig);

@DavidAnson
Copy link
Collaborator

Both? ;) A general message is good for context while the specific error is good for details. Something like "Error reading configuration file: " + exception.message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants