@@ -2124,6 +2124,105 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
21242124 */
21252125 let files = [ ] ;
21262126 let totalProjectStatementDocumented = 0 ;
2127+ const coverageExcludePatterns =
2128+ Configuration . mainData . coverageExclude || [ ] ;
2129+
2130+ const toUnixPath = ( filePath : string ) : string =>
2131+ ( filePath || "" ) . replace ( / \\ / g, "/" ) ;
2132+
2133+ const escapeRegex = ( value : string ) : string =>
2134+ value . replace ( / [ | \\ { } ( ) [ \] ^ $ + ? . ] / g, "\\$&" ) ;
2135+
2136+ const globToRegExp = ( globPattern : string ) : RegExp => {
2137+ const normalized = toUnixPath ( globPattern ) ;
2138+ const escaped = escapeRegex ( normalized )
2139+ . replace ( / \* \* / g, "::DOUBLE_STAR::" )
2140+ . replace ( / \* / g, "[^/]*" )
2141+ . replace ( / : : D O U B L E _ S T A R : : / g, ".*" ) ;
2142+ return new RegExp ( `^${ escaped } $` ) ;
2143+ } ;
2144+
2145+ const coverageExcludeRegexes = coverageExcludePatterns
2146+ . map ( ( pattern ) => String ( pattern || "" ) . trim ( ) )
2147+ . filter ( ( pattern ) => pattern . length > 0 )
2148+ . map ( ( pattern ) => globToRegExp ( pattern ) ) ;
2149+
2150+ const hasCoverageIgnoredTag = ( tags ) : boolean => {
2151+ if ( ! tags || ! Array . isArray ( tags ) ) {
2152+ return false ;
2153+ }
2154+
2155+ return tags . some ( ( tag ) => {
2156+ if ( ! tag ) {
2157+ return false ;
2158+ }
2159+
2160+ const explicitTagName =
2161+ tag . tagName ?. text ||
2162+ tag . tagName ?. escapedText ||
2163+ tag . tagName ||
2164+ tag . name ?. text ||
2165+ tag . name ||
2166+ "" ;
2167+
2168+ if ( explicitTagName ) {
2169+ return (
2170+ String ( explicitTagName ) . toLowerCase ( ) ===
2171+ "coverageignore"
2172+ ) ;
2173+ }
2174+
2175+ if ( typeof tag === "string" ) {
2176+ return tag . toLowerCase ( ) . indexOf ( "coverageignore" ) > - 1 ;
2177+ }
2178+
2179+ if ( typeof tag . label === "string" ) {
2180+ return (
2181+ tag . label . toLowerCase ( ) . indexOf ( "coverageignore" ) > - 1
2182+ ) ;
2183+ }
2184+
2185+ return false ;
2186+ } ) ;
2187+ } ;
2188+
2189+ const isCoverageIgnoredElement = ( element ) : boolean => {
2190+ if ( ! element ) {
2191+ return false ;
2192+ }
2193+
2194+ if ( element . coverageIgnore === true ) {
2195+ return true ;
2196+ }
2197+
2198+ if ( hasCoverageIgnoredTag ( element . jsdoctags ) ) {
2199+ return true ;
2200+ }
2201+
2202+ return false ;
2203+ } ;
2204+
2205+ const isCoverageIgnoredByFile = ( filePath : string ) : boolean => {
2206+ if ( ! coverageExcludeRegexes . length || ! filePath ) {
2207+ return false ;
2208+ }
2209+
2210+ const normalizedPath = toUnixPath ( filePath ) ;
2211+ return coverageExcludeRegexes . some ( ( regex ) =>
2212+ regex . test ( normalizedPath ) ,
2213+ ) ;
2214+ } ;
2215+
2216+ const shouldSkipCoverage = ( element ) : boolean => {
2217+ if ( ! element ) {
2218+ return true ;
2219+ }
2220+
2221+ return (
2222+ isCoverageIgnoredByFile ( element . file || element . filePath ) ||
2223+ isCoverageIgnoredElement ( element )
2224+ ) ;
2225+ } ;
21272226 const getStatus = function ( percent ) {
21282227 let status ;
21292228 if ( percent <= 25 ) {
@@ -2142,6 +2241,9 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
21422241 ) => {
21432242 _ . forEach ( list , ( el : any ) => {
21442243 const element = ( Object as any ) . assign ( { } , el ) ;
2244+ if ( shouldSkipCoverage ( element ) ) {
2245+ return ;
2246+ }
21452247 if ( ! element . propertiesClass ) {
21462248 element . propertiesClass = [ ] ;
21472249 }
@@ -2191,6 +2293,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
21912293 }
21922294
21932295 _ . forEach ( element . propertiesClass , ( property : any ) => {
2296+ if ( isCoverageIgnoredElement ( property ) ) {
2297+ totalStatements -= 1 ;
2298+ return ;
2299+ }
21942300 if (
21952301 property . modifierKind === SyntaxKind . PrivateKeyword
21962302 ) {
@@ -2206,6 +2312,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
22062312 }
22072313 } ) ;
22082314 _ . forEach ( element . methodsClass , ( method : any ) => {
2315+ if ( isCoverageIgnoredElement ( method ) ) {
2316+ totalStatements -= 1 ;
2317+ return ;
2318+ }
22092319 if ( method . modifierKind === SyntaxKind . PrivateKeyword ) {
22102320 // Doesn't handle private for coverage
22112321 totalStatements -= 1 ;
@@ -2219,6 +2329,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
22192329 }
22202330 } ) ;
22212331 _ . forEach ( element . hostBindings , ( property : any ) => {
2332+ if ( isCoverageIgnoredElement ( property ) ) {
2333+ totalStatements -= 1 ;
2334+ return ;
2335+ }
22222336 if (
22232337 property . modifierKind === SyntaxKind . PrivateKeyword
22242338 ) {
@@ -2234,6 +2348,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
22342348 }
22352349 } ) ;
22362350 _ . forEach ( element . hostListeners , ( method : any ) => {
2351+ if ( isCoverageIgnoredElement ( method ) ) {
2352+ totalStatements -= 1 ;
2353+ return ;
2354+ }
22372355 if ( method . modifierKind === SyntaxKind . PrivateKeyword ) {
22382356 // Doesn't handle private for coverage
22392357 totalStatements -= 1 ;
@@ -2247,6 +2365,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
22472365 }
22482366 } ) ;
22492367 _ . forEach ( element . inputsClass , ( input : any ) => {
2368+ if ( isCoverageIgnoredElement ( input ) ) {
2369+ totalStatements -= 1 ;
2370+ return ;
2371+ }
22502372 if ( input . modifierKind === SyntaxKind . PrivateKeyword ) {
22512373 // Doesn't handle private for coverage
22522374 totalStatements -= 1 ;
@@ -2260,6 +2382,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
22602382 }
22612383 } ) ;
22622384 _ . forEach ( element . outputsClass , ( output : any ) => {
2385+ if ( isCoverageIgnoredElement ( output ) ) {
2386+ totalStatements -= 1 ;
2387+ return ;
2388+ }
22632389 if ( output . modifierKind === SyntaxKind . PrivateKeyword ) {
22642390 // Doesn't handle private for coverage
22652391 totalStatements -= 1 ;
@@ -2324,6 +2450,9 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
23242450 } ;
23252451 let processFunctionsAndVariables = ( id , type ) => {
23262452 _ . forEach ( id , ( el : any ) => {
2453+ if ( shouldSkipCoverage ( el ) ) {
2454+ return ;
2455+ }
23272456 let cl : any = {
23282457 filePath : el . file ,
23292458 type : type ,
@@ -2367,6 +2496,9 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
23672496 let processClasses = ( list , type , linktype ) => {
23682497 _ . forEach ( list , ( cl : any ) => {
23692498 let element = ( Object as any ) . assign ( { } , cl ) ;
2499+ if ( shouldSkipCoverage ( element ) ) {
2500+ return ;
2501+ }
23702502 if ( ! element . properties ) {
23712503 element . properties = [ ] ;
23722504 }
@@ -2398,6 +2530,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
23982530 }
23992531
24002532 _ . forEach ( element . properties , ( property : any ) => {
2533+ if ( isCoverageIgnoredElement ( property ) ) {
2534+ totalStatements -= 1 ;
2535+ return ;
2536+ }
24012537 if (
24022538 property . modifierKind === SyntaxKind . PrivateKeyword
24032539 ) {
@@ -2413,6 +2549,10 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
24132549 }
24142550 } ) ;
24152551 _ . forEach ( element . methods , ( method : any ) => {
2552+ if ( isCoverageIgnoredElement ( method ) ) {
2553+ totalStatements -= 1 ;
2554+ return ;
2555+ }
24162556 if ( method . modifierKind === SyntaxKind . PrivateKeyword ) {
24172557 // Doesn't handle private for coverage
24182558 totalStatements -= 1 ;
@@ -2472,6 +2612,9 @@ at least one config for the 'info' or 'source' tab in --navTabConfig.`);
24722612 ) ;
24732613
24742614 _ . forEach ( Configuration . mainData . pipes , ( pipe : any ) => {
2615+ if ( shouldSkipCoverage ( pipe ) ) {
2616+ return ;
2617+ }
24752618 let cl : any = {
24762619 filePath : pipe . file ,
24772620 type : pipe . type ,
0 commit comments