Update test-repos implementation to output all unnecessary RegExps, remove suppression for fixed issues in https://github.com/pi-hole/docs test repository.

This commit is contained in:
David Anson 2023-04-24 21:24:19 -07:00
parent 8595962251
commit 38e168ba09

View file

@ -20,7 +20,7 @@ const readConfigPromise = promisify(markdownlint.readConfig);
* @returns {Promise} Test result. * @returns {Promise} Test result.
*/ */
async function lintTestRepo(t, globPatterns, configPath, ignoreRes) { async function lintTestRepo(t, globPatterns, configPath, ignoreRes) {
t.plan(1); t.plan(2);
const { globby } = await import("globby"); const { globby } = await import("globby");
const { "default": stripJsonComments } = await import("strip-json-comments"); const { "default": stripJsonComments } = await import("strip-json-comments");
const jsoncParse = (json) => { const jsoncParse = (json) => {
@ -98,18 +98,24 @@ async function lintTestRepo(t, globPatterns, configPath, ignoreRes) {
// Fail if any issues were found (that aren't ignored) // Fail if any issues were found (that aren't ignored)
// @ts-ignore // @ts-ignore
let resultsString = results.toString(); let resultsString = results.toString();
const unnecessaryIgnores = [];
for (const ignoreRe of (ignoreRes || [])) { for (const ignoreRe of (ignoreRes || [])) {
const lengthBefore = resultsString.length; const lengthBefore = resultsString.length;
resultsString = resultsString.replace(ignoreRe, ""); resultsString = resultsString.replace(ignoreRe, "");
if (resultsString.length === lengthBefore) { if (resultsString.length === lengthBefore) {
t.fail(`Unnecessary ignore: ${ignoreRe}`); unnecessaryIgnores.push(ignoreRe);
} }
} }
if (resultsString.length > 0) { t.is(
// eslint-disable-next-line no-console unnecessaryIgnores.length,
console.log(resultsString); 0,
} `Unnecessary ignores:\n${unnecessaryIgnores.join("\n")}`
t.is(resultsString.length, 0, "Unexpected linting violations"); );
t.is(
resultsString,
"",
`Unexpected linting violations:\n${resultsString}`
);
}); });
}); });
} }
@ -265,8 +271,7 @@ test("https://github.com/pi-hole/docs", (t) => {
const rootDir = "./test-repos/pi-hole-docs"; const rootDir = "./test-repos/pi-hole-docs";
const globPatterns = [ join(rootDir, "**/*.md") ]; const globPatterns = [ join(rootDir, "**/*.md") ];
const configPath = join(rootDir, ".markdownlint.json"); const configPath = join(rootDir, ".markdownlint.json");
const ignoreRes = [ /^test-repos\/pi-hole-docs\/docs\/guides\/vpn\/wireguard\/route-everything\.md: \d+: MD034\/.*$\r?\n?/gm ]; return lintTestRepo(t, globPatterns, configPath);
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
}); });
test("https://github.com/v8/v8.dev", (t) => { test("https://github.com/v8/v8.dev", (t) => {