markdownlint/test/markdownlint-test-repos.mjs
David Anson 4b948627aa
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run
Remove outdated table-column-style suppression from mdn/content test repo, address new VS Code type warnings.
2025-11-15 21:18:18 -08:00

70 lines
2.2 KiB
JavaScript

// @ts-check
import path from "node:path";
const { join } = path.posix;
import { globby } from "globby";
import jsoncParser from "jsonc-parser";
import jsYaml from "js-yaml";
import { formatLintResults } from "markdownlint/helpers";
import { lint, readConfig } from "markdownlint/promise";
import { markdownlintParallel } from "./markdownlint-test-parallel.mjs";
/** @typedef {import("markdownlint").Configuration} Configuration */
/**
* Lints a test repository.
*
* @param {import("ava").ExecutionContext<unknown>} t Test instance.
* @param {string[]} globPatterns Array of files to in/exclude.
* @param {string} configPath Path to config file.
* @param {Configuration} [configOverrides] Configuration overrides.
* @param {boolean} [parallel] True to lint in parallel.
* @returns {Promise<void>} Test result.
*/
export function lintTestRepo(t, globPatterns, configPath, configOverrides, parallel) {
t.plan(1);
const jsoncParse = (/** @type {string} */ json) => {
const config = jsoncParser.parse(json, [], { "allowTrailingComma": true });
return config.config || config;
};
const yamlParse = (/** @type {string} */ yaml) => jsYaml.load(yaml);
return Promise.all([
globby(globPatterns),
readConfig(configPath, [ jsoncParse, yamlParse ])
]).then((globbyAndReadConfigResults) => {
const [ files, rawConfig ] = globbyAndReadConfigResults;
// eslint-disable-next-line no-console
console.log(`${t.title}: Linting ${files.length} files...`);
const cookedConfig = Object.fromEntries(
Object.entries(rawConfig)
.map(([ k, v ]) => [
k.replace(/header/, "heading"),
v
])
);
const config = {
...cookedConfig,
...configOverrides
};
return (parallel ? markdownlintParallel : lint)({
files,
config
}).then((results) => {
t.snapshot(
formatLintResults(results).join("\n"),
"Expected linting violations"
);
});
});
}
/**
* Excludes a list of globs.
*
* @param {string} rootDir Root directory for globs.
* @param {...string} globs Globs to exclude.
* @returns {string[]} Array of excluded globs.
*/
export function excludeGlobs(rootDir, ...globs) {
return globs.map((glob) => "!" + join(rootDir, glob));
}