diff --git a/.gitignore b/.gitignore index 3469a76f..40e89dca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ coverage node_modules npm-debug.log !test/customRules/node_modules +!test/outputFormatters-module/node_modules webworker/markdownlint-cli2-webworker.js diff --git a/test/markdownlint-cli2-test-cases.js b/test/markdownlint-cli2-test-cases.js index 0be2ebd2..5f1a093b 100644 --- a/test/markdownlint-cli2-test-cases.js +++ b/test/markdownlint-cli2-test-cases.js @@ -962,6 +962,13 @@ const testCases = ({ "usesRequire": true }); + testCase({ + "name": "outputFormatters-module", + "args": [ "**/*.md" ], + "exitCode": 1, + "usesRequire": true + }); + testCase({ "name": "outputFormatters-missing", "args": [ ".*" ], diff --git a/test/markdownlint-cli2-test.js b/test/markdownlint-cli2-test.js index 9c81b0b8..934f9ebe 100644 --- a/test/markdownlint-cli2-test.js +++ b/test/markdownlint-cli2-test.js @@ -111,7 +111,7 @@ test("validateMarkdownlintConfigSchema", async (t) => { }); test("validateMarkdownlintCli2ConfigSchema", async (t) => { - t.plan(82); + t.plan(83); // Validate schema const { addSchema, validate } = diff --git a/test/outputFormatters-module/.markdownlint-cli2.jsonc b/test/outputFormatters-module/.markdownlint-cli2.jsonc new file mode 100644 index 00000000..f64f929a --- /dev/null +++ b/test/outputFormatters-module/.markdownlint-cli2.jsonc @@ -0,0 +1,6 @@ +{ + "outputFormatters": [ + [ "output-formatter-sample-commonjs" ], + [ "./node_modules/output-formatter-sample-module/sample-formatter.mjs" ] + ] +} diff --git a/test/outputFormatters-module/node_modules/output-formatter-sample-commonjs/package.json b/test/outputFormatters-module/node_modules/output-formatter-sample-commonjs/package.json new file mode 100644 index 00000000..07e21a2e --- /dev/null +++ b/test/outputFormatters-module/node_modules/output-formatter-sample-commonjs/package.json @@ -0,0 +1,14 @@ +{ + "name": "output-formatter-sample-commonjs", + "version": "0.0.1", + "description": "Package for markdownlint output formatter sample (commonjs)", + "main": "sample-formatter.cjs", + "type": "commonjs", + "author": "David Anson (https://dlaa.me/)", + "homepage": "https://github.com/DavidAnson/markdownlint", + "license": "MIT", + "keywords": [ + "markdownlint-cli2-formatter" + ], + "private": true +} diff --git a/test/outputFormatters-module/node_modules/output-formatter-sample-commonjs/sample-formatter.cjs b/test/outputFormatters-module/node_modules/output-formatter-sample-commonjs/sample-formatter.cjs new file mode 100644 index 00000000..52bceed5 --- /dev/null +++ b/test/outputFormatters-module/node_modules/output-formatter-sample-commonjs/sample-formatter.cjs @@ -0,0 +1,11 @@ +// @ts-check + +"use strict"; + +module.exports = (options, params) => { + const { logError, results } = options; + for (const result of results) { + const { fileName, lineNumber, ruleNames } = result; + logError(`cjs: ${fileName} ${lineNumber} ${ruleNames.join("/")}`); + } +}; diff --git a/test/outputFormatters-module/node_modules/output-formatter-sample-module/package.json b/test/outputFormatters-module/node_modules/output-formatter-sample-module/package.json new file mode 100644 index 00000000..7289f975 --- /dev/null +++ b/test/outputFormatters-module/node_modules/output-formatter-sample-module/package.json @@ -0,0 +1,14 @@ +{ + "name": "output-formatter-sample-module", + "version": "0.0.1", + "description": "Package for markdownlint output formatter sample (module)", + "main": "sample-formatter.mjs", + "type": "module", + "author": "David Anson (https://dlaa.me/)", + "homepage": "https://github.com/DavidAnson/markdownlint", + "license": "MIT", + "keywords": [ + "markdownlint-cli2-formatter" + ], + "private": true +} diff --git a/test/outputFormatters-module/node_modules/output-formatter-sample-module/sample-formatter.mjs b/test/outputFormatters-module/node_modules/output-formatter-sample-module/sample-formatter.mjs new file mode 100644 index 00000000..567f2a79 --- /dev/null +++ b/test/outputFormatters-module/node_modules/output-formatter-sample-module/sample-formatter.mjs @@ -0,0 +1,9 @@ +// @ts-check + +export default (options, params) => { + const { logError, results } = options; + for (const result of results) { + const { fileName, lineNumber, ruleNames } = result; + logError(`mjs: ${fileName} ${lineNumber} ${ruleNames.join("/")}`); + } +}; diff --git a/test/outputFormatters-module/viewme.md b/test/outputFormatters-module/viewme.md new file mode 100644 index 00000000..d60ebf5a --- /dev/null +++ b/test/outputFormatters-module/viewme.md @@ -0,0 +1,14 @@ +# 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 d1708093..288fc94d 100644 --- a/test/snapshots/markdownlint-cli2-test-exec.js.md +++ b/test/snapshots/markdownlint-cli2-test-exec.js.md @@ -6578,6 +6578,34 @@ Generated by [AVA](https://avajs.dev). `, } +## outputFormatters-module (exec) + +> Snapshot 1 + + { + exitCode: 1, + formatterCodeQuality: '', + formatterJson: '', + formatterJunit: '', + formatterSarif: '', + stderr: `cjs: viewme.md 3 MD009/no-trailing-spaces␊ + cjs: viewme.md 5 MD012/no-multiple-blanks␊ + cjs: viewme.md 6 MD025/single-title/single-h1␊ + cjs: viewme.md 12 MD019/no-multiple-space-atx␊ + cjs: viewme.md 14 MD047/single-trailing-newline␊ + mjs: viewme.md 3 MD009/no-trailing-spaces␊ + mjs: viewme.md 5 MD012/no-multiple-blanks␊ + mjs: viewme.md 6 MD025/single-title/single-h1␊ + mjs: viewme.md 12 MD019/no-multiple-space-atx␊ + mjs: viewme.md 14 MD047/single-trailing-newline␊ + `, + stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ + Finding: **/*.md␊ + Linting: 1 file(s)␊ + Summary: 5 error(s)␊ + `, + } + ## outputFormatters-missing (exec) > Snapshot 1 diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.snap b/test/snapshots/markdownlint-cli2-test-exec.js.snap index 209b5415..358d4c6d 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-main.js.md b/test/snapshots/markdownlint-cli2-test-main.js.md index 56750e06..6e248b1f 100644 --- a/test/snapshots/markdownlint-cli2-test-main.js.md +++ b/test/snapshots/markdownlint-cli2-test-main.js.md @@ -4525,6 +4525,34 @@ Generated by [AVA](https://avajs.dev). `, } +## outputFormatters-module (main) + +> Snapshot 1 + + { + exitCode: 1, + formatterCodeQuality: '', + formatterJson: '', + formatterJunit: '', + formatterSarif: '', + stderr: `cjs: viewme.md 3 MD009/no-trailing-spaces␊ + cjs: viewme.md 5 MD012/no-multiple-blanks␊ + cjs: viewme.md 6 MD025/single-title/single-h1␊ + cjs: viewme.md 12 MD019/no-multiple-space-atx␊ + cjs: viewme.md 14 MD047/single-trailing-newline␊ + mjs: viewme.md 3 MD009/no-trailing-spaces␊ + mjs: viewme.md 5 MD012/no-multiple-blanks␊ + mjs: viewme.md 6 MD025/single-title/single-h1␊ + mjs: viewme.md 12 MD019/no-multiple-space-atx␊ + mjs: viewme.md 14 MD047/single-trailing-newline␊ + `, + stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊ + Finding: **/*.md␊ + Linting: 1 file(s)␊ + Summary: 5 error(s)␊ + `, + } + ## outputFormatters-missing (main) > Snapshot 1 diff --git a/test/snapshots/markdownlint-cli2-test-main.js.snap b/test/snapshots/markdownlint-cli2-test-main.js.snap index 5d978a45..83a626f6 100644 Binary files a/test/snapshots/markdownlint-cli2-test-main.js.snap and b/test/snapshots/markdownlint-cli2-test-main.js.snap differ