Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ see the notices in the README.

### Fixed

- CI: the import check of the desktop modules (`scripts/check-desktop-modules.mjs`)
reported uses that are none – a `$` inside a regular expression (`/^\d+$/`)
as a use of `core.js`'s `$`, and the start of `else` as a use of
`shared/js/dom.js`'s `el` – and failed the *desktop UI* job. It now skips
regex contents and compares whole names.
- Desktop: `desktop/ui/js/revision.js` started with three stray lines (a
copy of its data block, left by a merge), so the file did not parse – the
Revision tab could not load, and the *desktop UI* check failed on `main`.
Expand Down
17 changes: 14 additions & 3 deletions scripts/check-desktop-modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}
Expand Down Expand Up @@ -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`);
}
}
Expand Down
Loading