Repository navigation
Fix CI: desktop import check skips regexes and compares whole names - #464
Merged
Merged
Conversation
…p-modules.mjs index ebd93d4..0c8b0ab 100755 --- a/scripts/check-desktop-modules.mjs +++ b/scripts/check-desktop-modules.mjs @@ -30,10 +30,20 @@ function escapeRegExp(text) { return text.replace(/[\\^$.*+?()[\]{}|\/-]/g, "\\$&"); } -/** Source without comments and string/regex contents (rough, line-preserving). */ +/** + * Source without comments and string/regex contents (rough, line-preserving). + * A regex literal is a `/…/` where an expression starts (after `(`, `,`, `=`, + * `:`, `[`, `!`, `&`, `|`, `?`, `{`, `}`, `;`, `return` or at the start of a + * line) – its `$`, `^` and words are no uses of names (`/^\d+$/` is no `$`). + * Regexes go before strings, so a quote inside a regex starts no string. + */ function code(text) { return text .replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, " ")) + .replace( + /(^|[=(,:[!&|?{};]|\breturn)(\s*)\/(?![*/])(?:\\.|\[(?:\\.|[^\]\\\n])*\]|[^/\\\n[])+\/[dgimsuyv]*/gm, + (m, pre, space) => pre + space + "/" + " ".repeat(Math.max(0, m.length - pre.length - space.length - 2)) + "/" + ) .replace(/"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*'|`(?:\\.|[^`\\])*`/g, (m) => '""' + " ".repeat(Math.max(0, m.length - 2))) .replace(/\/\/[^\n]*/g, ""); } @@ -122,8 +132,9 @@ for (const [f, m] of Object.entries(mods)) { if (!o || o === f || m.imports.has(n) || local.has(n)) continue; // a shared module can only use shared names (a desktop name is a word in a regex or text) if (m.shared && !mods[o].shared) continue; - // an object key ({ name: … }) is not a use - if (new RegExp(`(^|[^.\\w$])${escapeRegExp(n)}(?!\\s*:)`, "m").test(m.body)) { + // the whole name (`el` is no use inside `else`); an object key + // ({ name: … }) is not a use + if (new RegExp(`(^|[^.\\w$])${escapeRegExp(n)}(?![\\w$])(?!\\s*:)`, "m").test(m.body)) { errors.push(`${f}: uses ${n} of ${o} without importing it`); } }
scripts/check-desktop-modules.mjs failed the desktop UI job on main (c2a7f86) with false uses: the $ in regex literals like /^\d+$/ (bom-lines.js, checkin-bom.js, report-inputs.js) counted as a use of core.js's $, and the start of 'else' as a use of dom.js's new el. code() now blanks regex literals (before strings, line-preserving), and the final use test requires the whole name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The desktop UI job on main (c2a7f86) now gets past the syntax check and fails in
scripts/check-desktop-modules.mjs– with uses that are none:bom-lines.js,checkin-bom.js,report-inputs.js: uses $ of core.js – the$is inside regex literals (/^\d+$/).code()blanked comments and strings but not regexes, although its comment said so.bom-lines.js: uses el of dom.js – the final test looked for the name without a word boundary after it, so the start ofelsematched (dom.jsexportselsince recently).Fix in the check, not in the modules:
code()blanks regex literals (a/…/where an expression starts; before strings, so a quote in a regex starts no string; line-preserving), and the use test requires the whole name. CHANGELOG entry.Not run locally (no Node here) – the
uijob runs it; if a later step of that job still fails, it is the first time those steps run on main since the syntax error.🤖 Generated with Claude Code