Skip to content

Commit

Permalink
Refine previous commit for PR approval.
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Dec 18, 2023
1 parent 75611b6 commit 3f0be36
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 34 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Dot-only glob:
Optional parameters:
- --config specifies the path to a configuration file to define the base configuration
- --fix updates files to resolve fixable issues (can be overridden in configuration)
- --help writes this message to the console and exits without doing anything else
Configuration via:
- .markdownlint-cli2.jsonc
Expand Down
13 changes: 6 additions & 7 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Dot-only glob:
Optional parameters:
- --config specifies the path to a configuration file to define the base configuration
- --fix updates files to resolve fixable issues (can be overridden in configuration)
- --help writes this message to the console and exits without doing anything else
Configuration via:
- .markdownlint-cli2.jsonc
Expand All @@ -281,6 +282,7 @@ Cross-platform compatibility:
The most compatible syntax for cross-platform support:
$ markdownlint-cli2 "**/*.md" "#node_modules"`
);
return 2;
};

// Get (creating if necessary) and process a directory's info object
Expand Down Expand Up @@ -912,28 +914,26 @@ const main = async (params) => {
let fixDefault = false;
// eslint-disable-next-line unicorn/no-useless-undefined
let configPath = undefined;

let shouldShowHelp = false;
const argvFiltered = (argv || []).filter((arg) => {
if (configPath === null) {
configPath = arg;
return false;
// eslint-disable-next-line unicorn/prefer-switch
// eslint-disable-next-line unicorn/prefer-switch
} else if (arg === "--config") {
configPath = null;
return false;
} else if (arg === "--fix") {
fixDefault = true;
return false;
} else if (arg === '--help') {
} else if (arg === "--help") {
shouldShowHelp = true;
return false;
}
return true;
});
if (shouldShowHelp) {
showHelp(logMessage);
return 2;
return showHelp(logMessage);
}
// Read argv configuration file (if relevant and present)
let optionsArgv = null;
Expand Down Expand Up @@ -962,8 +962,7 @@ const main = async (params) => {
((globPatterns.length === 0) && !nonFileContents) ||
(configPath === null)
) {
showHelp(logMessage);
return 2;
return showHelp(logMessage);
}
// Include any file overrides or non-file content
const resolvedFileContents = {};
Expand Down
25 changes: 13 additions & 12 deletions test/markdownlint-cli2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const outputFormatterLengthIs = (t, length) => (options) => {
};

test("name and version", (t) => {
t.plan(2);
t.plan(3);
const packageJson = require("../package.json");
const logMessage = (msg) => {
const match = (/^(?<name>\S+)\sv(?<version>\S+)\s/u).exec(msg);
Expand All @@ -38,7 +38,8 @@ test("name and version", (t) => {
"argv": [],
logMessage,
logError
});
}).
then((exitCode) => t.is(exitCode, 2));
});

test("README files", (t) => {
Expand Down Expand Up @@ -611,26 +612,26 @@ test("--help", (t) => {
t.plan(2);
const stdouts = [];
return markdownlintCli2({
"argv": [ "--help" ],
"argv": [ "--help" ],
"logMessage": (msg) => stdouts.push(msg),
"logError": (msg) => t.fail(`message logged: ${msg}`)
})
.then((exitCode) => {
}).
then((exitCode) => {
t.is(exitCode, 2);
t.regex(stdouts.join('\n'), /Syntax: markdownlint-cli2/u);
t.regex(stdouts[0], /^markdownlint-cli2 v/u);
});
});

test("--help, using globs", (t) => {
test("--help, glob also present", (t) => {
t.plan(2);
const stdouts = [];
return markdownlintCli2({
"argv": [ "README.md", "--help" ],
return markdownlintCli2({
"argv": [ "README.md", "--help" ],
"logMessage": (msg) => stdouts.push(msg),
"logError": (msg) => t.fail(`message logged: ${msg}`)
})
.then((exitCode) => {
}).
then((exitCode) => {
t.is(exitCode, 2);
t.regex(stdouts.join('\n'), /Syntax: markdownlint-cli2/u);
t.regex(stdouts[0], /^markdownlint-cli2 v/u);
});
})

Check notice

Code scanning / CodeQL

Semicolon insertion Note test

Avoid automated semicolon insertion (97% of all statements in
the enclosing script
have an explicit semicolon).
21 changes: 14 additions & 7 deletions test/snapshots/markdownlint-cli2-test-exec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -36,6 +36,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -72,7 +73,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2-fix vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -90,6 +91,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -126,7 +128,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2-config vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -144,6 +146,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -180,7 +183,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2-config vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -198,6 +201,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -234,7 +238,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -252,6 +256,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -288,7 +293,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -306,6 +311,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -342,7 +348,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -360,6 +366,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-exec.js.snap
Binary file not shown.
12 changes: 8 additions & 4 deletions test/snapshots/markdownlint-cli2-test-fs.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -36,6 +36,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -72,7 +73,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -90,6 +91,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -126,7 +128,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -144,6 +146,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -180,7 +183,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -198,6 +201,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-fs.js.snap
Binary file not shown.
12 changes: 8 additions & 4 deletions test/snapshots/markdownlint-cli2-test-main.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -36,6 +36,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -72,7 +73,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -90,6 +91,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -126,7 +128,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -144,6 +146,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down Expand Up @@ -180,7 +183,7 @@ Generated by [AVA](https://avajs.dev).
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
https://github.com/DavidAnson/markdownlint-cli2␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]
Glob expressions (from the globby library):␊
- * matches any number of characters, but not /␊
Expand All @@ -198,6 +201,7 @@ Generated by [AVA](https://avajs.dev).
Optional parameters:␊
- --config specifies the path to a configuration file to define the base configuration␊
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
- --help writes this message to the console and exits without doing anything else␊
Configuration via:␊
- .markdownlint-cli2.jsonc␊
Expand Down
Binary file modified test/snapshots/markdownlint-cli2-test-main.js.snap
Binary file not shown.

0 comments on commit 3f0be36

Please sign in to comment.