Skip to content

Commit

Permalink
Add .markdownlint.jsonc to list of automatically-used configuration f…
Browse files Browse the repository at this point in the history
…iles (with highest precedence for consistency with markdownlint-cli2) (fixes #290).
  • Loading branch information
DavidAnson authored Jul 16, 2022
1 parent 2eba8d0 commit 1ce32d6
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ A sample configuration file:
For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], or the [style folder][style-folder].

The CLI argument `--config` is not required.
If it is not provided, `markdownlint-cli` looks for the file `.markdownlint.json`/`.markdownlint.yaml`/`.markdownlint.yml` in current folder, or for the file `.markdownlintrc` in the current or all parent folders.
If it is not provided, `markdownlint-cli` looks for the file `.markdownlint.jsonc`/`.markdownlint.json`/`.markdownlint.yaml`/`.markdownlint.yml` in current folder, or for the file `.markdownlintrc` in the current or all parent folders.
The algorithm is described in detail on the [`rc` package page][rc-standards].
If the `--config` argument is provided, the file must be valid JSON, JSONC, JS, or YAML.
JS configuration files contain JavaScript code, must have the `.js` or `.cjs` file extension, and must export (via `module.exports = ...`) a configuration object of the form shown above.
Expand Down
2 changes: 1 addition & 1 deletion markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const exitCodes = {
unexpectedError: 4
};

const projectConfigFiles = ['.markdownlint.json', '.markdownlint.yaml', '.markdownlint.yml'];
const projectConfigFiles = ['.markdownlint.jsonc', '.markdownlint.json', '.markdownlint.yaml', '.markdownlint.yml'];
const configFileParsers = [jsoncParse, jsYamlSafeLoad];
const fsOptions = {encoding: 'utf8'};
const processCwd = process.cwd();
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions test/config-files/json-c/heading-dollar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Heading$

Text
5 changes: 5 additions & 0 deletions test/config-files/jsonc-json-yaml-yml/.markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"no-trailing-punctuation": {
"punctuation": "!"
}
}
5 changes: 5 additions & 0 deletions test/config-files/jsonc-json-yaml-yml/.markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"no-trailing-punctuation": {
"punctuation": "$"
}
}
2 changes: 2 additions & 0 deletions test/config-files/jsonc-json-yaml-yml/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
no-trailing-punctuation:
punctuation: "!"
2 changes: 2 additions & 0 deletions test/config-files/jsonc-json-yaml-yml/.markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
no-trailing-punctuation:
punctuation: "!"
3 changes: 3 additions & 0 deletions test/config-files/jsonc-json-yaml-yml/heading-dollar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Heading$

Text
9 changes: 9 additions & 0 deletions test/config-files/jsonc/.markdownlint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
// Inline comment
"no-trailing-punctuation": {
/*
* Block comment
*/
"punctuation": "$"
}
}
6 changes: 5 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,21 @@ function getCwdConfigFileTest(extension) {
};
}

test('.markdownlint.jsonc in cwd is used automatically', getCwdConfigFileTest('jsonc'));

test('.markdownlint.json in cwd is used automatically', getCwdConfigFileTest('json'));

test('.markdownlint.yaml in cwd is used automatically', getCwdConfigFileTest('yaml'));

test('.markdownlint.yml in cwd is used automatically', getCwdConfigFileTest('yml'));

test('.markdownlint.jsonc in cwd is used instead of .markdownlint.json or .markdownlint.yaml or .markdownlint.yml', getCwdConfigFileTest('jsonc-json-yaml-yml'));

test('.markdownlint.json in cwd is used instead of .markdownlint.yaml or .markdownlint.yml', getCwdConfigFileTest('json-yaml-yml'));

test('.markdownlint.yaml in cwd is used instead of .markdownlint.yml', getCwdConfigFileTest('yaml-yml'));

test('.markdownlint.json with JavaScript-style comments is handled', getCwdConfigFileTest('jsonc'));
test('.markdownlint.json with JavaScript-style comments is handled', getCwdConfigFileTest('json-c'));

test('Custom rule from single file loaded', async t => {
try {
Expand Down

0 comments on commit 1ce32d6

Please sign in to comment.