mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.
This commit is contained in:
parent
191226f070
commit
1e71f6f44e
140 changed files with 1087 additions and 10428 deletions
55
schema/build-config-example.mjs
Normal file
55
schema/build-config-example.mjs
Normal file
|
@ -0,0 +1,55 @@
|
|||
// @ts-check
|
||||
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import yaml from "js-yaml";
|
||||
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
|
||||
const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
|
||||
|
||||
const configExample = {};
|
||||
for (const rule in configSchema.properties) {
|
||||
if (/^(?:MD\d{3}|default|extends)$/.test(rule)) {
|
||||
const properties = configSchema.properties[rule];
|
||||
configExample[rule + "-description"] = properties.description;
|
||||
configExample[rule] = properties.default;
|
||||
if (properties.properties) {
|
||||
const ruleExample = {};
|
||||
// eslint-disable-next-line guard-for-in
|
||||
for (const property in properties.properties) {
|
||||
const ruleProperties = properties.properties[property];
|
||||
ruleExample[property + "-sub-description"] = ruleProperties.description;
|
||||
ruleExample[property] = ruleProperties.default;
|
||||
}
|
||||
configExample[rule] = ruleExample;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const transformComments = (input, commentPrefix) => (
|
||||
commentPrefix +
|
||||
" Example markdownlint configuration with all properties set to their default value\n" +
|
||||
input
|
||||
.replace(/^(\s*)[^-\s]+-sub-description"?: "?([^"\n]+)"?,?$/gm, "$1" + commentPrefix + " $2")
|
||||
.replace(/^(\s*)[^-\s]+-description"?: "?([^"\n]+)"?,?$/gm, "\n$1" + commentPrefix + " $2")
|
||||
);
|
||||
|
||||
const configStringJson = JSON.stringify(configExample, null, 2);
|
||||
await fs.writeFile(
|
||||
path.join(__dirname(import.meta), ".markdownlint.jsonc"),
|
||||
transformComments(configStringJson, "//"),
|
||||
"utf8"
|
||||
);
|
||||
|
||||
const configStringYaml = yaml.dump(
|
||||
configExample,
|
||||
{
|
||||
"forceQuotes": true,
|
||||
"lineWidth": -1,
|
||||
"quotingType": "\""
|
||||
}
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(__dirname(import.meta), ".markdownlint.yaml"),
|
||||
transformComments(configStringYaml, "#"),
|
||||
"utf8"
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue