From 964151e73b6cc3c0b7c960eac3711ffbeac690ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Thu, 23 Mar 2023 18:46:23 +0100 Subject: [PATCH] feat(core): support x- extensions in the ruleset (#2440) --- .../core/src/ruleset/meta/rule.schema.json | 3 ++ .../core/src/ruleset/meta/ruleset.schema.json | 3 ++ .../validation/__tests__/validation.test.ts | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/packages/core/src/ruleset/meta/rule.schema.json b/packages/core/src/ruleset/meta/rule.schema.json index 48a0edaf8..d5c0700b8 100644 --- a/packages/core/src/ruleset/meta/rule.schema.json +++ b/packages/core/src/ruleset/meta/rule.schema.json @@ -84,6 +84,9 @@ }, "required": ["given", "then"], "additionalProperties": false, + "patternProperties": { + "^x-": true + }, "errorMessage": { "required": "the rule must have at least \"given\" and \"then\" properties" } diff --git a/packages/core/src/ruleset/meta/ruleset.schema.json b/packages/core/src/ruleset/meta/ruleset.schema.json index c59654879..6fc6fccdb 100644 --- a/packages/core/src/ruleset/meta/ruleset.schema.json +++ b/packages/core/src/ruleset/meta/ruleset.schema.json @@ -190,6 +190,9 @@ } } }, + "patternProperties": { + "^x-": true + }, "anyOf": [ { "required": ["extends"] diff --git a/packages/core/src/ruleset/validation/__tests__/validation.test.ts b/packages/core/src/ruleset/validation/__tests__/validation.test.ts index a78f8eb60..001427667 100644 --- a/packages/core/src/ruleset/validation/__tests__/validation.test.ts +++ b/packages/core/src/ruleset/validation/__tests__/validation.test.ts @@ -119,6 +119,18 @@ describe('JS Ruleset Validation', () => { ).not.toThrow(); }); + it('allows x- extensions on a ruleset', () => { + expect( + assertValidRuleset.bind(null, { + rules: {}, + 'x-internal': true, + 'x-vars': { + foo: 'bar', + }, + }), + ).not.toThrow(); + }); + it.each(['error', 'warn', 'info', 'hint', 'off'])('recognizes human-readable %s severity', severity => { expect( assertValidRuleset.bind(null, { @@ -843,6 +855,26 @@ describe('JS Ruleset Validation', () => { ); }); }); + + it('allows x- extensions on a rule', () => { + expect( + assertValidRuleset.bind(null, { + rules: { + rule: { + given: '$', + then: { + field: 'test', + function: truthy, + }, + 'x-internal': true, + 'x-vars': { + foo: 'bar', + }, + }, + }, + }), + ).not.toThrow(); + }); }); // we only check the most notable differences here, since the rest of the validation process is common to both JS and JSON