perf(linter): lazily normalize capitalized-comments text (#28481)

Instead of eagerly normalizing text (causing allocations), only
normalize text when first accessed.

On local fixtures:


Metric | Before → After
-- | --
Allocations | 187,675 → 157,156 (−16.3%)
Allocated bytes | 17,279,585 → 15,605,488 (−9.7%)
Maximum peak bytes | 11,334,860 → 11,334,440

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Cam McHenryandCopilot authored and GitHub committed 2026-10-30 12:26:34 -04:00
1 parent 6baaad639f
commit d8374148d6
1 file changed
+3 -1
@@ -1,3 +1,5 @@
use std::cell::LazyCell;
use lazy_regex::{Regex, RegexBuilder};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -207,7 +209,7 @@ impl Rule for CapitalizedComments {
// Normalize the content: remove leading whitespace and JSDoc-style * markers
// This is what ESLint calls "getTextWithoutAsterisks"
let normalized = normalize_comment_text(content);
let normalized = LazyCell::new(|| normalize_comment_text(content));
// Find the first letter position in original content
let Some((first_letter_offset, first_letter)) = find_first_letter(content) else {