Skip to content

Commit

Permalink
Add "showFound" configuration file option to show the list of found f…
Browse files Browse the repository at this point in the history
…iles before linting (fixes #205).
  • Loading branch information
DavidAnson committed Sep 13, 2023
1 parent 8a660ce commit 7dd9a60
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`);
}
Expand Down
5 changes: 5 additions & 0 deletions schema/markdownlint-cli2-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions test/markdownlint-cli2-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ const testCases = ({
"exitCode": 1
});

testCase({
"name": "showFound",
"args": [ "**/*.md" ],
"exitCode": 1
});

testCase({
"name": "frontMatter",
"args": [ "**/*.md" ],
Expand Down
2 changes: 1 addition & 1 deletion test/markdownlint-cli2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions test/markdownlint-cli2-yaml-example/.markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ noProgress: true
outputFormatters:
-
- markdownlint-cli2-formatter-default

# Show found files on stdout (only valid at root)
showFound: true
8 changes: 8 additions & 0 deletions test/showFound/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
// Comment
"config": {
"MD032": false,
"no-multiple-blanks": false
},
"showFound": true
}
8 changes: 8 additions & 0 deletions test/showFound/dir/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# About #

<!-- markdownlint-disable ol-prefix -->

Text text text
1. List
3. List
3. List
5 changes: 5 additions & 0 deletions test/showFound/dir/subdir/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"config": {
"first-line-heading": false
}
}
4 changes: 4 additions & 0 deletions test/showFound/dir/subdir/info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Information
Text ` code1` text `code2 ` text
<!-- markdownlint-disable-file no-space-in-code -->

6 changes: 6 additions & 0 deletions test/showFound/dir/subdir2/.markdownlint-cli2.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"config": {
"first-line-heading": false
},
"showFound": false
}
4 changes: 4 additions & 0 deletions test/showFound/dir/subdir2/info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Information
Text ` code1` text `code2 ` text
<!-- markdownlint-disable-file no-space-in-code -->

16 changes: 16 additions & 0 deletions test/showFound/viewme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Title

> Tagline

# Description

Text text text
Text text text
Text text text

## Summary

<!-- markdownlint-disable single-trailing-newline-->

Text text text
29 changes: 29 additions & 0 deletions test/snapshots/markdownlint-cli2-test-exec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-exec.js.snap
Binary file not shown.
29 changes: 29 additions & 0 deletions test/snapshots/markdownlint-cli2-test-fs.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-fs.js.snap
Binary file not shown.
29 changes: 29 additions & 0 deletions test/snapshots/markdownlint-cli2-test-main.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-main.js.snap
Binary file not shown.

0 comments on commit 7dd9a60

Please sign in to comment.