@@ -12,6 +12,10 @@ export const ReportCategory = {
1212 * Follows the Strategy pattern for different report formats
1313 */
1414export class BaseParser {
15+ constructor ( ) {
16+ this . _autoPatternRegexCache = null ;
17+ }
18+
1519 /**
1620 * Build glob patterns for file basenames matched anywhere in the workspace.
1721 * @param {string[] } baseNames - File basenames to match
@@ -66,6 +70,52 @@ export class BaseParser {
6670 return extensions . map ( ( extension ) => `**/*.${ extension } ` ) ;
6771 }
6872
73+ /**
74+ * Check if a file path matches this parser auto-detection patterns.
75+ * @param {string } filePath - Path to evaluate
76+ * @returns {boolean } True if path matches any auto pattern
77+ */
78+ matchesAutoPatterns ( filePath ) {
79+ if ( ! filePath ) {
80+ return false ;
81+ }
82+
83+ const normalizedPath = this . _normalizeFilePath ( filePath ) . toLowerCase ( ) ;
84+ const matchers = this . _getAutoPatternRegexes ( ) ;
85+
86+ return matchers . some ( ( matcher ) => matcher . test ( normalizedPath ) ) ;
87+ }
88+
89+ _getAutoPatternRegexes ( ) {
90+ if ( this . _autoPatternRegexCache ) {
91+ return this . _autoPatternRegexCache ;
92+ }
93+
94+ const patterns = this . getAutoPatterns ( ) ;
95+ this . _autoPatternRegexCache = patterns . map ( ( pattern ) =>
96+ this . _globToRegex ( pattern ) ,
97+ ) ;
98+
99+ return this . _autoPatternRegexCache ;
100+ }
101+
102+ _normalizeFilePath ( filePath ) {
103+ return String ( filePath ) . replace ( / \\ / g, "/" ) ;
104+ }
105+
106+ _globToRegex ( pattern ) {
107+ const escapedPattern = pattern
108+ . toLowerCase ( )
109+ . replace ( / [ - [ \] { } ( ) + ? . , \\ ^ $ | # \s ] / g, "\\$&" )
110+ . replace ( / \* \* \/ / g, "<<<ANY_DIR_PREFIX>>>" )
111+ . replace ( / \* \* / g, "<<<ANY_DIR>>>" )
112+ . replace ( / \* / g, "[^/]*" )
113+ . replace ( / < < < A N Y _ D I R _ P R E F I X > > > / g, "(?:.*/)?" )
114+ . replace ( / < < < A N Y _ D I R > > > / g, ".*" ) ;
115+
116+ return new RegExp ( `^${ escapedPattern } $` , "i" ) ;
117+ }
118+
69119 /**
70120 * Parse a report file
71121 * @param {string } content - The file content
0 commit comments