Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAnson committed Feb 4, 2024
1 parent 3eb9907 commit 5b71d6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
12 changes: 6 additions & 6 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const getParsers = () => require("./parsers/parsers.js");
// Negate a glob
const negateGlob = (glob) => `!${glob}`;

// ...
const utu = (file, error) => {
// Throws a meaningful exception for an unusable configuration file
const throwForConfigurationFile = (file, error) => {
throw new Error(
`Unable to use configuration file "${file}"; ${error.message}`,
`Unable to use configuration file '${file}'; ${error?.message}`,
// @ts-ignore
{ "cause": error }
);
Expand Down Expand Up @@ -193,11 +193,11 @@ const readOptionsOrConfig = async (configPath, fs, noRequire) => {
} else {
throw new Error(
"File name should be (or end with) one of the supported types " +
"(e.g., \".markdownlint.json\" or \"example.markdownlint-cli2.jsonc\")."
"(e.g., '.markdownlint.json' or 'example.markdownlint-cli2.jsonc')."
);
}
} catch (error) {
utu(configPath, error);
throwForConfigurationFile(configPath, error);
}
if (options) {
if (options.config) {
Expand Down Expand Up @@ -373,7 +373,7 @@ const getAndProcessDirInfo = (
});
})
.catch((error) => {
utu(file, error);
throwForConfigurationFile(file, error);
})
);

Expand Down
22 changes: 11 additions & 11 deletions test/markdownlint-cli2-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,14 @@ const testCases = ({
"name": "markdownlint-json-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /\.markdownlint\.json'.*Unable to parse JSONC content/u
"stderrRe": /'[^']*\.markdownlint\.json'.*Unable to parse JSONC content/u
});

testCase({
"name": "markdownlint-yaml-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /\.markdownlint\.yaml'.*Map keys must be unique/u
"stderrRe": /'[^']*\.markdownlint\.yaml'.*Map keys must be unique/u
});

testCase({
Expand Down Expand Up @@ -388,7 +388,7 @@ const testCases = ({
"name": "markdownlint-cli2-jsonc-mismatch",
"args": [ "viewme.md" ],
"exitCode": 2,
"stderrRe": /\.markdownlint-cli2\.jsonc".*Unable to parse JSONC content/u
"stderrRe": /'[^']*\.markdownlint-cli2\.jsonc'.*Unable to parse JSONC content/u
});

testCase({
Expand All @@ -415,7 +415,7 @@ const testCases = ({
"name": "markdownlint-cli2-jsonc-mismatch-config",
"args": [ "--config", "../markdownlint-cli2-jsonc-mismatch/.markdownlint-cli2.jsonc", "viewme.md" ],
"exitCode": 2,
"stderrRe": /\.markdownlint-cli2\.jsonc".*Unable to parse JSONC content/u,
"stderrRe": /'[^']*\.markdownlint-cli2\.jsonc'.*Unable to parse JSONC content/u,
"cwd": "no-config",
});

Expand Down Expand Up @@ -446,7 +446,7 @@ const testCases = ({
"name": "markdownlint-cli2-jsonc-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /\.markdownlint-cli2\.jsonc".*Unable to parse JSONC content/u
"stderrRe": /'[^']*\.markdownlint-cli2\.jsonc'.*Unable to parse JSONC content/u
});

testCase({
Expand All @@ -469,7 +469,7 @@ const testCases = ({
"name": "markdownlint-cli2-yaml-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /\.markdownlint-cli2\.yaml".*Map keys must be unique/u
"stderrRe": /'[^']*\.markdownlint-cli2\.yaml'.*Map keys must be unique/u
});

testCase({
Expand All @@ -490,15 +490,15 @@ const testCases = ({
"name": "markdownlint-cli2-cjs-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /\.markdownlint-cli2\.cjs".*Unable to require or import module '/u,
"stderrRe": /'[^']*\.markdownlint-cli2\.cjs'.*Unable to require or import module '/u,
"usesRequire": true
});

testCase({
"name": "markdownlint-cli2-mjs-invalid",
"args": [ ".*" ],
"exitCode": 2,
"stderrRe": /\.markdownlint-cli2\.mjs".*Unable to require or import module '/u,
"stderrRe": /'[^']*\.markdownlint-cli2\.mjs'.*Unable to require or import module '/u,
"usesRequire": true
});

Expand Down Expand Up @@ -682,7 +682,7 @@ const testCases = ({
"name": `config-files-${invalidConfigFile}-invalid-arg`,
"args": [ "--config", `cfg/${invalidConfigFile}`, "**/*.md" ],
"exitCode": 2,
"stderrRe": new RegExp(`${invalidConfigFile.replace(".", "\\.")}".*${stderrRe}`, "u"),
"stderrRe": new RegExp(`'[^']*${invalidConfigFile.replace(".", "\\.")}'.*${stderrRe}`, "u"),
"cwd": "config-files",
usesRequire
});
Expand All @@ -709,7 +709,7 @@ const testCases = ({
"args": [ "--config", "cfg/unrecognized.jsonc", "**/*.md" ],
"exitCode": 2,
"stderrRe":
/Unable to use configuration file "[^"]*cfg\/unrecognized\.jsonc"; File name should be \(or end with\) one of the supported types \(e\.g\., "\.markdownlint\.json" or "example\.markdownlint-cli2\.jsonc"\)\./u,
/Unable to use configuration file '[^']*cfg\/unrecognized\.jsonc'; File name should be \(or end with\) one of the supported types \(e\.g\., '\.markdownlint\.json' or 'example\.markdownlint-cli2\.jsonc'\)\./u,
"cwd": "config-files"
});

Expand Down Expand Up @@ -773,7 +773,7 @@ const testCases = ({
"name": "package-json-invalid",
"args": [ "**/*.md" ],
"exitCode": 2,
"stderrRe": /package\.json".*Unable to parse JSONC content/u
"stderrRe": /'[^']*package\.json'.*Unable to parse JSONC content/u
});

testCase({
Expand Down

0 comments on commit 5b71d6f

Please sign in to comment.