Add $id to configuration schema, switch to version-specific repository links.

This commit is contained in:
David Anson 2023-11-24 15:23:36 -08:00
parent 24ee072442
commit 316b0989c3
6 changed files with 36 additions and 33 deletions

View file

@ -204,8 +204,8 @@
}
// Show library version
document.getElementById("version").textContent =
"(v" + markdownlint.getVersion() + ")";
var version = markdownlint.getVersion();
document.getElementById("version").textContent = "(v" + version + ")";
// Add event listeners
document.body.addEventListener("dragover", onDragOver);
@ -227,7 +227,7 @@
"Content gets parsed and displayed in the upper-right box; rule violations (if any) show up in the lower-right box.",
"Click a violation for information about it or click its line number to highlighted it in the lower-left box.",
"",
"> *Note*: [All rules](https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md) are enabled except [MD013/line-length](https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md).",
"> *Note*: [All rules](https://github.com/DavidAnson/markdownlint/blob/v" + version + "/doc/Rules.md) are enabled except [MD013/line-length](https://github.com/DavidAnson/markdownlint/blob/v" + version + "/doc/md013.md).",
"",
"",
"#### Resources",

View file

@ -62,9 +62,9 @@ See also: [`markdownlint` built-in rule implementations][lib].
*None* - The entire body of code is tested to 100% coverage by the core
`markdownlint` project, so there are no additional tests here.
[custom-rules]: https://github.com/DavidAnson/markdownlint/blob/main/doc/CustomRules.md
[custom-rules]: https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/CustomRules.md
[jsdoc]: https://en.m.wikipedia.org/wiki/JSDoc
[lib]: https://github.com/DavidAnson/markdownlint/tree/main/lib
[lib]: https://github.com/DavidAnson/markdownlint/tree/v0.32.1/lib
[markdown]: https://en.wikipedia.org/wiki/Markdown
[markdownlint]: https://github.com/DavidAnson/markdownlint
[rules]: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
[rules]: https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/Rules.md

View file

