2019-10-30 20:37:06 -07:00
|
|
|
// @ts-check
|
|
|
|
|
2016-10-05 22:21:54 -07:00
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const rules = require("../lib/rules");
|
2016-10-05 22:21:54 -07:00
|
|
|
|
|
|
|
// Schema scaffolding
|
2018-04-27 22:05:34 -07:00
|
|
|
const schema = {
|
2016-10-05 22:21:54 -07:00
|
|
|
"title": "Markdownlint configuration schema",
|
|
|
|
"type": "object",
|
|
|
|
"properties": {
|
|
|
|
"default": {
|
|
|
|
"description": "Default state for all rules",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
2017-05-19 22:36:46 -07:00
|
|
|
},
|
|
|
|
"extends": {
|
|
|
|
"description": "Path to configuration file to extend",
|
2021-01-19 20:41:04 -08:00
|
|
|
"type": [
|
|
|
|
"string",
|
|
|
|
"null"
|
|
|
|
],
|
2017-05-19 22:36:46 -07:00
|
|
|
"default": null
|
2019-10-25 14:45:01 -07:00
|
|
|
},
|
|
|
|
"$schema": {
|
|
|
|
"description": "JSON Schema URI (used by some editors)",
|
|
|
|
"type": "string",
|
|
|
|
"default": "https://raw.githubusercontent.com/DavidAnson/markdownlint" +
|
2020-08-11 22:52:29 -07:00
|
|
|
"/main/schema/markdownlint-config-schema.json"
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
},
|
2020-09-15 21:48:00 -07:00
|
|
|
"additionalProperties": {
|
|
|
|
"type:": [
|
|
|
|
"boolean",
|
|
|
|
"object"
|
|
|
|
]
|
|
|
|
}
|
2016-10-05 22:21:54 -07:00
|
|
|
};
|
2018-04-27 22:05:34 -07:00
|
|
|
const tags = {};
|
2016-10-05 22:21:54 -07:00
|
|
|
|
|
|
|
// Add rules
|
|
|
|
rules.forEach(function forRule(rule) {
|
|
|
|
rule.tags.forEach(function forTag(tag) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const tagRules = tags[tag] || [];
|
2018-01-12 23:21:06 -08:00
|
|
|
tagRules.push(rule.names[0]);
|
2016-10-05 22:21:54 -07:00
|
|
|
tags[tag] = tagRules;
|
|
|
|
});
|
2018-04-27 22:05:34 -07:00
|
|
|
const scheme = {
|
2018-01-18 21:34:30 -08:00
|
|
|
"description": rule.names.join("/") + " - " + rule.description,
|
2016-10-05 22:21:54 -07:00
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
|
|
|
};
|
2018-04-27 22:05:34 -07:00
|
|
|
let custom = true;
|
2018-01-12 23:21:06 -08:00
|
|
|
switch (rule.names[0]) {
|
2016-10-05 22:21:54 -07:00
|
|
|
case "MD002":
|
|
|
|
scheme.properties = {
|
|
|
|
"level": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Heading level",
|
2016-10-05 22:21:54 -07:00
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD003":
|
|
|
|
scheme.properties = {
|
|
|
|
"style": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Heading style",
|
2016-10-05 22:21:54 -07:00
|
|
|
"type": "string",
|
|
|
|
"enum": [
|
|
|
|
"consistent",
|
|
|
|
"atx",
|
|
|
|
"atx_closed",
|
|
|
|
"setext",
|
|
|
|
"setext_with_atx",
|
|
|
|
"setext_with_atx_closed"
|
|
|
|
],
|
|
|
|
"default": "consistent"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD004":
|
|
|
|
scheme.properties = {
|
|
|
|
"style": {
|
|
|
|
"description": "List style",
|
|
|
|
"type": "string",
|
|
|
|
"enum": [
|
|
|
|
"consistent",
|
|
|
|
"asterisk",
|
|
|
|
"plus",
|
|
|
|
"dash",
|
|
|
|
"sublist"
|
|
|
|
],
|
|
|
|
"default": "consistent"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD007":
|
|
|
|
scheme.properties = {
|
|
|
|
"indent": {
|
|
|
|
"description": "Spaces for indent",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 2
|
2020-01-01 15:53:03 -05:00
|
|
|
},
|
|
|
|
"start_indented": {
|
|
|
|
"description": "Whether to indent the first level of the list",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD009":
|
|
|
|
scheme.properties = {
|
|
|
|
"br_spaces": {
|
|
|
|
"description": "Spaces for line break",
|
|
|
|
"type": "integer",
|
2018-04-30 21:34:19 -07:00
|
|
|
"default": 2
|
2017-05-11 21:44:41 -07:00
|
|
|
},
|
|
|
|
"list_item_empty_lines": {
|
|
|
|
"description": "Allow spaces for empty lines in list items",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
2019-12-09 22:05:57 -08:00
|
|
|
},
|
|
|
|
"strict": {
|
|
|
|
"description": "Include unnecessary breaks",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD010":
|
|
|
|
scheme.properties = {
|
|
|
|
"code_blocks": {
|
|
|
|
"description": "Include code blocks",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
2021-04-09 16:33:01 -07:00
|
|
|
},
|
|
|
|
"spaces_per_tab": {
|
|
|
|
"description": "Number of spaces for each hard tab",
|
|
|
|
"type": "number",
|
|
|
|
"default": 1
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD012":
|
|
|
|
scheme.properties = {
|
|
|
|
"maximum": {
|
|
|
|
"description": "Consecutive blank lines",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD013":
|
|
|
|
scheme.properties = {
|
|
|
|
"line_length": {
|
|
|
|
"description": "Number of characters",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 80
|
|
|
|
},
|
2019-03-26 22:34:19 -07:00
|
|
|
"heading_line_length": {
|
|
|
|
"description": "Number of characters for headings",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 80
|
|
|
|
},
|
2019-06-07 19:57:15 -07:00
|
|
|
"code_block_line_length": {
|
|
|
|
"description": "Number of characters for code blocks",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 80
|
|
|
|
},
|
2016-10-05 22:21:54 -07:00
|
|
|
"code_blocks": {
|
|
|
|
"description": "Include code blocks",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
|
|
|
},
|
|
|
|
"tables": {
|
|
|
|
"description": "Include tables",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
2017-02-11 16:20:24 -08:00
|
|
|
},
|
2018-03-19 23:39:42 +01:00
|
|
|
"headings": {
|
|
|
|
"description": "Include headings",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
|
|
|
},
|
2017-02-11 16:20:24 -08:00
|
|
|
"headers": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Include headings",
|
2017-02-11 16:20:24 -08:00
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
2019-12-12 21:22:45 -08:00
|
|
|
},
|
|
|
|
"strict": {
|
|
|
|
"description": "Strict length checking",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
2020-03-22 14:06:29 -07:00
|
|
|
},
|
|
|
|
"stern": {
|
|
|
|
"description": "Stern length checking",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2019-03-24 21:50:56 -07:00
|
|
|
case "MD022":
|
|
|
|
scheme.properties = {
|
|
|
|
"lines_above": {
|
|
|
|
"description": "Blank lines above heading",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
},
|
|
|
|
"lines_below": {
|
|
|
|
"description": "Blank lines below heading",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2018-07-19 21:49:30 -07:00
|
|
|
case "MD024":
|
|
|
|
scheme.properties = {
|
|
|
|
"allow_different_nesting": {
|
|
|
|
"description": "Only check sibling headings",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
|
|
|
},
|
|
|
|
"siblings_only": {
|
|
|
|
"description": "Only check sibling headings",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2016-10-05 22:21:54 -07:00
|
|
|
case "MD026":
|
2020-11-17 20:32:17 -08:00
|
|
|
scheme.properties = {
|
|
|
|
"punctuation": {
|
|
|
|
"description": "Punctuation characters",
|
|
|
|
"type": "string",
|
|
|
|
"default": ".,;:!。,;:!"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2016-10-05 22:21:54 -07:00
|
|
|
case "MD036":
|
|
|
|
scheme.properties = {
|
|
|
|
"punctuation": {
|
|
|
|
"description": "Punctuation characters",
|
|
|
|
"type": "string",
|
2019-06-06 22:21:31 -07:00
|
|
|
"default": ".,;:!?。,;:!?"
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD029":
|
|
|
|
scheme.properties = {
|
|
|
|
"style": {
|
|
|
|
"description": "List style",
|
|
|
|
"type": "string",
|
|
|
|
"enum": [
|
|
|
|
"one",
|
2017-12-12 22:41:11 -08:00
|
|
|
"ordered",
|
2019-03-06 21:57:19 -08:00
|
|
|
"one_or_ordered",
|
|
|
|
"zero"
|
2016-10-05 22:21:54 -07:00
|
|
|
],
|
2017-12-12 22:41:11 -08:00
|
|
|
"default": "one_or_ordered"
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD030":
|
|
|
|
scheme.properties = {
|
|
|
|
"ul_single": {
|
|
|
|
"description": "Spaces for single-line unordered list items",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
},
|
|
|
|
"ol_single": {
|
|
|
|
"description": "Spaces for single-line ordered list items",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
},
|
|
|
|
"ul_multi": {
|
|
|
|
"description": "Spaces for multi-line unordered list items",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
},
|
|
|
|
"ol_multi": {
|
|
|
|
"description": "Spaces for multi-line ordered list items",
|
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2019-08-02 22:58:41 -07:00
|
|
|
case "MD031":
|
|
|
|
scheme.properties = {
|
|
|
|
"list_items": {
|
|
|
|
"description": "Include list items",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2016-10-05 22:21:54 -07:00
|
|
|
case "MD033":
|
|
|
|
scheme.properties = {
|
|
|
|
"allowed_elements": {
|
|
|
|
"description": "Allowed elements",
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
|
|
|
"default": []
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case "MD035":
|
|
|
|
scheme.properties = {
|
|
|
|
"style": {
|
|
|
|
"description": "Horizontal rule style",
|
|
|
|
"type": "string",
|
|
|
|
"default": "consistent"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2019-03-16 20:21:57 -07:00
|
|
|
case "MD025":
|
2017-05-06 15:25:14 -07:00
|
|
|
case "MD041":
|
|
|
|
scheme.properties = {
|
|
|
|
"level": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "Heading level",
|
2017-05-06 15:25:14 -07:00
|
|
|
"type": "integer",
|
|
|
|
"default": 1
|
|
|
|
},
|
|
|
|
"front_matter_title": {
|
|
|
|
"description": "RegExp for matching title in front matter",
|
|
|
|
"type": "string",
|
2017-10-24 22:15:03 -07:00
|
|
|
"default": "^\\s*title\\s*[:=]"
|
2017-05-06 15:25:14 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2016-10-05 22:21:54 -07:00
|
|
|
case "MD043":
|
|
|
|
scheme.properties = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"headings": {
|
|
|
|
"description": "List of headings",
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2021-01-19 20:41:04 -08:00
|
|
|
"default": []
|
2018-03-19 23:39:42 +01:00
|
|
|
},
|
2016-10-05 22:21:54 -07:00
|
|
|
"headers": {
|
2018-03-19 23:39:42 +01:00
|
|
|
"description": "List of headings",
|
2016-10-05 22:21:54 -07:00
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2021-01-19 20:41:04 -08:00
|
|
|
"default": []
|
2016-10-05 22:21:54 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2016-12-22 13:34:18 -08:00
|
|
|
case "MD044":
|
|
|
|
scheme.properties = {
|
|
|
|
"names": {
|
|
|
|
"description": "List of proper names",
|
|
|
|
"type": "array",
|
|
|
|
"items": {
|
|
|
|
"type": "string"
|
|
|
|
},
|
2021-01-19 20:41:04 -08:00
|
|
|
"default": []
|
2017-03-18 19:47:26 -07:00
|
|
|
},
|
|
|
|
"code_blocks": {
|
|
|
|
"description": "Include code blocks",
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
2016-12-22 13:34:18 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2019-04-17 14:42:17 -07:00
|
|
|
case "MD046":
|
|
|
|
scheme.properties = {
|
|
|
|
"style": {
|
|
|
|
"description": "Block style",
|
|
|
|
"type": "string",
|
|
|
|
"enum": [
|
|
|
|
"consistent",
|
|
|
|
"fenced",
|
|
|
|
"indented"
|
|
|
|
],
|
|
|
|
"default": "consistent"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2019-10-08 21:10:02 -07:00
|
|
|
case "MD048":
|
|
|
|
scheme.properties = {
|
|
|
|
"style": {
|
2021-05-14 08:45:14 -07:00
|
|
|
"description": "Code fence style",
|
2019-10-08 21:10:02 -07:00
|
|
|
"type": "string",
|
|
|
|
"enum": [
|
|
|
|
"consistent",
|
|
|
|
"backtick",
|
|
|
|
"tilde"
|
|
|
|
],
|
|
|
|
"default": "consistent"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
break;
|
2016-10-05 22:21:54 -07:00
|
|
|
default:
|
|
|
|
custom = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (custom) {
|
2019-10-30 20:37:06 -07:00
|
|
|
// @ts-ignore
|
2016-10-05 22:21:54 -07:00
|
|
|
scheme.type = [ "boolean", "object" ];
|
|
|
|
scheme.additionalProperties = false;
|
|
|
|
}
|
2018-01-12 23:21:06 -08:00
|
|
|
rule.names.forEach(function forName(name) {
|
|
|
|
schema.properties[name] = scheme;
|
2016-10-05 22:21:54 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Add tags
|
|
|
|
Object.keys(tags).forEach(function forTag(tag) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const scheme = {
|
2016-10-05 22:21:54 -07:00
|
|
|
"description": tag + " - " + tags[tag].join(", "),
|
|
|
|
"type": "boolean",
|
|
|
|
"default": true
|
|
|
|
};
|
|
|
|
schema.properties[tag] = scheme;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Write schema
|
2018-04-27 22:05:34 -07:00
|
|
|
const schemaFile = path.join(__dirname, "markdownlint-config-schema.json");
|
2016-10-05 22:21:54 -07:00
|
|
|
fs.writeFileSync(schemaFile, JSON.stringify(schema, null, " "));
|