Skip to content

Commit 74c845e

Browse files
committed
Add support for .markdownlint-cli2.yaml configuration files (fixes #5).
1 parent bb7c4dd commit 74c845e

24 files changed

+168
-7
lines changed

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Dot-only glob:
6161
6262
Configuration via:
6363
- .markdownlint-cli2.jsonc
64+
- .markdownlint-cli2.yaml
6465
- .markdownlint-cli2.js
6566
- .markdownlint.jsonc or .markdownlint.json
6667
- .markdownlint.yaml or .markdownlint.yml
@@ -159,13 +160,23 @@ $ markdownlint-cli2 "**/*.md" "#node_modules"
159160
- For example: [`.markdownlint-cli2.jsonc`][markdownlint-cli2-jsonc] with all
160161
properties set
161162

162-
### `.markdownlint-cli2.js`
163+
### `.markdownlint-cli2.yaml`
163164

164-
- The format of this file is a [CommonJS module][commonjs-module] that exports
165-
the `.markdownlint-cli2.jsonc` object described above.
165+
- The format of this file is a [YAML][yaml] object with the structure described
166+
above for `.markdownlint-cli2.jsonc`.
166167
- Other details are the same as for `.markdownlint-cli2.jsonc` described above.
167168
- If a `.markdownlint-cli2.jsonc` file is present in the same directory, it
168169
takes precedence.
170+
- For example: [`.markdownlint-cli2.yaml`][markdownlint-cli2-yaml] with all
171+
properties set
172+
173+
### `.markdownlint-cli2.js`
174+
175+
- The format of this file is a [CommonJS module][commonjs-module] that exports
176+
the object described above for `.markdownlint-cli2.jsonc`.
177+
- Other details are the same as for `.markdownlint-cli2.jsonc` described above.
178+
- If a `.markdownlint-cli2.jsonc` or `.markdownlint-cli2.yaml` file is present
179+
in the same directory, it takes precedence.
169180
- For example: [`.markdownlint-cli2.js`][markdownlint-cli2-js]
170181

171182
### `.markdownlint.jsonc` or `.markdownlint.json`
@@ -254,6 +265,7 @@ $ markdownlint-cli2 "**/*.md" "#node_modules"
254265
[markdownlint-cli2-formatter]: https://www.npmjs.com/search?q=keywords:markdownlint-cli2-formatter
255266
[markdownlint-cli2-js]: test/markdownlint-cli2-js/.markdownlint-cli2.js
256267
[markdownlint-cli2-jsonc]: test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc
268+
[markdownlint-cli2-yaml]: test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml
257269
[markdownlint-js]: test/markdownlint-js/.markdownlint.js
258270
[markdownlint-jsonc]: test/markdownlint-jsonc/.markdownlint.jsonc
259271
[markdownlint-yaml]: test/markdownlint-yaml/.markdownlint.yaml

markdownlint-cli2.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Dot-only glob:
9494
9595
Configuration via:
9696
- .markdownlint-cli2.jsonc
97+
- .markdownlint-cli2.yaml
9798
- .markdownlint-cli2.js
9899
- .markdownlint.jsonc or .markdownlint.json
99100
- .markdownlint.yaml or .markdownlint.yml
@@ -131,14 +132,20 @@ $ ${name} "**/*.md" "#node_modules"`
131132
};
132133
dirToDirInfo[dir] = dirInfo;
133134
const markdownlintCli2Jsonc = path.join(dir, ".markdownlint-cli2.jsonc");
135+
const markdownlintCli2Yaml = path.join(dir, ".markdownlint-cli2.yaml");
134136
tasks.push(
135137
fs.access(markdownlintCli2Jsonc).
136138
then(
137139
() => fs.readFile(markdownlintCli2Jsonc, utf8).then(jsoncParse),
138-
requireConfig(
139-
dir,
140-
".markdownlint-cli2.js",
141-
() => null)
140+
() => fs.access(markdownlintCli2Yaml).
141+
then(
142+
() => fs.readFile(markdownlintCli2Yaml, utf8).then(yamlParse),
143+
requireConfig(
144+
dir,
145+
".markdownlint-cli2.js",
146+
() => null
147+
)
148+
)
142149
).
143150
then((options) => {
144151
dirInfo.markdownlintOptions = options;

test/markdownlint-cli2-jsonc/.markdownlint-cli2.yaml

Whitespace-only changes.

test/markdownlint-cli2-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,28 @@ testCase({
257257
"stderrRe": /Unexpected end of JSON input/u
258258
});
259259

260+
testCase({
261+
"name": "markdownlint-cli2-yaml",
262+
"args": [ "**/*.md" ],
263+
"exitCode": 1
264+
});
265+
266+
testCase({
267+
"name": "markdownlint-cli2-yaml-example",
268+
"args": [ "**/*.md" ],
269+
"exitCode": 1,
270+
"cwd": "markdownlint-cli2-yaml-example-copy",
271+
"pre": copyDirectory,
272+
"post": deleteDirectory
273+
});
274+
275+
testCase({
276+
"name": "markdownlint-cli2-yaml-invalid",
277+
"args": [ ".*" ],
278+
"exitCode": 2,
279+
"stderrRe": /Map keys must be unique/u
280+
});
281+
260282
testCase({
261283
"name": "markdownlint-cli2-js",
262284
"args": [ "**/*.md" ],
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title-case.md:1:1 titlecase-rule Titlecase rule [Title Case: 'Expected # Heading, found # heading']
2+
viewme.md:6 MD025/single-title/single-h1 Multiple top level headings in the same document [Context: "# Description"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# An example .markdownlint-cli2.yaml file
3+
#
4+
5+
# Disable some built-in rules
6+
config:
7+
no-trailing-spaces: false
8+
no-multiple-blanks: false
9+
10+
# Include a custom rule package
11+
customRules:
12+
- markdownlint-rule-titlecase
13+
14+
# Fix any fixable errors
15+
fix: true
16+
17+
# Define a custom front matter pattern
18+
frontMatter: "<head>[^]*<\/head>"
19+
20+
# Define glob expressions to ignore
21+
ignores:
22+
- "ignore*.md"
23+
24+
# Use a plugin to recognize math
25+
markdownItPlugins:
26+
-
27+
- "@iktakahiro/markdown-it-katex"
28+
29+
# Disable inline config comments
30+
noInlineConfig: true
31+
32+
# Disable progress on stdout
33+
noProgress: true
34+
35+
# Use a specific formatter
36+
outputFormatters:
37+
-
38+
- markdownlint-cli2-formatter-default
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<head>
2+
<front>matter</front>
3+
</head>
4+
# Heading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Heading
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Katex
2+
3+
- List item
4+
5+
$1 *2* 3$
6+
7+
$$1 *2* 3$$
8+
9+
$$1
10+
+ 2
11+
+ 3$$
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# heading
2+
3+
<!-- markdownlint-disable-file titlecase-rule -->

0 commit comments

Comments
 (0)