Skip to content

Commit

Permalink
feat(core): support x- extensions in the ruleset (#2440)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Mar 23, 2023
1 parent c6be1c6 commit 964151e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/ruleset/meta/rule.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
},
"required": ["given", "then"],
"additionalProperties": false,
"patternProperties": {
"^x-": true
},
"errorMessage": {
"required": "the rule must have at least \"given\" and \"then\" properties"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/ruleset/meta/ruleset.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@
}
}
},
"patternProperties": {
"^x-": true
},
"anyOf": [
{
"required": ["extends"]
Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/ruleset/validation/__tests__/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 964151e

Please sign in to comment.