diff --git a/README.md b/README.md index d85bdf5..a244882 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ Cross-platform compatibility: - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases - The path separator is forward slash (/) on all platforms; backslash (\) is automatically converted +- On any platform, passing the parameter "--" causes all remaining parameters to be treated literally The most compatible syntax for cross-platform support: $ markdownlint-cli2 "**/*.md" "#node_modules" diff --git a/markdownlint-cli2.js b/markdownlint-cli2.js index 79406ec..6213ae0 100755 --- a/markdownlint-cli2.js +++ b/markdownlint-cli2.js @@ -285,6 +285,7 @@ Cross-platform compatibility: - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted +- On any platform, passing the parameter "--" causes all remaining parameters to be treated literally The most compatible syntax for cross-platform support: $ markdownlint-cli2 "**/*.md" "#node_modules"` @@ -921,26 +922,28 @@ const main = async (params) => { let fixDefault = false; // eslint-disable-next-line unicorn/no-useless-undefined let configPath = undefined; + let sawDashDash = false; let shouldShowHelp = false; const argvFiltered = (argv || []).filter((arg) => { - if (configPath === null) { + if (sawDashDash) { + return true; + } else if (configPath === null) { configPath = arg; - return false; // eslint-disable-next-line unicorn/prefer-switch + } else if (arg === "--") { + sawDashDash = true; } else if (arg === "--config") { configPath = null; - return false; } else if (arg === "--fix") { fixDefault = true; - return false; } else if (arg === "--help") { shouldShowHelp = true; - return false; } else if (arg === "--no-globs") { noGlobs = true; - return false; + } else { + return true; } - return true; + return false; }); if (shouldShowHelp) { return showHelp(logMessage, true); diff --git a/test/markdownlint-cli2-test.js b/test/markdownlint-cli2-test.js index 641909e..856d5d8 100644 --- a/test/markdownlint-cli2-test.js +++ b/test/markdownlint-cli2-test.js @@ -10,6 +10,7 @@ const { "main": markdownlintCli2 } = require("../markdownlint-cli2.js"); const jsoncParse = require("../parsers/jsonc-parse.js"); const yamlParse = require("../parsers/yaml-parse.js"); const FsMock = require("./fs-mock"); +const FsVirtual = require("../webworker/fs-virtual"); const schemaIdVersionRe = /^.*v(?\d+\.\d+\.\d+).*$/u; const markdownlintConfigSchemaDefinition = require("../schema/markdownlint-config-schema.json"); @@ -658,3 +659,38 @@ test("--help, glob also present", (t) => { t.regex(stdouts[0], /^markdownlint-cli2 v/u); }); }); + +test("-- stops matching parameters per POSIX Utility Conventions 12.2 Guideline 10", async (t) => { + t.plan(17); + const files = [ + [ "/--fix", "# Title" ], + [ "/bad.md", "# Title" ], + [ "/good.md", "# Title\n" ] + ]; + const scenario = async (argv, exitCode) => t.is( + await markdownlintCli2({ + argv, + "directory": "/", + "fs": new FsVirtual(files) + }), + exitCode + ); + await scenario([], 2); + await scenario([ "--" ], 2); + await scenario([ "--fix" ], 2); + await scenario([ "--fix", "--" ], 2); + await scenario([ "--", "--fix" ], 1); + await scenario([ "bad.md" ], 1); + await scenario([ "bad.md", "--" ], 1); + await scenario([ "--", "bad.md" ], 1); + await scenario([ "good.md" ], 0); + await scenario([ "good.md", "--" ], 0); + await scenario([ "--", "good.md" ], 0); + await scenario([ "--fix", "--", "good.md" ], 0); + await scenario([ "--fix", "--", "bad.md" ], 0); + await scenario([ "good.md", "--", "--fix" ], 1); + await scenario([ "bad.md", "--", "--fix" ], 1); + await scenario([ "--", "--" ], 0); + files.push([ "/--", "# Title" ]); + await scenario([ "--", "--" ], 1); +}); diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.md b/test/snapshots/markdownlint-cli2-test-exec.js.md index 491042f..a4ba652 100644 --- a/test/snapshots/markdownlint-cli2-test-exec.js.md +++ b/test/snapshots/markdownlint-cli2-test-exec.js.md @@ -54,6 +54,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -110,6 +111,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -166,6 +168,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -222,6 +225,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -734,6 +738,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ diff --git a/test/snapshots/markdownlint-cli2-test-exec.js.snap b/test/snapshots/markdownlint-cli2-test-exec.js.snap index 435d4b9..e3deada 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 de07dcb..671c6f8 100644 --- a/test/snapshots/markdownlint-cli2-test-fs.js.md +++ b/test/snapshots/markdownlint-cli2-test-fs.js.md @@ -54,6 +54,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -110,6 +111,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -166,6 +168,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -222,6 +225,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -734,6 +738,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ diff --git a/test/snapshots/markdownlint-cli2-test-fs.js.snap b/test/snapshots/markdownlint-cli2-test-fs.js.snap index 3835f5d..a663aae 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 db47051..c0338dd 100644 --- a/test/snapshots/markdownlint-cli2-test-main.js.md +++ b/test/snapshots/markdownlint-cli2-test-main.js.md @@ -54,6 +54,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -110,6 +111,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -166,6 +168,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -222,6 +225,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ @@ -734,6 +738,7 @@ Generated by [AVA](https://avajs.dev). - Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊ - Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊ - The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊ + - On any platform, passing the parameter "--" causes all remaining parameters to be treated literally␊ ␊ The most compatible syntax for cross-platform support:␊ $ markdownlint-cli2 "**/*.md" "#node_modules"␊ diff --git a/test/snapshots/markdownlint-cli2-test-main.js.snap b/test/snapshots/markdownlint-cli2-test-main.js.snap index 95188b0..9ebad4d 100644 Binary files a/test/snapshots/markdownlint-cli2-test-main.js.snap and b/test/snapshots/markdownlint-cli2-test-main.js.snap differ diff --git a/webworker/fs-virtual.js b/webworker/fs-virtual.js index b40c0fe..e84d8d1 100644 --- a/webworker/fs-virtual.js +++ b/webworker/fs-virtual.js @@ -2,6 +2,8 @@ "use strict"; +/* c8 ignore start */ + const dirent = (path, directory) => { const name = path.replace(/^.*\//u, ""); return { @@ -16,7 +18,6 @@ const dirent = (path, directory) => { }; }; -// eslint-disable-next-line no-unused-vars class FsVirtual { constructor(files) { @@ -86,3 +87,9 @@ class FsVirtual { }; } } + +/* c8 ignore stop */ + +if (typeof module !== "undefined") { + module.exports = FsVirtual; +}