diff --git a/README.md b/README.md index 3cdeb90c..99b89448 100644 --- a/README.md +++ b/README.md @@ -320,6 +320,9 @@ of the rules within. - This top-level setting is valid **only** in the directory from which `markdownlint-cli2` is run - Search [`markdownlint-cli2-formatter` on npm][markdownlint-cli2-formatter] + - `showFound`: `Boolean` value to display the list of found files on `stdout` + - This top-level setting is valid **only** in the directory from which + `markdownlint-cli2` is run and **only** when `noProgress` has not been set - When referencing a module via the `customRules`, `markdownItPlugins`, or `outputFormatters` properties, each `String` identifier is passed to Node's [`require` function][nodejs-require] then (if that failed) its diff --git a/markdownlint-cli2.js b/markdownlint-cli2.js index b5f680a9..c8a9d82f 100755 --- a/markdownlint-cli2.js +++ b/markdownlint-cli2.js @@ -950,9 +950,15 @@ const main = async (params) => { ); // Output linting status if (showProgress) { - let fileCount = 0; - for (const dirInfo of dirInfos) { - fileCount += dirInfo.files.length; + const fileNames = dirInfos.flatMap((dirInfo) => { + const { files } = dirInfo; + return files.map((file) => pathPosix.relative(baseDir, file)); + }); + const fileCount = fileNames.length; + if (baseMarkdownlintOptions.showFound) { + fileNames.push(""); + fileNames.sort(); + logMessage(`Found:${fileNames.join("\n ")}`); } logMessage(`Linting: ${fileCount} file(s)`); } diff --git a/schema/markdownlint-cli2-config-schema.json b/schema/markdownlint-cli2-config-schema.json index 93bbea49..48e7afb4 100644 --- a/schema/markdownlint-cli2-config-schema.json +++ b/schema/markdownlint-cli2-config-schema.json @@ -103,6 +103,11 @@ ], "minItems": 1 } + }, + "showFound": { + "description": "Whether to show the list of found files on stdout (only valid at the root)", + "type": "boolean", + "default": false } }, "additionalProperties": false diff --git a/test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc b/test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc index af879ee8..350631b8 100644 --- a/test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc +++ b/test/markdownlint-cli2-jsonc-example/.markdownlint-cli2.jsonc @@ -43,5 +43,8 @@ // Use a specific formatter (only valid at root) "outputFormatters": [ [ "markdownlint-cli2-formatter-default" ] - ] + ], + + // Show found files on stdout (only valid at root) + "showFound": true } diff --git a/test/markdownlint-cli2-test-cases.js b/test/markdownlint-cli2-test-cases.js index 35cb8fd7..0be2ebd2 100644 --- a/test/markdownlint-cli2-test-cases.js +++ b/test/markdownlint-cli2-test-cases.js @@ -506,6 +506,12 @@ const testCases = ({ "exitCode": 1 }); + testCase({ + "name": "showFound", + "args": [ "**/*.md" ], + "exitCode": 1 + }); + testCase({ "name": "frontMatter", "args": [ "**/*.md" ], diff --git a/test/markdownlint-cli2-test.js b/test/markdownlint-cli2-test.js index b82d1a44..b5371ab1 100644 --- a/test/markdownlint-cli2-test.js +++ b/test/markdownlint-cli2-test.js @@ -83,7 +83,7 @@ test("validateMarkdownlintConfigSchema", async (t) => { }); test("validateMarkdownlintCli2ConfigSchema", async (t) => { - t.plan(78); + t.plan(81); const schema = require("../schema/markdownlint-cli2-config-schema.json"); const { "default": stripJsonComments } = await import("strip-json-comments"); const { globby } = await import("globby"); diff --git a/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml b/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml index be27908d..adb4ee29 100644 --- a/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml +++ b/test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml @@ -40,3 +40,6 @@ noProgress: true outputFormatters: - - markdownlint-cli2-formatter-default + +# Show found files on stdout (only valid at root) +showFound: true diff --git a/test/showFound/.markdownlint-cli2.jsonc b/test/showFound/.markdownlint-cli2.jsonc new file mode 100644 index 00000000..8011086f --- /dev/null +++ b/test/showFound/.markdownlint-cli2.jsonc @@ -0,0 +1,8 @@ +{ + // Comment + "config": { + "MD032": false, + "no-multiple-blanks": false + }, + "showFound": true +} diff --git a/test/showFound/dir/about.md b/test/showFound/dir/about.md new file mode 100644 index 00000000..a3cbb13a --- /dev/null +++ b/test/showFound/dir/about.md @@ -0,0 +1,8 @@ +# About # + + + +Text text text +1. List +3. List +3. List diff --git a/test/showFound/dir/subdir/.markdownlint-cli2.jsonc b/test/showFound/dir/subdir/.markdownlint-cli2.jsonc new file mode 100644 index 00000000..11eee665 --- /dev/null +++ b/test/showFound/dir/subdir/.markdownlint-cli2.jsonc @@ -0,0 +1,5 @@ +{ + "config": { + "first-line-heading": false + } +} diff --git a/test/showFound/dir/subdir/info.md b/test/showFound/dir/subdir/info.md new file mode 100644 index 00000000..99e35de3 --- /dev/null +++ b/test/showFound/dir/subdir/info.md @@ -0,0 +1,4 @@ +## Information +Text ` code1` text `code2 ` text + + diff --git a/test/showFound/dir/subdir2/.markdownlint-cli2.jsonc b/test/showFound/dir/subdir2/.markdownlint-cli2.jsonc new file mode 100644 index 00000000..26bd1cf4 --- /dev/null +++ b/test/showFound/dir/subdir2/.markdownlint-cli2.jsonc @@ -0,0 +1,6 @@ +{ + "config": { + "first-line-heading": false + }, + "showFound": false +} diff --git a/test/showFound/dir/subdir2/info.md b/test/showFound/dir/subdir2/info.md new file mode 100644 index 00000000..99e35de3 --- /dev/null +++ b/test/showFound/dir/subdir2/info.md @@ -0,0 +1,4 @@ +## Information +Text ` code1` text `code2 ` text + + diff --git a/test/showFound/viewme.md b/test/showFound/viewme.md new file mode 100644 index 00000000..85316a2f --- /dev/null +++ b/test/showFound/viewme.md @@ -0,0 +1,16 @@ +# Title + +> Tagline + + +# Description + +Text text text +Text text text +Text text text + +## Summary + + + +Text text text \ No newline at end of file diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.md b/test/snapshots/markdownlint-cli2-test-exec.js.md index 40202deb..d1708093 100644 --- a/test/snapshots/markdownlint-cli2-test-exec.js.md +++ b/test/snapshots/markdownlint-cli2-test-exec.js.md @@ -1473,6 +1473,35 @@ Generated by [AVA](https://avajs.dev). `, } +## showFound (exec) + +> Snapshot 1 + + { + exitCode: 1, + formatterCodeQuality: '', + formatterJson: '', + formatterJunit: '', + formatterSarif: '', + stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊ + 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"]␊ + 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"]␊ + viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊ + viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊ + viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊ + `, + stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ + Finding: **/*.md␊ + Found:␊ + dir/about.md␊ + dir/subdir/info.md␊ + dir/subdir2/info.md␊ + viewme.md␊ + Linting: 4 file(s)␊ + Summary: 6 error(s)␊ + `, + } + ## frontMatter (exec) > Snapshot 1 diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.snap b/test/snapshots/markdownlint-cli2-test-exec.js.snap index e7b10fe2..209b5415 100644 Binary files a/test/snapshots/markdownlint-cli2-test-exec.js.snap and b/test/snapshots/markdownlint-cli2-test-exec.js.snap differ diff --git a/test/snapshots/markdownlint-cli2-test-fs.js.md b/test/snapshots/markdownlint-cli2-test-fs.js.md index f0c06299..af3daf56 100644 --- a/test/snapshots/markdownlint-cli2-test-fs.js.md +++ b/test/snapshots/markdownlint-cli2-test-fs.js.md @@ -1085,6 +1085,35 @@ Generated by [AVA](https://avajs.dev). `, } +## showFound (fs) + +> Snapshot 1 + + { + exitCode: 1, + formatterCodeQuality: '', + formatterJson: '', + formatterJunit: '', + formatterSarif: '', + stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊ + 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"]␊ + 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"]␊ + viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊ + viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊ + viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊ + `, + stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ + Finding: **/*.md␊ + Found:␊ + dir/about.md␊ + dir/subdir/info.md␊ + dir/subdir2/info.md␊ + viewme.md␊ + Linting: 4 file(s)␊ + Summary: 6 error(s)␊ + `, + } + ## frontMatter (fs) > Snapshot 1 diff --git a/test/snapshots/markdownlint-cli2-test-fs.js.snap b/test/snapshots/markdownlint-cli2-test-fs.js.snap index e76dbd55..36ce6862 100644 Binary files a/test/snapshots/markdownlint-cli2-test-fs.js.snap and b/test/snapshots/markdownlint-cli2-test-fs.js.snap differ diff --git a/test/snapshots/markdownlint-cli2-test-main.js.md b/test/snapshots/markdownlint-cli2-test-main.js.md index af630067..56750e06 100644 --- a/test/snapshots/markdownlint-cli2-test-main.js.md +++ b/test/snapshots/markdownlint-cli2-test-main.js.md @@ -1311,6 +1311,35 @@ Generated by [AVA](https://avajs.dev). `, } +## showFound (main) + +> Snapshot 1 + + { + exitCode: 1, + formatterCodeQuality: '', + formatterJson: '', + formatterJunit: '', + formatterSarif: '', + stderr: `dir/about.md:1:1 MD021/no-multiple-space-closed-atx Multiple spaces inside hashes on closed atx style heading [Context: "# About #"]␊ + 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"]␊ + 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"]␊ + viewme.md:3:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]␊ + viewme.md:6 MD025/single-title/single-h1 Multiple top-level headings in the same document [Context: "# Description"]␊ + viewme.md:12:1 MD019/no-multiple-space-atx Multiple spaces after hash on atx style heading [Context: "## Summary"]␊ + `, + stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ + Finding: **/*.md␊ + Found:␊ + dir/about.md␊ + dir/subdir/info.md␊ + dir/subdir2/info.md␊ + viewme.md␊ + Linting: 4 file(s)␊ + Summary: 6 error(s)␊ + `, + } + ## frontMatter (main) > Snapshot 1 diff --git a/test/snapshots/markdownlint-cli2-test-main.js.snap b/test/snapshots/markdownlint-cli2-test-main.js.snap index 28623d7d..5d978a45 100644 Binary files a/test/snapshots/markdownlint-cli2-test-main.js.snap and b/test/snapshots/markdownlint-cli2-test-main.js.snap differ