Skip to content

Commit 964151e

Browse files
authored
feat(core): support x- extensions in the ruleset (#2440)
1 parent c6be1c6 commit 964151e

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

packages/core/src/ruleset/meta/rule.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
},
8585
"required": ["given", "then"],
8686
"additionalProperties": false,
87+
"patternProperties": {
88+
"^x-": true
89+
},
8790
"errorMessage": {
8891
"required": "the rule must have at least \"given\" and \"then\" properties"
8992
}

packages/core/src/ruleset/meta/ruleset.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@
190190
}
191191
}
192192
},
193+
"patternProperties": {
194+
"^x-": true
195+
},
193196
"anyOf": [
194197
{
195198
"required": ["extends"]

packages/core/src/ruleset/validation/__tests__/validation.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ describe('JS Ruleset Validation', () => {
119119
).not.toThrow();
120120
});
121121

122+
it('allows x- extensions on a ruleset', () => {
123+
expect(
124+
assertValidRuleset.bind(null, {
125+
rules: {},
126+
'x-internal': true,
127+
'x-vars': {
128+
foo: 'bar',
129+
},
130+
}),
131+
).not.toThrow();
132+
});
133+
122134
it.each(['error', 'warn', 'info', 'hint', 'off'])('recognizes human-readable %s severity', severity => {
123135
expect(
124136
assertValidRuleset.bind(null, {
@@ -843,6 +855,26 @@ describe('JS Ruleset Validation', () => {
843855
);
844856
});
845857
});
858+
859+
it('allows x- extensions on a rule', () => {
860+
expect(
861+
assertValidRuleset.bind(null, {
862+
rules: {
863+
rule: {
864+
given: '$',
865+
then: {
866+
field: 'test',
867+
function: truthy,
868+
},
869+
'x-internal': true,
870+
'x-vars': {
871+
foo: 'bar',
872+
},
873+
},
874+
},
875+
}),
876+
).not.toThrow();
877+
});
846878
});
847879

848880
// we only check the most notable differences here, since the rest of the validation process is common to both JS and JSON

0 commit comments

Comments
 (0)