@ -6,6 +6,10 @@
*/
export interface Configuration {
/**
* JSON Schema URI (expected by some editors)
*/
$schema?: string;
/**
* Default state for all rules
*/
@ -14,10 +18,6 @@ export interface Configuration {
* Path to configuration file to extend
*/
extends?: string | null;
/**
* JSON Schema URI (used by some editors)
*/
$schema?: string;
/**
* MD001/heading-increment : Heading levels should only increment by one level at a time : https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md001.md
*/

View file

@ -7,13 +7,22 @@ const path = require("node:path");
/** @type {import("../lib/markdownlint").Rule[]} */
const rules = require("../lib/rules");
const jsonSchemaToTypeScript = require("json-schema-to-typescript");
const { version } = require("../lib/constants");
const schemaUri = `https://raw.githubusercontent.com/DavidAnson/markdownlint/v${version}/schema/markdownlint-config-schema.json`;
// Schema scaffolding
const schema = {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": schemaUri,
"title": "markdownlint configuration schema",
"type": "object",
"properties": {
"$schema": {
"description": "JSON Schema URI (expected by some editors)",
"type": "string",
"default": schemaUri
},
"default": {
"description": "Default state for all rules",
"type": "boolean",
@ -26,12 +35,6 @@ const schema = {
"null"
],
"default": null
},
"$schema": {
"description": "JSON Schema URI (used by some editors)",
"type": "string",
"default": "https://raw.githubusercontent.com/DavidAnson/markdownlint" +
"/main/schema/markdownlint-config-schema.json"
}
},
"additionalProperties": {

View file

@ -1,8 +1,14 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/DavidAnson/markdownlint/v0.32.1/schema/markdownlint-config-schema.json",
"title": "markdownlint configuration schema",
"type": "object",
"properties": {
"$schema": {
"description": "JSON Schema URI (expected by some editors)",
"type": "string",
"default": "https://raw.githubusercontent.com/DavidAnson/markdownlint/v0.32.1/schema/markdownlint-config-schema.json"
},
"default": {
"description": "Default state for all rules",
"type": "boolean",
@ -16,11 +22,6 @@
],
"default": null
},
"$schema": {
"description": "JSON Schema URI (used by some editors)",
"type": "string",
"default": "https://raw.githubusercontent.com/DavidAnson/markdownlint/main/schema/markdownlint-config-schema.json"
},
"MD001": {
"description": "MD001/heading-increment : Heading levels should only increment by one level at a time : https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md001.md",
"type": "boolean",

View file

@ -20,10 +20,9 @@ const configSchema = require("../schema/markdownlint-config-schema.json");
const deprecatedRuleNames = new Set(constants.deprecatedRuleNames);
const jsonSchemaVersion = "http://json-schema.org/draft-07/schema#";
const configSchemaUri = "https://example.com/configSchema";
const configSchemaStrictUri = "https://example.com/configSchemaStrict";
const configSchemaStrict = {
...configSchema,
"$id": `${configSchema.$id}-strict`,
"additionalProperties": false
};
@ -918,8 +917,8 @@ test("validateJsonUsingConfigSchemaStrict", async(t) => {
t.plan(171);
const { addSchema, validate } =
await import("@hyperjump/json-schema/draft-07");
addSchema(configSchemaStrict, configSchemaStrictUri);
const validateConfigSchema = await validate(configSchemaStrictUri);
addSchema(configSchemaStrict);
const validateConfigSchema = await validate(configSchemaStrict.$id);
const configRe =
/^[\s\S]*<!-- markdownlint-configure-file ([\s\S]*) -->[\s\S]*$/;
const ignoreFiles = new Set([
@ -956,8 +955,8 @@ test("validateConfigSchemaAllowsUnknownProperties", async(t) => {
t.plan(4);
const { addSchema, validate } =
await import("@hyperjump/json-schema/draft-07");
addSchema(configSchema, configSchemaUri);
addSchema(configSchemaStrict, configSchemaStrictUri);
addSchema(configSchema);
addSchema(configSchemaStrict);
const testCases = [
{
"property": true
@ -971,14 +970,14 @@ test("validateConfigSchemaAllowsUnknownProperties", async(t) => {
for (const testCase of testCases) {
const defaultResult =
// eslint-disable-next-line no-await-in-loop
await validate(configSchemaUri, testCase, "BASIC");
await validate(configSchema.$id, testCase, "BASIC");
t.true(
defaultResult.valid,
"Unknown property blocked by default: " + JSON.stringify(testCase)
);
const strictResult =
// eslint-disable-next-line no-await-in-loop
await validate(configSchemaStrictUri, testCase, "BASIC");
await validate(configSchemaStrict.$id, testCase, "BASIC");
t.false(
strictResult.valid,
"Unknown property allowed when strict: " + JSON.stringify(testCase)
@ -990,8 +989,8 @@ test("validateConfigSchemaAppliesToUnknownProperties", async(t) => {
t.plan(4);
const { addSchema, validate } =
await import("@hyperjump/json-schema/draft-07");
addSchema(configSchema, configSchemaUri);
const validateConfigSchema = await validate(configSchemaUri);
addSchema(configSchema);
const validateConfigSchema = await validate(configSchema.$id);
for (const allowed of [ true, {} ]) {
t.true(
validateConfigSchema({ "property": allowed }, "BASIC").valid,
@ -1024,8 +1023,8 @@ test("validateConfigExampleJson", async(t) => {
"utf8"
);
const jsonObject = JSON.parse(stripJsonComments(dataJson));
addSchema(configSchemaStrict, configSchemaStrictUri);
const result = await validate(configSchemaStrictUri, jsonObject, "BASIC");
addSchema(configSchemaStrict);
const result = await validate(configSchemaStrict.$id, jsonObject, "BASIC");
t.true(
result.valid,
`${fileJson}\n${JSON.stringify(result, null, 2)}`