@@ -699,19 +699,21 @@ export function complexityData(customDbPath, opts = {}) {
699699 params . push ( kindFilter ) ;
700700 }
701701
702+ const isValidThreshold = ( v ) => typeof v === 'number' && Number . isFinite ( v ) ;
703+
702704 let having = '' ;
703705 if ( aboveThreshold ) {
704706 const conditions = [ ] ;
705- if ( thresholds . cognitive ?. warn != null ) {
707+ if ( isValidThreshold ( thresholds . cognitive ?. warn ) ) {
706708 conditions . push ( `fc.cognitive >= ${ thresholds . cognitive . warn } ` ) ;
707709 }
708- if ( thresholds . cyclomatic ?. warn != null ) {
710+ if ( isValidThreshold ( thresholds . cyclomatic ?. warn ) ) {
709711 conditions . push ( `fc.cyclomatic >= ${ thresholds . cyclomatic . warn } ` ) ;
710712 }
711- if ( thresholds . maxNesting ?. warn != null ) {
713+ if ( isValidThreshold ( thresholds . maxNesting ?. warn ) ) {
712714 conditions . push ( `fc.max_nesting >= ${ thresholds . maxNesting . warn } ` ) ;
713715 }
714- if ( thresholds . maintainabilityIndex ?. warn != null ) {
716+ if ( isValidThreshold ( thresholds . maintainabilityIndex ?. warn ) ) {
715717 conditions . push (
716718 `fc.maintainability_index > 0 AND fc.maintainability_index <= ${ thresholds . maintainabilityIndex . warn } ` ,
717719 ) ;
@@ -758,14 +760,17 @@ export function complexityData(customDbPath, opts = {}) {
758760
759761 const functions = filtered . map ( ( r ) => {
760762 const exceeds = [ ] ;
761- if ( thresholds . cognitive ?. warn != null && r . cognitive >= thresholds . cognitive . warn )
763+ if ( isValidThreshold ( thresholds . cognitive ?. warn ) && r . cognitive >= thresholds . cognitive . warn )
762764 exceeds . push ( 'cognitive' ) ;
763- if ( thresholds . cyclomatic ?. warn != null && r . cyclomatic >= thresholds . cyclomatic . warn )
765+ if ( isValidThreshold ( thresholds . cyclomatic ?. warn ) && r . cyclomatic >= thresholds . cyclomatic . warn )
764766 exceeds . push ( 'cyclomatic' ) ;
765- if ( thresholds . maxNesting ?. warn != null && r . max_nesting >= thresholds . maxNesting . warn )
767+ if (
768+ isValidThreshold ( thresholds . maxNesting ?. warn ) &&
769+ r . max_nesting >= thresholds . maxNesting . warn
770+ )
766771 exceeds . push ( 'maxNesting' ) ;
767772 if (
768- thresholds . maintainabilityIndex ?. warn != null &&
773+ isValidThreshold ( thresholds . maintainabilityIndex ?. warn ) &&
769774 r . maintainability_index > 0 &&
770775 r . maintainability_index <= thresholds . maintainabilityIndex . warn
771776 )
@@ -817,10 +822,13 @@ export function complexityData(customDbPath, opts = {}) {
817822 minMI : + Math . min ( ...miValues ) . toFixed ( 1 ) ,
818823 aboveWarn : allRows . filter (
819824 ( r ) =>
820- ( thresholds . cognitive ?. warn != null && r . cognitive >= thresholds . cognitive . warn ) ||
821- ( thresholds . cyclomatic ?. warn != null && r . cyclomatic >= thresholds . cyclomatic . warn ) ||
822- ( thresholds . maxNesting ?. warn != null && r . max_nesting >= thresholds . maxNesting . warn ) ||
823- ( thresholds . maintainabilityIndex ?. warn != null &&
825+ ( isValidThreshold ( thresholds . cognitive ?. warn ) &&
826+ r . cognitive >= thresholds . cognitive . warn ) ||
827+ ( isValidThreshold ( thresholds . cyclomatic ?. warn ) &&
828+ r . cyclomatic >= thresholds . cyclomatic . warn ) ||
829+ ( isValidThreshold ( thresholds . maxNesting ?. warn ) &&
830+ r . max_nesting >= thresholds . maxNesting . warn ) ||
831+ ( isValidThreshold ( thresholds . maintainabilityIndex ?. warn ) &&
824832 r . maintainability_index > 0 &&
825833 r . maintainability_index <= thresholds . maintainabilityIndex . warn ) ,
826834 ) . length ,
0 commit comments