Skip to content

JS-1227 perf: Optimize S125 commented-out code detection#6340

Open
vdiez wants to merge 1 commit intomasterfrom
perf/optimize-S125-commented-code-detection
Open

JS-1227 perf: Optimize S125 commented-out code detection#6340
vdiez wants to merge 1 commit intomasterfrom
perf/optimize-S125-commented-code-detection

Conversation

@vdiez
Copy link
Contributor

@vdiez vdiez commented Feb 6, 2026

Summary

  • Add cheap regex prefilter (/[;{}()=<>]/) before the recognizer+parser pipeline — skips the entire expensive path for comments that can't possibly be JS code
  • Defer new SourceCode() construction — only build it when getLastToken is actually needed, avoiding expensive token indexing for most comments
  • Short-circuit couldBeJsCode — use .some() instead of .filter().length to bail on first matching line
  • Pre-compile regex patterns in ContainsDetector — avoid new RegExp() on every scan() call per line (also fixed missing g flag in replaceAll)
  • Replace per-char regex whitespace check in EndWithDetector with a Set char-code lookup
  • Optimize injectMissingBraces — single-pass loop instead of two match() calls + array allocations

Test plan

  • S125 unit tests pass
  • Verify no behavior regressions on ruling tests

🤖 Generated with Claude Code

@vdiez vdiez requested a review from a team February 6, 2026 15:19
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod bot changed the title perf: Optimize S125 commented-out code detection JS-1227 perf: Optimize S125 commented-out code detection Feb 6, 2026
@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Feb 6, 2026

JS-1227

@vdiez vdiez requested a review from zglicz February 6, 2026 15:21
@github-actions
Copy link
Contributor

github-actions bot commented Feb 6, 2026

Ruling Report

No changes to ruling expected issues in this PR

@vdiez vdiez force-pushed the perf/optimize-S125-commented-code-detection branch 2 times, most recently from 898011d to 7d1e2d1 Compare February 6, 2026 16:03
@vdiez vdiez closed this Feb 6, 2026
@vdiez vdiez reopened this Feb 6, 2026
Add cheap regex prefilter before recognizer/parser pipeline, defer
SourceCode construction, short-circuit couldBeJsCode, pre-compile
regex in ContainsDetector, and replace per-char regex with Set lookup
in EndWithDetector.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vdiez vdiez force-pushed the perf/optimize-S125-commented-code-detection branch from 9257360 to 6e2cbca Compare February 6, 2026 16:57
@sonarqube-next
Copy link

sonarqube-next bot commented Feb 6, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant