@@ -15,45 +15,72 @@ export class APIVersion extends RuleCommon implements IRuleDefinition {
1515 }
1616
1717 protected check (
18- flow : core . Flow ,
19- options : { expression ?: string } | undefined ,
20- _suppressions : Set < string >
21- ) : core . Violation [ ] {
22-
23- let flowAPIVersionNumber : number | null = null ;
24- if ( flow . xmldata . apiVersion ) {
25- flowAPIVersionNumber = + flow . xmldata . apiVersion ;
26- }
18+ flow : core . Flow ,
19+ options : { expression ?: string } | undefined ,
20+ _suppressions : Set < string >
21+ ) : core . Violation [ ] {
2722
28- // No API version
29- if ( ! flowAPIVersionNumber ) {
30- return [
31- new core . Violation (
32- new core . FlowAttribute ( "API Version <49" , "apiVersion" , "<49" )
33- )
34- ] ;
35- }
23+ let flowAPIVersionNumber : number | null = null ;
24+ if ( flow . xmldata . apiVersion ) {
25+ flowAPIVersionNumber = + flow . xmldata . apiVersion ;
26+ }
3627
37- // Custom logic
38- if ( options ?. expression ) {
39- const isValid = new Function (
40- `return ${ flowAPIVersionNumber } ${ options . expression } ;`
41- ) ( ) ;
42-
43- if ( ! isValid ) {
28+ // No API version
29+ if ( ! flowAPIVersionNumber ) {
4430 return [
4531 new core . Violation (
46- new core . FlowAttribute (
47- `${ flowAPIVersionNumber } ` ,
48- "apiVersion" ,
49- options . expression
50- )
32+ new core . FlowAttribute ( "API Version <49" , "apiVersion" , "<49" )
5133 )
5234 ] ;
5335 }
54- }
5536
56- return [ ] ;
57- }
37+ // Custom logic
38+ if ( options ?. expression ) {
39+
40+ // Match something like: >= 58
41+ const match = options . expression . match ( / ^ \s * ( > = | < = | > | < | = = = | ! = = ) \s * ( \d + ) \s * $ / ) ;
42+
43+ if ( ! match ) {
44+ // Invalid expression format
45+ return [
46+ new core . Violation (
47+ new core . FlowAttribute (
48+ "Invalid API rule expression" ,
49+ "apiVersion" ,
50+ options . expression
51+ )
52+ )
53+ ] ;
54+ }
55+
56+ const [ , operator , versionStr ] = match ;
57+ const target = parseFloat ( versionStr ) ;
58+
59+ let isValid = true ;
60+
61+ switch ( operator ) {
62+ case ">" : isValid = flowAPIVersionNumber > target ; break ;
63+ case "<" : isValid = flowAPIVersionNumber < target ; break ;
64+ case ">=" : isValid = flowAPIVersionNumber >= target ; break ;
65+ case "<=" : isValid = flowAPIVersionNumber <= target ; break ;
66+ case "===" : isValid = flowAPIVersionNumber === target ; break ;
67+ case "!==" : isValid = flowAPIVersionNumber !== target ; break ;
68+ }
69+
70+ if ( ! isValid ) {
71+ return [
72+ new core . Violation (
73+ new core . FlowAttribute (
74+ `${ flowAPIVersionNumber } ` ,
75+ "apiVersion" ,
76+ options . expression
77+ )
78+ )
79+ ] ;
80+ }
81+ }
82+
83+ return [ ] ;
84+ }
5885
5986}
0 commit comments