Conversation
The isExcluded() method in codeLensProvider.ts converted glob patterns to regular expressions but did not escape regex metacharacters (. + ? ^ $ etc.) present in the literal parts of the pattern. As a result a pattern like `**/*.min.js` compiled to `^.*/[^/]*.[^/]*.[^/]*$` where each `.` acted as a wildcard instead of matching a literal dot. This meant a file such as `fooXminXjs` would incorrectly be excluded. Fix: save `**` and `*` wildcards as null-byte placeholders before calling the standard regex escape (replace special chars with their escaped form), then restore the placeholders as their intended regex tokens. This ensures only the wildcard tokens are special; all other characters are matched literally. Also correct the JSDoc on UnifiedFunctionMetrics.startLine / endLine from "1-based" to "0-based", matching the actual values returned by all language analyzers (and confirmed by the unit test assertion on line 610 of csharpAnalyzer.test.ts). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes incorrect exclusions caused by unescaped regex metacharacters when converting glob exclude patterns to RegExp in the CodeLens provider, and aligns UnifiedFunctionMetrics position docs with actual 0-based analyzer output.
Changes:
- Escape regex metacharacters in glob-to-regex conversion while preserving
*/**wildcard semantics via placeholders. - Apply the same escaping logic to the filename-only matching branch.
- Correct
UnifiedFunctionMetrics.startLine/endLineJSDoc to indicate 0-based line numbers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/providers/codeLensProvider.ts | Makes glob exclude matching safe by escaping regex metacharacters while preserving wildcard tokens. |
| src/metricsAnalyzer/metricsAnalyzerFactory.ts | Updates JSDoc to reflect 0-based function boundary line numbering used throughout analyzers/consumers. |
Agent-Logs-Url: https://github.com/askpt/code-metrics/sessions/0a12dec2-17a9-4391-9323-587776d4a82c Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #235 +/- ##
==========================================
- Coverage 67.45% 67.26% -0.19%
==========================================
Files 8 8
Lines 2928 2936 +8
Branches 276 276
==========================================
Hits 1975 1975
- Misses 951 959 +8
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot increase the code coverage: #235 (comment) |
Agent-Logs-Url: https://github.com/askpt/code-metrics/sessions/27972a80-bcb9-4394-b0f0-89773ca29bbe Co-authored-by: askpt <2493377+askpt@users.noreply.github.com>
Added coverage for the filename-only branch (patterns without a
Combined with the earlier full-path branch cases ( |
🤖 This is an automated PR from Repo Assist.
Problem
isExcluded()incodeLensProvider.tsconverts glob exclude patterns to regular expressions but does not escape regex metacharacters in the literal portions of the pattern.For example, the default pattern
**/*.min.jswas compiled into the regex:Each literal
.acts as a regex wildcard (matches any character), so a file likepath/to/fooXminXjswould incorrectly match and be excluded. Similarly, patterns like**/*.test.*or**/*.spec.*could exclude unexpected files.Fix
Save
**and*wildcard tokens as null-byte placeholders before calling the standard regex-escape step, then restore the placeholders as their intended regex tokens (.*/[^/]*). This ensures only the intended wildcard tokens are special; all other characters in the pattern (including.) are matched literally.Before:
After:
The same fix is applied to the filename-only branch.
Also included
Corrected the JSDoc on
UnifiedFunctionMetrics.startLine/endLinefrom"(1-based)"to"(0-based)". The language analyzers return 0-based line numbers for function boundaries (as confirmed by the existing assertionresults[0].startLine === 1 // 0-based line numberon line 610 ofcsharpAnalyzer.test.ts), andcreateAnalyzerpasses them through without normalization.Added unit tests to
codeLensProvider.test.tsverifying that literal dots in glob patterns are matched literally and not as regex wildcards — covering both the full-path branch (patterns with a/) and the filename-only branch (patterns without a/):**/*.min.jsexcludesfoo.min.jsbut does not excludefooXminXjs;**/*.spec.*excludesapp.spec.tsbut does not excludeappXspecXts*.generated.*does not excludefooXgeneratedXcs;*.min.jsexcludesfoo.min.jsbut does not excludefooXminXjsTest Status
npm run compile— passes with no errorsnpm run lint— passes with no warningsnpm test— requires VS Code binary download (sandboxed environment); existing tests cover theisExcludedpatterns including*.generated.*,**/bin/**, andtest*and all continue to pass logically with the fix (verified manually)