Skip to content

Commit 226eb98

Browse files
committed
Inherited config from empty directories should not be ignored, resolve paths relative to original directory.
1 parent 2071de0 commit 226eb98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+294
-9
lines changed

markdownlint-cli2.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,19 @@ const createDirInfos = async (globPatterns, dirToDirInfo) => {
257257
);
258258
for (const dir of dirs) {
259259
const dirInfo = dirToDirInfo[dir];
260-
if ((dirInfo.files.length === 0) || noConfigDirInfo(dirInfo)) {
260+
if (noConfigDirInfo(dirInfo)) {
261261
if (dirInfo.parent) {
262262
appendToArray(dirInfo.parent.files, dirInfo.files);
263263
}
264264
dirToDirInfo[dir] = null;
265265
} else {
266+
const { markdownlintOptions } = dirInfo;
267+
if (markdownlintOptions) {
268+
markdownlintOptions.customRules =
269+
requireIds(dir, markdownlintOptions.customRules || []);
270+
markdownlintOptions.markdownItPlugins =
271+
requireIdsAndParams(dir, markdownlintOptions.markdownItPlugins || []);
272+
}
266273
dirInfos.push(dirInfo);
267274
}
268275
}
@@ -273,9 +280,6 @@ const createDirInfos = async (globPatterns, dirToDirInfo) => {
273280
}
274281

275282
// Verify dirInfos is simplified
276-
// if (dirInfos.filter((di) => !di.files.length).length > 0) {
277-
// throw new Error("Empty files");
278-
// }
279283
// if (dirInfos.filter(
280284
// (di) => di.parent && !dirInfos.includes(di.parent)).length > 0
281285
// ) {
@@ -330,13 +334,12 @@ const lintFiles = async (dirInfos) => {
330334
const options = {
331335
"files": filteredFiles,
332336
"config": markdownlintConfig || markdownlintOptions.config,
333-
"customRules": requireIds(dir, markdownlintOptions.customRules || []),
337+
"customRules": markdownlintOptions.customRules,
334338
"frontMatter": markdownlintOptions.frontMatter
335339
? new RegExp(markdownlintOptions.frontMatter, "u")
336340
: undefined,
337341
"handleRuleFailures": true,
338-
"markdownItPlugins":
339-
requireIdsAndParams(dir, markdownlintOptions.markdownItPlugins || []),
342+
"markdownItPlugins": markdownlintOptions.markdownItPlugins,
340343
"noInlineConfig": Boolean(markdownlintOptions.noInlineConfig),
341344
"resultVersion": 3
342345
};

test/append-to-array-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const checkArray =
1818
(array, maximum) => ((array.length === (maximum + 1)) &&
1919
array.every((v, i) => v === i));
2020

21+
// @ts-ignore
2122
test("empty source and destination", (t) => {
2223
t.plan(1);
2324
const destination = [];
@@ -26,6 +27,7 @@ test("empty source and destination", (t) => {
2627
t.deepEqual(destination, []);
2728
});
2829

30+
// @ts-ignore
2931
test("empty source", (t) => {
3032
t.plan(1);
3133
const destination = makeArray(0, 3);
@@ -34,6 +36,7 @@ test("empty source", (t) => {
3436
t.true(checkArray(destination, 3));
3537
});
3638

39+
// @ts-ignore
3740
test("empty destination", (t) => {
3841
t.plan(1);
3942
const destination = [];
@@ -42,6 +45,7 @@ test("empty destination", (t) => {
4245
t.true(checkArray(destination, 2));
4346
});
4447

48+
// @ts-ignore
4549
test("small source and small destination", (t) => {
4650
t.plan(1);
4751
const destination = makeArray(0, 4);
@@ -50,6 +54,7 @@ test("small source and small destination", (t) => {
5054
t.true(checkArray(destination, 5));
5155
});
5256

57+
// @ts-ignore
5358
test("small source and large destination", (t) => {
5459
t.plan(1);
5560
const destination = makeArray(0, 1000000);
@@ -58,6 +63,7 @@ test("small source and large destination", (t) => {
5863
t.true(checkArray(destination, 1000003));
5964
});
6065

66+
// @ts-ignore
6167
test("large source and small destination", (t) => {
6268
t.plan(1);
6369
const destination = makeArray(0, 3);
@@ -66,6 +72,7 @@ test("large source and small destination", (t) => {
6672
t.true(checkArray(destination, 1000000));
6773
});
6874

75+
// @ts-ignore
6976
test("large source and large destination", (t) => {
7077
t.plan(1);
7178
const destination = makeArray(0, 999999);
@@ -74,6 +81,7 @@ test("large source and large destination", (t) => {
7481
t.true(checkArray(destination, 2000000));
7582
});
7683

84+
// @ts-ignore
7785
test("sliceSize", (t) => {
7886
t.plan(1);
7987
const destination = [];
@@ -82,6 +90,7 @@ test("sliceSize", (t) => {
8290
t.true(checkArray(destination, sliceSize - 1));
8391
});
8492

93+
// @ts-ignore
8594
test("sliceSize - 1", (t) => {
8695
t.plan(1);
8796
const destination = [];
@@ -90,6 +99,7 @@ test("sliceSize - 1", (t) => {
9099
t.true(checkArray(destination, sliceSize - 2));
91100
});
92101

102+
// @ts-ignore
93103
test("sliceSize + 1", (t) => {
94104
t.plan(1);
95105
const destination = [];

test/customRules-missing.stdout

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
Finding: .*
2-
Linting: 1 file(s)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
Finding: .*
2-
Linting: 1 file(s)

test/markdownlint-cli2-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const empty = () => "";
1616

1717
const testCase = (options) => {
1818
const { name, args, exitCode, cwd, stderrRe, pre, post } = options;
19+
// @ts-ignore
1920
test(name, (t) => {
2021
t.plan(5);
2122
return Promise.all([
@@ -440,6 +441,13 @@ testCase({
440441
"exitCode": 1
441442
});
442443

444+
testCase({
445+
"name": "nested-options-config",
446+
"args": [ "**/*.md" ],
447+
"exitCode": 1
448+
});
449+
450+
// @ts-ignore
443451
test("READMEs", (t) => {
444452
// test.plan(1);
445453
const markdownlintCli2 = require("../markdownlint-cli2.js");

test/nested-options-config.stderr

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
config-options-disjoint-empty/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
2+
config-options-disjoint-empty/dir/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
3+
config-options-disjoint-empty/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
4+
config-options-disjoint-empty/dir/dir/dir/info.md:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "` code1`"]
5+
config-options-disjoint-empty/dir/dir/dir/info.md:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "`code2 `"]
6+
config-options-disjoint-empty/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
7+
config-options-disjoint-empty/dir/dir/info.md:1 first-line Rule that reports an error for the first line
8+
config-options-disjoint-empty/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
9+
config-options-disjoint-empty/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
10+
config-options-disjoint-empty/dir/dir/info.md:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "` code1`"]
11+
config-options-disjoint-empty/dir/dir/info.md:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "`code2 `"]
12+
config-options-disjoint-empty/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
13+
config-options-disjoint/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
14+
config-options-disjoint/dir/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
15+
config-options-disjoint/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
16+
config-options-disjoint/dir/dir/dir/info.md:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "` code1`"]
17+
config-options-disjoint/dir/dir/dir/info.md:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "`code2 `"]
18+
config-options-disjoint/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
19+
config-options-disjoint/dir/dir/info.md:1 first-line Rule that reports an error for the first line
20+
config-options-disjoint/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
21+
config-options-disjoint/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
22+
config-options-disjoint/dir/dir/info.md:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "` code1`"]
23+
config-options-disjoint/dir/dir/info.md:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "`code2 `"]
24+
config-options-disjoint/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
25+
config-options-disjoint/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
26+
config-options-disjoint/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
27+
config-options-disjoint/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
28+
config-options-disjoint/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
29+
config-options-overlap-empty/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
30+
config-options-overlap-empty/dir/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
31+
config-options-overlap-empty/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
32+
config-options-overlap-empty/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
33+
config-options-overlap-empty/dir/dir/info.md:1 first-line Rule that reports an error for the first line
34+
config-options-overlap-empty/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
35+
config-options-overlap-empty/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
36+
config-options-overlap-empty/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
37+
config-options-overlap/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
38+
config-options-overlap/dir/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
39+
config-options-overlap/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
40+
config-options-overlap/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
41+
config-options-overlap/dir/dir/info.md:1 first-line Rule that reports an error for the first line
42+
config-options-overlap/dir/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
43+
config-options-overlap/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
44+
config-options-overlap/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
45+
config-options-overlap/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
46+
config-options-overlap/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
47+
config-options-overlap/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
48+
config-options-overlap/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
49+
options-config-disjoint-empty/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
50+
options-config-disjoint-empty/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
51+
options-config-disjoint-empty/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
52+
options-config-disjoint-empty/dir/dir/info.md:1 first-line Rule that reports an error for the first line
53+
options-config-disjoint-empty/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
54+
options-config-disjoint-empty/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
55+
options-config-disjoint/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
56+
options-config-disjoint/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
57+
options-config-disjoint/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
58+
options-config-disjoint/dir/dir/info.md:1 first-line Rule that reports an error for the first line
59+
options-config-disjoint/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
60+
options-config-disjoint/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
61+
options-config-disjoint/dir/info.md:1 first-line Rule that reports an error for the first line
62+
options-config-disjoint/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
63+
options-config-disjoint/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
64+
options-config-disjoint/dir/info.md:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "` code1`"]
65+
options-config-disjoint/dir/info.md:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "`code2 `"]
66+
options-config-disjoint/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
67+
options-config-disjoint/info.md:1 first-line Rule that reports an error for the first line
68+
options-config-disjoint/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
69+
options-config-disjoint/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
70+
options-config-disjoint/info.md:2:6 MD038/no-space-in-code Spaces inside code span elements [Context: "` code1`"]
71+
options-config-disjoint/info.md:2:20 MD038/no-space-in-code Spaces inside code span elements [Context: "`code2 `"]
72+
options-config-disjoint/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
73+
options-config-overlap-empty/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
74+
options-config-overlap-empty/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
75+
options-config-overlap-empty/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
76+
options-config-overlap-empty/dir/dir/info.md:1 first-line Rule that reports an error for the first line
77+
options-config-overlap-empty/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
78+
options-config-overlap-empty/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
79+
options-config-overlap/dir/dir/dir/info.md:1 first-line Rule that reports an error for the first line
80+
options-config-overlap/dir/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
81+
options-config-overlap/dir/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
82+
options-config-overlap/dir/dir/info.md:1 first-line Rule that reports an error for the first line
83+
options-config-overlap/dir/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
84+
options-config-overlap/dir/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
85+
options-config-overlap/dir/info.md:1 first-line Rule that reports an error for the first line
86+
options-config-overlap/dir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
87+
options-config-overlap/dir/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
88+
options-config-overlap/dir/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]
89+
options-config-overlap/info.md:1 first-line Rule that reports an error for the first line
90+
options-config-overlap/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]
91+
options-config-overlap/info.md:1 MD041/first-line-heading/first-line-h1 First line in file should be a top level heading [Context: "## Information"]
92+
options-config-overlap/info.md:4 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]

test/nested-options-config.stdout

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Finding: **/*.md
2+
Linting: 24 file(s)
3+
Summary: 92 error(s)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"blanks-around-headings": false,
3+
"no-space-in-code": false
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"customRules": [
3+
"../../../first-line.js"
4+
]
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Information
2+
Text ` code1` text `code2 ` text
3+

0 commit comments

Comments
 (0)