From 316b0989c3bf7f2d8eda5c36a1ad5f0bdfd5c0fb Mon Sep 17 00:00:00 2001 From: David Anson Date: Fri, 24 Nov 2023 15:23:36 -0800 Subject: [PATCH] Add $id to configuration schema, switch to version-specific repository links. --- demo/default.js | 6 +++--- helpers/README.md | 6 +++--- lib/configuration.d.ts | 8 ++++---- schema/build-config-schema.js | 15 +++++++++------ schema/markdownlint-config-schema.json | 11 ++++++----- test/markdownlint-test.js | 23 +++++++++++------------ 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/demo/default.js b/demo/default.js index 9f859ccb..12dcf18b 100644 --- a/demo/default.js +++ b/demo/default.js @@ -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", diff --git a/helpers/README.md b/helpers/README.md index 9d911be1..6ebe0ed5 100644 --- a/helpers/README.md +++ b/helpers/README.md @@ -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 diff --git a/lib/configuration.d.ts b/lib/configuration.d.ts index 4c7ba4c9..4cc1c2fd 100644 --- a/lib/configuration.d.ts +++ b/lib/configuration.d.ts @@ -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 */ diff --git a/schema/build-config-schema.js b/schema/build-config-schema.js index 1f7e8a34..782bdcea 100644 --- a/schema/build-config-schema.js +++ b/schema/build-config-schema.js @@ -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": { diff --git a/schema/markdownlint-config-schema.json b/schema/markdownlint-config-schema.json index 9fc6a184..0ac0694e 100644 --- a/schema/markdownlint-config-schema.json +++ b/schema/markdownlint-config-schema.json @@ -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", diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index 41551800..9340af26 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -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]*[\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)}`