Use proper YAML serialization to produce correct example output for multi-item arrays (fixes #721).

This commit is contained in:
Simon Schrottner 2023-02-21 00:04:05 +01:00 committed by GitHub
parent 7c818914fb
commit 3e454481fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 22 deletions

View file

@ -89,7 +89,8 @@
"tv4": "1.3.0",
"typescript": "4.9.5",
"webpack": "5.75.0",
"webpack-cli": "5.0.1"
"webpack-cli": "5.0.1",
"yaml": "2.2.1"
},
"keywords": [
"markdown",

View file

@ -1,5 +1,5 @@
// Example markdownlint configuration with all properties set to their default value
{
// Example markdownlint JSON(C) configuration with all properties set to their default value
// Default state for all rules
"default": true,

View file

@ -1,4 +1,4 @@
# Example markdownlint YAML configuration with all properties set to their default value
# Example markdownlint configuration with all properties set to their default value
# Default state for all rules
default: true
@ -257,6 +257,5 @@ MD052: true
# MD053/link-image-reference-definitions - Link and image reference definitions should be needed
MD053:
# Ignored definitions
ignored_definitions: [
"//"
]
ignored_definitions:
- "//"

View file

@ -4,6 +4,7 @@
const fs = require("node:fs");
const path = require("node:path");
const yaml = require("yaml");
const configSchema = require("./markdownlint-config-schema.json");
const configExample = {};
@ -25,29 +26,34 @@ for (const rule in configSchema.properties) {
}
}
const configStringJson = JSON.stringify(configExample, null, 2)
const transformComments = (input, commentPrefix) => (
commentPrefix +
// eslint-disable-next-line max-len
.replace(/^\{/, "{\n // Example markdownlint JSON(C) configuration with all properties set to their default value")
.replace(/(\s+)"[^-"]+-description": "(.+)",/g, "\n$1// $2")
.replace(/"[^-"]+-sub-description": "(.+)",/g, "// $1");
" Example markdownlint configuration with all properties set to their default value\n" +
input
// eslint-disable-next-line max-len
.replace(/^(\s*)[^-\s]+-sub-description"?: "?([^"\n]+)"?,?$/gm, "$1" + commentPrefix + " $2")
// eslint-disable-next-line max-len
.replace(/^(\s*)[^-\s]+-description"?: "?([^"\n]+)"?,?$/gm, "\n$1" + commentPrefix + " $2")
);
const configStringJson = JSON.stringify(configExample, null, 2);
fs.writeFileSync(
path.join(__dirname, ".markdownlint.jsonc"),
configStringJson,
transformComments(configStringJson, "//"),
"utf8"
);
const configStringYaml = configStringJson
.replace(/JSON\(C\)/, "YAML")
.replace(/\n {2}/g, "\n")
.replace(/\/\/ /g, "# ")
.replace(/(\s*)"([^"]+)":/g, "$1$2:")
.replace(/: \{/g, ":")
.replace(/\n\}/g, "")
.replace(/,\n/g, "\n")
.replace(/^\{\n/, "")
.replace(/\}$/, "");
const configStringYaml = yaml.stringify(
configExample,
{
"lineWidth": 0,
"defaultStringType": "QUOTE_DOUBLE",
"defaultKeyType": "PLAIN"
}
);
fs.writeFileSync(
path.join(__dirname, ".markdownlint.yaml"),
configStringYaml,
transformComments(configStringYaml, "#"),
"utf8"
);