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

Throw on bad config file #228

Merged
merged 2 commits into from
Oct 27, 2021
Merged

Throw on bad config file #228

merged 2 commits into from
Oct 27, 2021

Conversation

janosh
Copy link
Contributor

@janosh janosh commented Oct 26, 2021

Closes #105.

@janosh janosh changed the title throw-on-bad-config-file Throw on bad config file Oct 26, 2021
Copy link
Collaborator

@DavidAnson DavidAnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

markdownlint.js Outdated
@@ -68,7 +68,7 @@ function readConfiguration(userConfigFile) {
markdownlint.readConfigSync(userConfigFile, configFileParsers);
config = require('deep-extend')(config, userConfig);
} catch (error) {
console.warn('Cannot read or parse config file ' + userConfigFile + ': ' + error.message);
throw 'Cannot read or parse config file ' + userConfigFile + ': ' + error.message;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests to cover the new behavior. I'm thinking one for missing file and one for a invalid file?

Also, why not a change more like: https://github.com/igorshubovych/markdownlint-cli/blob/master/markdownlint.js#L190-L193? I'm not sure I see where the throw gets turned into an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing I don't like about letting the process run by setting an exitCode but not calling exit() is it accumulates further output to stdout/err. If you then write tests, you get more than the minimal output. E.g.

 [Expected: 1; Actual: 2]
  - `Cannot read or parse config file 'non-existent-file-path.yaml': ENOENT: no such file or directory, open 'non-existent-file-path.yaml'␊
  - md043-config.md:13 MD012/no-multiple-blanks Multiple consecutive blank lines␊

I'll use it of course to keep consistency. Didn't see the similar case on L190-L193 before.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, future refactoring... :)

Copy link
Collaborator

@DavidAnson DavidAnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just one small request!

test/test.js Show resolved Hide resolved
@DavidAnson DavidAnson merged commit 40a0ee6 into igorshubovych:master Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior on invalid config
2 participants