Skip to content

Commit ea2b4ff

Browse files
committed
Return exitCode 2 (linting not completed) for --config with missing configPath (i.e., last parameter).
1 parent bd3bd40 commit ea2b4ff

8 files changed

+167
-1
lines changed

markdownlint-cli2.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,10 @@ const main = async (params) => {
877877
noGlobs,
878878
noRequire
879879
);
880-
if ((globPatterns.length === 0) && !nonFileContents) {
880+
if (
881+
((globPatterns.length === 0) && !nonFileContents) ||
882+
(configPath === null)
883+
) {
881884
showHelp(logMessage);
882885
return 2;
883886
}

test/markdownlint-cli2-test-cases.js

+7
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ const testCases =
156156
"cwd": "no-config"
157157
});
158158

159+
testCase({
160+
"name": "missing-argument-config-arg",
161+
"args": [ "**", "--config" ],
162+
"exitCode": 2,
163+
"cwd": "no-config"
164+
});
165+
159166
testCase({
160167
"name": "one-argument-config-arg",
161168
"args": [ "--config", "../config-files/cfg/.markdownlint-cli2.jsonc" ],

test/snapshots/markdownlint-cli2-test-exec.js.md

+52
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,58 @@ Generated by [AVA](https://avajs.dev).
214214

215215
## no-arguments-config-arg (exec)
216216

217+
> Snapshot 1
218+
219+
{
220+
exitCode: 2,
221+
formatterCodeQuality: '',
222+
formatterJson: '',
223+
formatterJunit: '',
224+
stderr: '',
225+
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
226+
https://github.com/DavidAnson/markdownlint-cli2␊
227+
228+
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
229+
230+
Glob expressions (from the globby library):␊
231+
- * matches any number of characters, but not /␊
232+
- ? matches a single character, but not /␊
233+
- ** matches any number of characters, including /␊
234+
- {} allows for a comma-separated list of "or" expressions␊
235+
- ! or # at the beginning of a pattern negate the match␊
236+
- : at the beginning identifies a literal file path␊
237+
238+
Dot-only glob:␊
239+
- The command "markdownlint-cli2 ." would lint every file in the current directory tree which is probably not intended␊
240+
- Instead, it is mapped to "markdownlint-cli2 *.{md,markdown}" which lints all Markdown files in the current directory␊
241+
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
242+
243+
Optional parameters:␊
244+
- --config specifies the path to a configuration file to define the base configuration␊
245+
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
246+
247+
Configuration via:␊
248+
- .markdownlint-cli2.jsonc␊
249+
- .markdownlint-cli2.yaml␊
250+
- .markdownlint-cli2.cjs or .markdownlint-cli2.mjs␊
251+
- .markdownlint.jsonc or .markdownlint.json␊
252+
- .markdownlint.yaml or .markdownlint.yml␊
253+
- .markdownlint.cjs or .markdownlint.mjs␊
254+
255+
Cross-platform compatibility:␊
256+
- UNIX and Windows shells expand globs according to different rules; quoting arguments is recommended␊
257+
- Some Windows shells don't handle single-quoted (') arguments well; double-quote (") is recommended␊
258+
- Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊
259+
- Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊
260+
- The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊
261+
262+
The most compatible syntax for cross-platform support:␊
263+
$ markdownlint-cli2 "**/*.md" "#node_modules"␊
264+
`,
265+
}
266+
267+
## missing-argument-config-arg (exec)
268+
217269
> Snapshot 1
218270
219271
{
Binary file not shown.

test/snapshots/markdownlint-cli2-test-fs.js.md

+52
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,58 @@ Generated by [AVA](https://avajs.dev).
5858

5959
## no-arguments-config-arg (fs)
6060

61+
> Snapshot 1
62+
63+
{
64+
exitCode: 2,
65+
formatterCodeQuality: '',
66+
formatterJson: '',
67+
formatterJunit: '',
68+
stderr: '',
69+
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
70+
https://github.com/DavidAnson/markdownlint-cli2␊
71+
72+
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
73+
74+
Glob expressions (from the globby library):␊
75+
- * matches any number of characters, but not /␊
76+
- ? matches a single character, but not /␊
77+
- ** matches any number of characters, including /␊
78+
- {} allows for a comma-separated list of "or" expressions␊
79+
- ! or # at the beginning of a pattern negate the match␊
80+
- : at the beginning identifies a literal file path␊
81+
82+
Dot-only glob:␊
83+
- The command "markdownlint-cli2 ." would lint every file in the current directory tree which is probably not intended␊
84+
- Instead, it is mapped to "markdownlint-cli2 *.{md,markdown}" which lints all Markdown files in the current directory␊
85+
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
86+
87+
Optional parameters:␊
88+
- --config specifies the path to a configuration file to define the base configuration␊
89+
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
90+
91+
Configuration via:␊
92+
- .markdownlint-cli2.jsonc␊
93+
- .markdownlint-cli2.yaml␊
94+
- .markdownlint-cli2.cjs or .markdownlint-cli2.mjs␊
95+
- .markdownlint.jsonc or .markdownlint.json␊
96+
- .markdownlint.yaml or .markdownlint.yml␊
97+
- .markdownlint.cjs or .markdownlint.mjs␊
98+
99+
Cross-platform compatibility:␊
100+
- UNIX and Windows shells expand globs according to different rules; quoting arguments is recommended␊
101+
- Some Windows shells don't handle single-quoted (') arguments well; double-quote (") is recommended␊
102+
- Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊
103+
- Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊
104+
- The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊
105+
106+
The most compatible syntax for cross-platform support:␊
107+
$ markdownlint-cli2 "**/*.md" "#node_modules"␊
108+
`,
109+
}
110+
111+
## missing-argument-config-arg (fs)
112+
61113
> Snapshot 1
62114
63115
{
27 Bytes
Binary file not shown.

test/snapshots/markdownlint-cli2-test-main.js.md

+52
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,58 @@ Generated by [AVA](https://avajs.dev).
5858

5959
## no-arguments-config-arg (main)
6060

61+
> Snapshot 1
62+
63+
{
64+
exitCode: 2,
65+
formatterCodeQuality: '',
66+
formatterJson: '',
67+
formatterJunit: '',
68+
stderr: '',
69+
stdout: `markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)␊
70+
https://github.com/DavidAnson/markdownlint-cli2␊
71+
72+
Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix]␊
73+
74+
Glob expressions (from the globby library):␊
75+
- * matches any number of characters, but not /␊
76+
- ? matches a single character, but not /␊
77+
- ** matches any number of characters, including /␊
78+
- {} allows for a comma-separated list of "or" expressions␊
79+
- ! or # at the beginning of a pattern negate the match␊
80+
- : at the beginning identifies a literal file path␊
81+
82+
Dot-only glob:␊
83+
- The command "markdownlint-cli2 ." would lint every file in the current directory tree which is probably not intended␊
84+
- Instead, it is mapped to "markdownlint-cli2 *.{md,markdown}" which lints all Markdown files in the current directory␊
85+
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead␊
86+
87+
Optional parameters:␊
88+
- --config specifies the path to a configuration file to define the base configuration␊
89+
- --fix updates files to resolve fixable issues (can be overridden in configuration)␊
90+
91+
Configuration via:␊
92+
- .markdownlint-cli2.jsonc␊
93+
- .markdownlint-cli2.yaml␊
94+
- .markdownlint-cli2.cjs or .markdownlint-cli2.mjs␊
95+
- .markdownlint.jsonc or .markdownlint.json␊
96+
- .markdownlint.yaml or .markdownlint.yml␊
97+
- .markdownlint.cjs or .markdownlint.mjs␊
98+
99+
Cross-platform compatibility:␊
100+
- UNIX and Windows shells expand globs according to different rules; quoting arguments is recommended␊
101+
- Some Windows shells don't handle single-quoted (') arguments well; double-quote (") is recommended␊
102+
- Shells that expand globs do not support negated patterns (!node_modules); quoting is required here␊
103+
- Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases␊
104+
- The path separator is forward slash (/) on all platforms; backslash (\\) is automatically converted␊
105+
106+
The most compatible syntax for cross-platform support:␊
107+
$ markdownlint-cli2 "**/*.md" "#node_modules"␊
108+
`,
109+
}
110+
111+
## missing-argument-config-arg (main)
112+
61113
> Snapshot 1
62114
63115
{
Binary file not shown.

0 commit comments

Comments
 (0)