From 6061cce169ecf8820cd8cd0b9f1c6570ebb3dafe Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 15 Sep 2020 21:48:00 -0700 Subject: [PATCH] Allow unknown (custom) rule names in .markdownlint.json schema. --- schema/build-config-schema.js | 7 +++++- schema/markdownlint-config-schema.json | 7 +++++- test/markdownlint-test.js | 34 ++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/schema/build-config-schema.js b/schema/build-config-schema.js index 4977f8a2..bab8cf57 100644 --- a/schema/build-config-schema.js +++ b/schema/build-config-schema.js @@ -28,7 +28,12 @@ const schema = { "/main/schema/markdownlint-config-schema.json" } }, - "additionalProperties": false + "additionalProperties": { + "type:": [ + "boolean", + "object" + ] + } }; const tags = {}; diff --git a/schema/markdownlint-config-schema.json b/schema/markdownlint-config-schema.json index bd41c0d7..3df38ed2 100644 --- a/schema/markdownlint-config-schema.json +++ b/schema/markdownlint-config-schema.json @@ -1547,5 +1547,10 @@ "default": true } }, - "additionalProperties": false + "additionalProperties": { + "type:": [ + "boolean", + "object" + ] + } } \ No newline at end of file diff --git a/test/markdownlint-test.js b/test/markdownlint-test.js index a403b857..7c78d6dd 100644 --- a/test/markdownlint-test.js +++ b/test/markdownlint-test.js @@ -22,6 +22,10 @@ const homepage = packageJson.homepage; const version = packageJson.version; const deprecatedRuleNames = new Set([ "MD002", "MD006" ]); +const configSchemaStrict = { + ...configSchema, + "additionalProperties": false +}; tape("simpleAsync", (test) => { test.plan(2); @@ -940,7 +944,7 @@ tape("rules", (test) => { }); }); -tape("validateConfigSchema", (test) => { +tape("validateJsonUsingConfigSchemaStrict", (test) => { const jsonFileRe = /\.json$/i; const resultsFileRe = /\.results\.json$/i; const jsConfigFileRe = /^jsconfig\.json$/i; @@ -958,12 +962,38 @@ tape("validateConfigSchema", (test) => { "utf8" ); test.ok( - tv4.validate(JSON.parse(data), configSchema), + // @ts-ignore + tv4.validate(JSON.parse(data), configSchemaStrict), file + "\n" + JSON.stringify(tv4.error, null, 2)); }); test.end(); }); +tape("validateConfigSchemaAllowsUnknownProperties", (test) => { + test.plan(4); + const testCases = [ + { + "property": true + }, + { + "property": { + "object": 1 + } + } + ]; + testCases.forEach((testCase) => { + test.ok( + // @ts-ignore + tv4.validate(testCase, configSchema), + "Unknown property blocked by default: " + JSON.stringify(testCase)); + test.notok( + // @ts-ignore + tv4.validate(testCase, configSchemaStrict), + "Unknown property allowed when strict: " + JSON.stringify(testCase)); + }); + test.end(); +}); + tape("configSingle", (test) => { test.plan(2); markdownlint.readConfig("./test/config/config-child.json",