wip
Some checks failed
Checkers / linkcheck (push) Has been cancelled
Checkers / spellcheck (push) Has been cancelled
CI / build (20, macos-latest) (push) Has been cancelled
CI / build (20, ubuntu-latest) (push) Has been cancelled
CI / build (20, windows-latest) (push) Has been cancelled
CI / build (22, macos-latest) (push) Has been cancelled
CI / build (22, ubuntu-latest) (push) Has been cancelled
CI / build (22, windows-latest) (push) Has been cancelled
CI / build (24, macos-latest) (push) Has been cancelled
CI / build (24, ubuntu-latest) (push) Has been cancelled
CI / build (24, windows-latest) (push) Has been cancelled
CI / pnpm (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
TestRepos / build (latest, ubuntu-latest) (push) Has been cancelled
UpdateTestRepos / update (push) Has been cancelled

This commit is contained in:
David Anson 2025-09-17 21:36:43 -07:00
parent 6e243fa35b
commit 0241a979c4
10 changed files with 3298 additions and 58 deletions

View file

@ -61,8 +61,12 @@ for (const rule of rules) {
""
);
const ruleData = schema.properties[name];
const ruleProperties = ruleData.oneOf.at(-1).properties;
if (ruleProperties) {
const ruleProperties = Object.fromEntries(
Object.entries(
ruleData.oneOf.at(-1).properties
).filter(([ key ]) => key !== "severity")
);
if (Object.keys(ruleProperties).length > 0) {
section.push(
"Parameters:",
""

File diff suppressed because it is too large Load diff

View file

@ -6,14 +6,20 @@ import yaml from "js-yaml";
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json");
/** @type {Object<string, any>} */
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;
const subproperties = properties.oneOf?.at(-1).properties;
if (subproperties) {
const subproperties = Object.fromEntries(
Object.entries(
properties.oneOf?.at(-1).properties || []
).filter(([ key ]) => key !== "severity")
);
if (Object.keys(subproperties).length > 0) {
/** @type {Object<string, any>} */
const ruleExample = {};
// eslint-disable-next-line guard-for-in
for (const property in subproperties) {
@ -26,6 +32,13 @@ for (const rule in configSchema.properties) {
}
}
/**
* Transforms comments to use the specified prefix.
*
* @param {string} input Markdown input.
* @param {string} commentPrefix Comment prefix.
* @returns {string} Transformed input.
*/
const transformComments = (input, commentPrefix) => (
commentPrefix +
" Example markdownlint configuration with all properties set to their default value\n" +

View file

@ -74,17 +74,17 @@ for (const rule of rules) {
"type": "object",
"additionalProperties": false,
"properties": {
// "severity": {
// "description": "Rule severity",
// "type": "string",
// "enum": [
// "error"
// ],
// "default": "error"
// }
"severity": {
"description": "Rule severity",
"type": "string",
"enum": [
"error"
],
"default": "error"
}
}
};
let custom = true;
scheme.oneOf.push(subscheme);
/* eslint-disable camelcase */
switch (ruleName) {
case "MD001":
@ -638,13 +638,9 @@ for (const rule of rules) {
};
break;
default:
custom = false;
break;
}
/* eslint-enable camelcase */
if (custom) {
scheme.oneOf.push(subscheme);
}
for (const name of rule.names) {
schema.properties[name] = scheme;
// Using $ref causes rule aliases not to get JSDoc comments

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,58 @@
# Configure File With Severity
Text * text* {MD037}
Text ` text` {MD038}
Text [ text](.) {MD039}
+ List item {MD004}
Text (text)[.] {MD011}
2. List item {MD029}
<!-- markdownlint-disable -->
Text * text*
Text ` text`
Text [ text](.)
+ List item
Text (text)[.]
2. List item
<!-- markdownlint-restore -->
Text * text* {MD037}
Text ` text` {MD038}
Text [ text](.) {MD039}
+ List item {MD004}
Text (text)[.] {MD011}
2. List item {MD029}
<!-- markdownlint-configure-file {
"default": false,
"MD037": "error",
"MD038": "error",
"MD039": "error",
"MD004": {
"severity": "error",
"style": "dash"
},
"MD011": {
"severity": "error"
},
"MD029": {
"severity": "error"
}
} -->

View file

@ -346,17 +346,104 @@ test("enableRulesString", getConfigTestImplementation(
configTestExpected3511
));
test("enableRulesEmptyObject", getConfigTestImplementation(
test("enableRulesObjectEmpty", getConfigTestImplementation(
{
"MD041": {},
"default": false,
// @ts-ignore
"no-multiple-space-atx": {},
"extra": {}
},
configTestExpected3511
));
test("enableRulesObjectTruthy", getConfigTestImplementation(
{
"MD041": {
// @ts-ignore
"severity": 1
},
"default": false,
"no-multiple-space-atx": {
// @ts-ignore
"severity": 1
},
"extra": {
"severity": 1
}
},
configTestExpected3511
));
test("enableRulesObjectFalsy", getConfigTestImplementation(
{
"MD041": {
// @ts-ignore
"severity": 0
},
"default": false,
"no-multiple-space-atx": {
// @ts-ignore
"severity": 0
},
"extra": {
"severity": 0
}
},
configTestExpected3511
));
test("enableRulesObjectError", getConfigTestImplementation(
{
"MD041": {
"severity": "error"
},
"default": false,
"no-multiple-space-atx": {
"severity": "error"
},
"extra": {
"severity": "error"
}
},
configTestExpected3511
));
test("enableRulesObjectWarning", getConfigTestImplementation(
{
"MD041": {
// @ts-ignore
"severity": "warning"
},
"default": false,
"no-multiple-space-atx": {
// @ts-ignore
"severity": "warning"
},
"extra": {
"severity": "warning"
}
},
configTestExpected3511
));
test("enableRulesObjectOff", getConfigTestImplementation(
{
"MD041": {
// @ts-ignore
"severity": "off"
},
"default": false,
"no-multiple-space-atx": {
// @ts-ignore
"severity": "off"
},
"extra": {
"severity": "off"
}
},
configTestExpected3511
));
test("disableTag", getConfigTestImplementation(
{
"default": true,
@ -921,7 +1008,7 @@ test("readme", async(t) => {
});
test("validateJsonUsingConfigSchemaStrict", async(t) => {
t.plan(211);
t.plan(212);
// @ts-ignore
const ajv = new Ajv(ajvOptions);
const validateSchemaStrict = ajv.compile(configSchemaStrict);

View file

@ -11203,6 +11203,320 @@ Generated by [AVA](https://avajs.dev).
`,
}
## configure-file-with-severity.md
> Snapshot 1
{
errors: [
{
errorContext: null,
errorDetail: 'Expected: dash; Actual: plus',
errorRange: [
1,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 1,
insertText: '-',
},
lineNumber: 9,
ruleDescription: 'Unordered list style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md004.md',
ruleNames: [
'MD004',
'ul-style',
],
severity: 'error',
},
{
errorContext: null,
errorDetail: 'Expected: dash; Actual: plus',
errorRange: [
1,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 1,
insertText: '-',
},
lineNumber: 37,
ruleDescription: 'Unordered list style',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md004.md',
ruleNames: [
'MD004',
'ul-style',
],
severity: 'error',
},
{
errorContext: null,
errorDetail: '(text)[.]',
errorRange: [
6,
9,
],
fixInfo: {
deleteCount: 9,
editColumn: 6,
insertText: '[text](.)',
},
lineNumber: 11,
ruleDescription: 'Reversed link syntax',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md011.md',
ruleNames: [
'MD011',
'no-reversed-links',
],
severity: 'error',
},
{
errorContext: null,
errorDetail: '(text)[.]',
errorRange: [
6,
9,
],
fixInfo: {
deleteCount: 9,
editColumn: 6,
insertText: '[text](.)',
},
lineNumber: 39,
ruleDescription: 'Reversed link syntax',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md011.md',
ruleNames: [
'MD011',
'no-reversed-links',
],
severity: 'error',
},
{
errorContext: null,
errorDetail: 'Expected: 1; Actual: 2; Style: 1/1/1',
errorRange: [
1,
3,
],
fixInfo: {
deleteCount: 1,
editColumn: 1,
insertText: '1',
},
lineNumber: 13,
ruleDescription: 'Ordered list item prefix',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md029.md',
ruleNames: [
'MD029',
'ol-prefix',
],
severity: 'error',
},
{
errorContext: null,
errorDetail: 'Expected: 1; Actual: 2; Style: 1/1/1',
errorRange: [
1,
3,
],
fixInfo: {
deleteCount: 1,
editColumn: 1,
insertText: '1',
},
lineNumber: 41,
ruleDescription: 'Ordered list item prefix',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md029.md',
ruleNames: [
'MD029',
'ol-prefix',
],
severity: 'error',
},
{
errorContext: '* t',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 3,
ruleDescription: 'Spaces inside emphasis markers',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md037.md',
ruleNames: [
'MD037',
'no-space-in-emphasis',
],
severity: 'error',
},
{
errorContext: '* t',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 31,
ruleDescription: 'Spaces inside emphasis markers',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md037.md',
ruleNames: [
'MD037',
'no-space-in-emphasis',
],
severity: 'error',
},
{
errorContext: '` text`',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 5,
ruleDescription: 'Spaces inside code span elements',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md038.md',
ruleNames: [
'MD038',
'no-space-in-code',
],
severity: 'error',
},
{
errorContext: '` text`',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 33,
ruleDescription: 'Spaces inside code span elements',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md038.md',
ruleNames: [
'MD038',
'no-space-in-code',
],
severity: 'error',
},
{
errorContext: '[ text]',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 7,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
severity: 'error',
},
{
errorContext: '[ text]',
errorDetail: null,
errorRange: [
7,
1,
],
fixInfo: {
deleteCount: 1,
editColumn: 7,
},
lineNumber: 35,
ruleDescription: 'Spaces inside link text',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md039.md',
ruleNames: [
'MD039',
'no-space-in-links',
],
severity: 'error',
},
],
fixed: `# Configure File With Severity␊
Text *text* {MD037}␊
Text \`text\` {MD038}␊
Text [text](.) {MD039}␊
- List item {MD004}␊
Text [text](.) {MD011}␊
1. List item {MD029}␊
<!-- markdownlint-disable -->
Text * text*
Text \` text\`␊
Text [ text](.)␊
+ List item␊
Text (text)[.]␊
2. List item␊
<!-- markdownlint-restore -->
Text *text* {MD037}␊
Text \`text\` {MD038}␊
Text [text](.) {MD039}␊
- List item {MD004}␊
Text [text](.) {MD011}␊
1. List item {MD029}␊
<!-- markdownlint-configure-file {␊
"default": false,␊
"MD037": "error",␊
"MD038": "error",␊
"MD039": "error",␊
"MD004": {␊
"severity": "error",␊
"style": "dash"␊
},␊
"MD011": {␊
"severity": "error"␊
},␊
"MD029": {␊
"severity": "error"␊
}␊
} -->␊
`,
}
## consecutive_blank_lines.md
> Snapshot 1