From 12832e3a98138b45b94a376f9f324cb44667c5ba Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Sat, 14 Nov 2026 23:43:21 +0000 Subject: [PATCH] perf(lint): rules scan script, style and comment blocks in linear time (#7770) * perf(lint): rules scan script, style and comment blocks in linear time Several always-on rules matched open/any/close regexes over the whole document, which rescan to the end from every unclosed opener, so lint time grew with the square of the page on pages of unclosed openers lintHyperframeHtml drops from about 2.6 s to 45 ms. Co-Authored-By: Claude Opus 5.5 * test(lint): compare each fuzz page in one assertion so the run fits the default timeout Co-Authored-By: Claude Opus 5.5 * chore(player): raise the packed size budget for the bundled slideshow island scan Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- packages/lint/src/linearScans.test.ts | 156 ++++++++++++++++++ packages/lint/src/linearScans.ts | 130 +++++++++++++++ packages/lint/src/rules/composition.ts | 13 +- packages/lint/src/rules/core.ts | 76 +++------ packages/lint/src/rules/gsap.ts | 3 +- packages/lint/src/utils.ts | 1 - .../src/slideshow/parseSlideshow.test.ts | 53 ++++++ .../parsers/src/slideshow/parseSlideshow.ts | 26 ++- scripts/package-size-budgets.json | 2 +- 9 files changed, 390 insertions(+), 70 deletions(-) create mode 100644 packages/lint/src/linearScans.test.ts create mode 100644 packages/lint/src/linearScans.ts diff --git a/packages/lint/src/linearScans.test.ts b/packages/lint/src/linearScans.test.ts new file mode 100644 index 0000000000..f356f77d07 --- /dev/null +++ b/packages/lint/src/linearScans.test.ts @@ -0,0 +1,156 @@ +import { isDeepStrictEqual } from "node:util"; +import { describe, expect, it } from "vitest"; +import { + blockComments, + emptyStyleBlocks, + hasInvalidScriptClose, + hasScriptWithSrc, + htmlTagTracker, + protectedBlockRanges, + replaceBlockComments, + styleTagTokens, +} from "./linearScans"; + +const PATTERNS = { + blockComment: /\/\*[\s\S]*?\*\//g, + invalidScriptClose: /]*>[\s\S]*?<\s*\/\s*script(?!>)/i, + scriptWithSrc: /]*\bsrc\s*=/i, + styleBlock: /]*>[\s\S]*?<\/style>/gi, + styleTokens: /]*>|/gi, + protectedBlock: + /<(style|script|template|title|noscript|pre|code|textarea|text)\b[^>]*>[\s\S]*?<\/\1(?:\s[^>]*)?>/gi, +}; + +function insideHtmlTag(source: string, index: number): boolean { + let inTag = false; + let quote: string | null = null; + for (let i = 0; i < index; i++) { + const char = source[i]; + if (!inTag) { + if (char === "<") inTag = true; + continue; + } + if (quote) { + if (char === quote) quote = null; + continue; + } + if (char === '"' || char === "'") quote = char; + else if (char === ">") inTag = false; + } + return inTag; +} + +const TOKENS = [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "