Skip to content

Commit 7dd9a60

Browse files
committed
Add "showFound" configuration file option to show the list of found files before linting (fixes #205).
1 parent 8a660ce commit 7dd9a60

20 files changed

+169
-5
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ of the rules within.
320320
- This top-level setting is valid **only** in the directory from which
321321
`markdownlint-cli2` is run
322322
- Search [`markdownlint-cli2-formatter` on npm][markdownlint-cli2-formatter]
323+
- `showFound`: `Boolean` value to display the list of found files on `stdout`
324+
- This top-level setting is valid **only** in the directory from which
325+
`markdownlint-cli2` is run and **only** when `noProgress` has not been set
323326
- When referencing a module via the `customRules`, `markdownItPlugins`, or
324327
`outputFormatters` properties, each `String` identifier is passed to Node's
325328
[`require` function][nodejs-require] then (if that failed) its

markdownlint-cli2.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -950,9 +950,15 @@ const main = async (params) => {
950950
);
951951
// Output linting status
952952
if (showProgress) {
953-
let fileCount = 0;
954-
for (const dirInfo of dirInfos) {
955-
fileCount += dirInfo.files.length;
953+
const fileNames = dirInfos.flatMap((dirInfo) => {
954+
const { files } = dirInfo;
955+
return files.map((file) => pathPosix.relative(baseDir, file));
956+
});
957+
const fileCount = fileNames.length;
958+
if (baseMarkdownlintOptions.showFound) {
959+
fileNames.push("");
960+
fileNames.sort();
961+
logMessage(`Found:${fileNames.join("\n ")}`);
956962
}
957963
logMessage(`Linting: ${fileCount} file(s)`);
958964
}

schema/markdownlint-cli2-config-schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@
103103
],
104104
"minItems": 1
105105
}
106+
},
107+
"showFound": {
108+
"description": "Whether to show the list of found files on stdout (only valid at the root)",
109+
"type": "boolean",
110+
"default": false
106111
}
107112
},
108113
"additionalProperties": false

test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
// Use a specific formatter (only valid at root)
4444
"outputFormatters": [
4545
[ "markdownlint-cli2-formatter-default" ]
46-
]
46+
],
47+
48+
// Show found files on stdout (only valid at root)
49+
"showFound": true
4750
}

test/markdownlint-cli2-test-cases.js

+6
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,12 @@ const testCases = ({
506506
"exitCode": 1
507507
});
508508

509+
testCase({
510+
"name": "showFound",
511+
"args": [ "**/*.md" ],
512+
"exitCode": 1
513+
});
514+
509515
testCase({
510516
"name": "frontMatter",
511517
"args": [ "**/*.md" ],

test/markdownlint-cli2-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ test("validateMarkdownlintConfigSchema", async (t) => {
8383
});
8484

8585
test("validateMarkdownlintCli2ConfigSchema", async (t) => {
86-
t.plan(78);
86+
t.plan(81);
8787
const schema = require("../schema/markdownlint-cli2-config-schema.json");
8888
const { "default": stripJsonComments } = await import("strip-json-comments");
8989
const { globby } = await import("globby");

test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ noProgress: true
4040
outputFormatters:
4141
-
4242
- markdownlint-cli2-formatter-default
43+
44+
# Show found files on stdout (only valid at root)
45+
showFound: true
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// Comment
3+
"config": {
4+
"MD032": false,
5+
"no-multiple-blanks": false
6+
},
7+
"showFound": true
8+
}

test/showFound/dir/about.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# About #
2+
3+
<!-- markdownlint-disable ol-prefix -->
4+
5+
Text text text
6+
1. List
7+
3. List
8+
3. List
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"config": {
3+
"first-line-heading": false
4+
}
5+
}

test/showFound/dir/subdir/info.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Information
2+
Text ` code1` text `code2 ` text
3+
<!-- markdownlint-disable-file no-space-in-code -->
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"config": {
3+
"first-line-heading": false
4+
},
5+
"showFound": false
6+
}

test/showFound/dir/subdir2/info.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Information
2+
Text ` code1` text `code2 ` text
3+
<!-- markdownlint-disable-file no-space-in-code -->
4+

test/showFound/viewme.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Title
2+
3+
> Tagline
4+
5+
6+
# Description
7+
8+
Text text text
9+
Text text text
10+
Text text text
11+
12+
## Summary
13+
14+
<!-- markdownlint-disable single-trailing-newline-->
15+
16+
Text text text

test/snapshots/markdownlint-cli2-test-exec.js.md

+29
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,35 @@ Generated by [AVA](https://avajs.dev).
14731473
`,
14741474
}
14751475

1476+
## showFound (exec)
1477+
1478+
> Snapshot 1
1479+
1480+
{
1481+
exitCode: 1,
1482+
formatterCodeQuality: '',
1483+
formatterJson: '',
1484+
formatterJunit: '',
1485+
formatterSarif: '',
1486+
stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊
1487+
dir/subdir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
1488+
dir/subdir2/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
1489+
viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊
1490+
viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊
1491+
viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊
1492+
`,
1493+
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
1494+
Finding: **/*.md␊
1495+
Found:␊
1496+
dir/about.md␊
1497+
dir/subdir/info.md␊
1498+
dir/subdir2/info.md␊
1499+
viewme.md␊
1500+
Linting: 4 file(s)␊
1501+
Summary: 6 error(s)␊
1502+
`,
1503+
}
1504+
14761505
## frontMatter (exec)
14771506

14781507
> Snapshot 1
Binary file not shown.

test/snapshots/markdownlint-cli2-test-fs.js.md

+29
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,35 @@ Generated by [AVA](https://avajs.dev).
10851085
`,
10861086
}
10871087

1088+
## showFound (fs)
1089+
1090+
> Snapshot 1
1091+
1092+
{
1093+
exitCode: 1,
1094+
formatterCodeQuality: '',
1095+
formatterJson: '',
1096+
formatterJunit: '',
1097+
formatterSarif: '',
1098+
stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊
1099+
dir/subdir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
1100+
dir/subdir2/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
1101+
viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊
1102+
viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊
1103+
viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊
1104+
`,
1105+
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
1106+
Finding: **/*.md␊
1107+
Found:␊
1108+
dir/about.md␊
1109+
dir/subdir/info.md␊
1110+
dir/subdir2/info.md␊
1111+
viewme.md␊
1112+
Linting: 4 file(s)␊
1113+
Summary: 6 error(s)␊
1114+
`,
1115+
}
1116+
10881117
## frontMatter (fs)
10891118

10901119
> Snapshot 1
61 Bytes
Binary file not shown.

test/snapshots/markdownlint-cli2-test-main.js.md

+29
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,35 @@ Generated by [AVA](https://avajs.dev).
13111311
`,
13121312
}
13131313

1314+
## showFound (main)
1315+
1316+
> Snapshot 1
1317+
1318+
{
1319+
exitCode: 1,
1320+
formatterCodeQuality: '',
1321+
formatterJson: '',
1322+
formatterJunit: '',
1323+
formatterSarif: '',
1324+
stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊
1325+
dir/subdir/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
1326+
dir/subdir2/info.md:1 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Information"]␊
1327+
viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊
1328+
viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊
1329+
viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊
1330+
`,
1331+
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
1332+
Finding: **/*.md␊
1333+
Found:␊
1334+
dir/about.md␊
1335+
dir/subdir/info.md␊
1336+
dir/subdir2/info.md␊
1337+
viewme.md␊
1338+
Linting: 4 file(s)␊
1339+
Summary: 6 error(s)␊
1340+
`,
1341+
}
1342+
13141343
## frontMatter (main)
13151344

13161345
> Snapshot 1
Binary file not shown.

0 commit comments

Comments
 (0)