File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed
packages/core/src/ruleset Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -315,6 +315,30 @@ describe('Ruleset', () => {
315315` ) ;
316316 } ) ;
317317
318+ it ( 'should respect extensions' , async ( ) => {
319+ const ruleset = {
320+ rules : {
321+ 'foo-rule' : {
322+ given : '$' ,
323+ then : {
324+ function ( ) {
325+ return ;
326+ } ,
327+ } ,
328+ extensions : {
329+ foo : 'bar' ,
330+ } ,
331+ } ,
332+ } ,
333+ } ;
334+
335+ const rulesetInstance = new Ruleset ( ruleset ) ;
336+
337+ expect ( rulesetInstance . rules [ 'foo-rule' ] . extensions ) . toEqual ( {
338+ foo : 'bar' ,
339+ } ) ;
340+ } ) ;
341+
318342 it ( 'should include parserOptions' , async ( ) => {
319343 const { parserOptions } = await loadRuleset ( import ( './__fixtures__/parser-options-ruleset' ) ) ;
320344
Original file line number Diff line number Diff line change 7777 "enum" : [" style" , " validation" ],
7878 "type" : " string" ,
7979 "errorMessage" : " allowed types are \" style\" and \" validation\" "
80+ },
81+ "extensions" : {
82+ "type" : " object"
8083 }
8184 },
8285 "required" : [" given" , " then" ],
Original file line number Diff line number Diff line change @@ -24,9 +24,10 @@ export interface IRule {
2424 documentationUrl : string | null ;
2525 then : IRuleThen [ ] ;
2626 given : string [ ] ;
27+ extensions : Record < string , unknown > | null ;
2728}
2829
29- type RuleJson = Omit < IRule , 'then' > & {
30+ type RuleJson = Omit < IRule , 'then' | 'extensions' > & {
3031 name : string ;
3132 then : ( Pick < IRuleThen , 'field' > & { function : string ; functionOptions ?: string } ) [ ] ;
3233 owner : number ;
@@ -43,6 +44,7 @@ export class Rule implements IRule {
4344 #enabled: boolean ;
4445 public recommended : boolean ;
4546 public documentationUrl : string | null ;
47+ public extensions : Record < string , unknown > | null ;
4648 #then! : IRuleThen [ ] ;
4749 #given! : string [ ] ;
4850
@@ -61,6 +63,7 @@ export class Rule implements IRule {
6163 this . formats = 'formats' in definition ? new Formats ( definition . formats ) : null ;
6264 this . then = definition . then ;
6365 this . given = definition . given ;
66+ this . extensions = definition . extensions ?? null ;
6467 }
6568
6669 public overrides ?: { rulesetSource : string ; definition : Map < string , Map < string , DiagnosticSeverity | - 1 > > } ;
Original file line number Diff line number Diff line change @@ -42,6 +42,9 @@ export type RuleDefinition = {
4242 resolved ?: boolean ;
4343
4444 then : IRuleThen | IRuleThen [ ] ;
45+
46+ // User extensions/metadata point
47+ extensions ?: Record < string , unknown > ;
4548} ;
4649
4750export interface IRuleThen {
You can’t perform that action at this time.
0 commit comments