33export function validateCommitOrder ( positions : string [ ] ) : boolean {
44 // loop over positions
55 const errors : number [ ] = [ ] ;
6- let previous = { level : 0 , step : 0 } ;
7- let current = { level : 0 , step : 0 } ;
6+ let previous = { level : 0 , step : 0 , type : "" } ;
7+ let current = { level : 0 , step : 0 , type : "" } ;
88 positions . forEach ( ( position : string , index : number ) => {
99 if ( position === "INIT" ) {
1010 if ( previous . level !== 0 && previous . step !== 0 ) {
1111 errors . push ( index ) ;
1212 }
13- current = { level : 0 , step : 0 } ;
13+ current = { level : 0 , step : 0 , type : "" } ;
1414 return ;
1515 } else {
1616 // @deprecate - remove L|Q
1717 const levelMatch = position . match ( / ^ (?< level > [ 0 - 9 ] + ) $ / ) ;
1818 // @deprecate - remove S|Q|A
1919 const stepMatch = position . match (
20- / ^ (?< level > [ 0 - 9 ] + ) \. (?< step > [ 0 - 9 ] + ) : [ T | S ] $ /
20+ / ^ (?< level > [ 0 - 9 ] + ) \. (?< step > [ 0 - 9 ] + ) : (?< stepType > [ T | S ] ) $ /
2121 ) ;
2222 if ( levelMatch ) {
2323 // allows next level or step
@@ -27,7 +27,7 @@ export function validateCommitOrder(positions: string[]): boolean {
2727 return ;
2828 }
2929 const level = Number ( levelString ) ;
30- current = { level, step : 0 } ;
30+ current = { level, step : 0 , type : "" } ;
3131 } else if ( stepMatch ) {
3232 // allows next level or step
3333 if ( ! stepMatch ?. groups ?. level || ! stepMatch ?. groups . step ) {
@@ -38,13 +38,26 @@ export function validateCommitOrder(positions: string[]): boolean {
3838
3939 const level = Number ( levelString ) ;
4040 const step = Number ( stepString ) ;
41- current = { level, step } ;
41+ const type = stepMatch ?. groups . stepType ;
42+
43+ const sameStep = previous . level === level && previous . step === step ;
44+
45+ if (
46+ // tests should come before the solution
47+ ( sameStep && type === "T" && previous . type === "S" ) ||
48+ // step should have tests
49+ ( ! sameStep && type === "S" )
50+ ) {
51+ errors . push ( index ) ;
52+ }
53+ current = { level, step, type } ;
4254 } else {
4355 // error
4456 console . warn ( `Invalid commit position: ${ position } ` ) ;
4557 return ;
4658 }
4759 if (
60+ // levels or steps are out of order
4861 current . level < previous . level ||
4962 ( current . level === previous . level && current . step < previous . step )
5063 ) {
0 commit comments