From 38f017e4c6554707bff1618bb7ea12b61108c9f1 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Mon, 23 Nov 2026 23:57:08 -0500 Subject: [PATCH 1/4] Standardize homepage, AGENTS sections, and template pins. Set package homepage from the catalog, fill missing AGENTS headings, clear memory-leak inventory noise, and align knip/vitest with SceneryStackTemplate where drifted. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1864003..f7f2702 100644 --- a/package.json +++ b/package.json @@ -85,5 +85,6 @@ }, "allowScripts": { "@swc/core@1.16.22": true - } + }, + "homepage": "https://openlyceum.github.io/MolScope" } From e2e1a1bc32ecf269c4a6a220fd60ad824505a9b1 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 10:06:46 -0500 Subject: [PATCH 2/4] chore(biome): enforce no enum/namespace and as-const; sort package.json on fix Mirror erasableSyntaxOnly in the linter and enable useSortedPackageJson assist. --- biome.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/biome.json b/biome.json index 60bb205..f093ad4 100644 --- a/biome.json +++ b/biome.json @@ -3,7 +3,8 @@ "assist": { "actions": { "source": { - "organizeImports": "on" + "organizeImports": "on", + "useSortedPackageJson": "on" } } }, @@ -82,7 +83,9 @@ "style": { "noCommonJs": "error", "noDefaultExport": "off", + "noEnum": "error", "noExportedImports": "warn", + "noNamespace": "error", "noParameterAssign": "error", "preset": "recommended", "useBlockStatements": "error", @@ -98,6 +101,7 @@ "strictCase": false } }, + "useAsConstAssertion": "warn", "useForOf": "warn", "useImportType": "error", "useNamingConvention": { From 0486f5233d9583d54ccf85e3868a48c566d1ba91 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 12:18:51 -0500 Subject: [PATCH 3/4] Tie script message keys to their arguments --- src/common/model/ScriptEngine.ts | 61 ++++++++++++++++++------------ src/common/view/formatters.ts | 12 +++--- tests/common/script-engine.test.ts | 3 +- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/common/model/ScriptEngine.ts b/src/common/model/ScriptEngine.ts index 056ae22..5e659e0 100644 --- a/src/common/model/ScriptEngine.ts +++ b/src/common/model/ScriptEngine.ts @@ -43,13 +43,28 @@ export const ScriptMessageKey = { } as const; type ScriptMessageKeyValue = (typeof ScriptMessageKey)[keyof typeof ScriptMessageKey]; -export type ScriptMessage = { - readonly key: ScriptMessageKeyValue; - readonly isError: boolean; - /** Substitution values; the view decides the wording. */ - readonly args: Readonly>; +type ScriptMessageArgs = { + selected: { count: number }; + loaded: { title: string; count: number }; + loading: Record; + measured: { value: number; count: number }; + echo: { text: string }; + help: { commands: string }; + unknownCommand: { command: string }; + badSelection: { token: string }; + badArgument: { argument: string }; + noStructure: Record; + loadFailed: { reason: string }; }; +export type ScriptMessage = { + [Key in ScriptMessageKeyValue]: { + readonly key: Key; + readonly isError: boolean; + readonly args: Readonly; + }; +}[ScriptMessageKeyValue]; + /** Superseded work is neither a successful load nor a user-facing script error. */ export class ScriptCancelledError extends Error {} @@ -222,8 +237,12 @@ export class ScriptEngine { } messages.push( error instanceof SelectionSyntaxError - ? message(ScriptMessageKey.BAD_SELECTION, true, { token: error.token }) - : message(ScriptMessageKey.LOAD_FAILED, true, { reason: error instanceof Error ? error.message : "" }), + ? { key: ScriptMessageKey.BAD_SELECTION, isError: true, args: { token: error.token } } + : { + key: ScriptMessageKey.LOAD_FAILED, + isError: true, + args: { reason: error instanceof Error ? error.message : "" }, + }, ); break; } @@ -239,10 +258,10 @@ export class ScriptEngine { const first = args[0] ?? ""; if (verb === "help") { - return [message(ScriptMessageKey.HELP, false, { commands: COMMANDS.join(", ") })]; + return [{ key: ScriptMessageKey.HELP, isError: false, args: { commands: COMMANDS.join(", ") } }]; } if (verb === "echo") { - return [message(ScriptMessageKey.ECHO, false, { text: rest.replace(/^["']|["']$/g, "") })]; + return [{ key: ScriptMessageKey.ECHO, isError: false, args: { text: rest.replace(/^["']|["']$/g, "") } }]; } if (verb === "load") { return this.load(rest); @@ -263,8 +282,8 @@ export class ScriptEngine { const context = this.target.selectionContext(); if (!(state && context)) { return COMMANDS.includes(verb) - ? [message(ScriptMessageKey.NO_STRUCTURE, true, {})] - : [message(ScriptMessageKey.UNKNOWN_COMMAND, true, { command: head })]; + ? [{ key: ScriptMessageKey.NO_STRUCTURE, isError: true, args: {} }] + : [{ key: ScriptMessageKey.UNKNOWN_COMMAND, isError: true, args: { command: head } }]; } return this.executeStructureCommand(verb, rest, args, first, head, state, context); @@ -342,7 +361,7 @@ export class ScriptEngine { this.target.centerOn(rest ? evaluateSelection(rest, context) : null); return []; default: - return [message(ScriptMessageKey.UNKNOWN_COMMAND, true, { command: head })]; + return [{ key: ScriptMessageKey.UNKNOWN_COMMAND, isError: true, args: { command: head } }]; } } @@ -405,7 +424,7 @@ export class ScriptEngine { private cmdSelect(state: DisplayState, rest: string, context: SelectionContext): ScriptMessage[] { state.setSelection(evaluateSelection(rest, context)); this.target.displayChanged(); - return [message(ScriptMessageKey.SELECTED, false, { count: state.selectedCount() })]; + return [{ key: ScriptMessageKey.SELECTED, isError: false, args: { count: state.selectedCount() } }]; } private cmdRestrict(state: DisplayState, rest: string, context: SelectionContext): ScriptMessage[] { @@ -415,7 +434,7 @@ export class ScriptEngine { state.setSelection(mask); state.setHidden(false); this.target.displayChanged(); - return [message(ScriptMessageKey.SELECTED, false, { count: state.selectedCount() })]; + return [{ key: ScriptMessageKey.SELECTED, isError: false, args: { count: state.selectedCount() } }]; } private cmdDisplayHide(state: DisplayState, rest: string, context: SelectionContext, hide: boolean): ScriptMessage[] { @@ -485,7 +504,7 @@ export class ScriptEngine { request = id ? { source: "library", id, range } : { source: "pubchem", name }; } const result = await this.target.load(request, true); - return [message(ScriptMessageKey.LOADED, false, { title: result.title, count: result.atomCount })]; + return [{ key: ScriptMessageKey.LOADED, isError: false, args: { title: result.title, count: result.atomCount } }]; } private background(arg: string): ScriptMessage[] { @@ -573,7 +592,7 @@ export class ScriptEngine { const value = this.target.addMeasurement(indices); return value === null ? [badArgument(joined)] - : [message(ScriptMessageKey.MEASURED, false, { value, count: indices.length })]; + : [{ key: ScriptMessageKey.MEASURED, isError: false, args: { value, count: indices.length } }]; } private set(args: readonly string[]): ScriptMessage[] { @@ -629,14 +648,6 @@ export class ScriptEngine { } } -function message( - key: ScriptMessageKeyValue, - isError: boolean, - args: Readonly>, -): ScriptMessage { - return { key, isError, args }; -} - function badArgument(argument: string): ScriptMessage { - return message(ScriptMessageKey.BAD_ARGUMENT, true, { argument }); + return { key: ScriptMessageKey.BAD_ARGUMENT, isError: true, args: { argument } }; } diff --git a/src/common/view/formatters.ts b/src/common/view/formatters.ts index 19c30d4..cfe3795 100644 --- a/src/common/view/formatters.ts +++ b/src/common/view/formatters.ts @@ -74,14 +74,14 @@ export function formatMeasurement(atomCount: number, value: number): string { export function formatScriptMessage(message: ScriptMessage): string { const patterns = StringManager.getInstance().getScriptMessages(); const pattern = patterns[`${message.key}StringProperty`].value; - const args: Record = { ...message.args }; - if (message.key === "loadFailed" && typeof args["reason"] === "string") { - args["reason"] = formatLoadError(args["reason"]); + if (message.key === "loadFailed") { + return StringUtils.fillIn(pattern, { reason: formatLoadError(message.args.reason) }); } - if (message.key === "measured" && typeof args["value"] === "number") { - args["value"] = formatMeasurement(Number(args["count"] ?? 2), args["value"]); + if (message.key === "measured") { + const { count, value } = message.args; + return StringUtils.fillIn(pattern, { count, value: formatMeasurement(count, value) }); } - return StringUtils.fillIn(pattern, args); + return StringUtils.fillIn(pattern, message.args); } /** Translate known parse reasons while preserving server/network diagnostics. */ diff --git a/tests/common/script-engine.test.ts b/tests/common/script-engine.test.ts index 95e41b3..3e114d6 100644 --- a/tests/common/script-engine.test.ts +++ b/tests/common/script-engine.test.ts @@ -94,8 +94,7 @@ describe("ScriptEngine", () => { it("selects and styles only the selection, like Jmol", async () => { const messages = await model.runScript("select nitrogen; spacefill 100%; color yellow"); - expect(messages[0]?.key).toBe(ScriptMessageKey.SELECTED); - expect(messages[0]?.args["count"]).toBe(4); + expect(messages[0]).toMatchObject({ key: ScriptMessageKey.SELECTED, args: { count: 4 } }); const state = model.displayState!; const n = state.structure.atoms.findIndex((a) => a.element.symbol === "N"); const c = state.structure.atoms.findIndex((a) => a.element.symbol === "C"); From 8e0b8c869fb9d8b1edb38bf379c86b0757b9eb11 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 15:24:02 -0500 Subject: [PATCH 4/4] chore(biome): adopt bad-sim-text plugins and fix violations Add no-math-round, no-native-timer, no-window-inner-size, and require-property-suffix; replace Math.round with roundSymmetric and align Property names. --- biome-plugins/no-math-round.grit | 12 +++++ biome-plugins/no-native-timer.grit | 18 +++++++ biome-plugins/no-window-inner-size.grit | 13 +++++ biome-plugins/require-property-suffix.grit | 35 +++++++++++++ biome.json | 4 ++ package.json | 60 +++++++++++----------- src/common/model/ColorSchemes.ts | 7 +-- src/common/view/MoleculeRenderer.ts | 15 +++--- src/common/view/ViewerControlPanel.ts | 12 ++--- tests/biome-plugins.node-test.ts | 53 ++++++++++++++++++- 10 files changed, 182 insertions(+), 47 deletions(-) create mode 100644 biome-plugins/no-math-round.grit create mode 100644 biome-plugins/no-native-timer.grit create mode 100644 biome-plugins/no-window-inner-size.grit create mode 100644 biome-plugins/require-property-suffix.grit diff --git a/biome-plugins/no-math-round.grit b/biome-plugins/no-math-round.grit new file mode 100644 index 0000000..c00d4d3 --- /dev/null +++ b/biome-plugins/no-math-round.grit @@ -0,0 +1,12 @@ +// Flags Math.round(). Prefer roundSymmetric from scenerystack/dot so positive and +// negative values round the same way (see phetsims/dot#35). +// Suppress a deliberate use with: // biome-ignore lint/plugin/no-math-round: +language js + +`Math.round($value)` as $call where { + register_diagnostic( + span = $call, + message = "Use roundSymmetric(value) from scenerystack/dot instead of Math.round(), which rounds positive and negative numbers differently.", + severity = "warn" + ) +} diff --git a/biome-plugins/no-native-timer.grit b/biome-plugins/no-native-timer.grit new file mode 100644 index 0000000..12db2dd --- /dev/null +++ b/biome-plugins/no-native-timer.grit @@ -0,0 +1,18 @@ +// Flags bare setTimeout / setInterval (and window.* forms). Sim code should step +// from the model/view step(dt) chain, or use stepTimer from scenerystack/axon when a +// delayed callback is truly needed. Method calls like stepTimer.setTimeout are allowed. +// Suppress a deliberate use with: // biome-ignore lint/plugin/no-native-timer: +language js + +or { + `setTimeout($...)`, + `setInterval($...)`, + `window.setTimeout($...)`, + `window.setInterval($...)` +} as $call where { + register_diagnostic( + span = $call, + message = "Do not call setTimeout/setInterval in sim code; step from model/view step(dt), or use stepTimer from scenerystack/axon for a delayed callback.", + severity = "warn" + ) +} diff --git a/biome-plugins/no-window-inner-size.grit b/biome-plugins/no-window-inner-size.grit new file mode 100644 index 0000000..a60a72f --- /dev/null +++ b/biome-plugins/no-window-inner-size.grit @@ -0,0 +1,13 @@ +// Flags window.innerWidth / window.innerHeight. Prefer Sim.dimensionProperty (or the +// screen's layoutBounds / visibleBounds) so layout tracks the sim display, not the +// browser chrome. +// Suppress a deliberate use with: // biome-ignore lint/plugin/no-window-inner-size: +language js + +or { `window.innerWidth`, `window.innerHeight` } as $hit where { + register_diagnostic( + span = $hit, + message = "Use Sim.dimensionProperty (or layoutBounds/visibleBounds) instead of window.innerWidth/innerHeight.", + severity = "warn" + ) +} diff --git a/biome-plugins/require-property-suffix.grit b/biome-plugins/require-property-suffix.grit new file mode 100644 index 0000000..6ab614a --- /dev/null +++ b/biome-plugins/require-property-suffix.grit @@ -0,0 +1,35 @@ +// Flags axon Property instances whose binding name does not end in "Property". +// Covers same-line const/let/var and this.field for the common *Property constructors. +// Class fields (`public readonly foo = new NumberProperty(...)`, bare `foo = ...`) are +// not reliably matched by Biome GritQL — rename those in review or with a codemod. +// Type-only annotations are out of scope (PhET's rule is type-checker based). +// Suppress a deliberate use with: // biome-ignore lint/plugin/require-property-suffix: +// GritQL regexes here must use non-capturing groups (?:...); a plain (...) silently never matches. +language js + +or { + `const $name = new $ctor($...)`, + `let $name = new $ctor($...)`, + `var $name = new $ctor($...)`, + `this.$name = new $ctor($...)` +} as $stmt where { + $ctor <: or { + `Property`, + `BooleanProperty`, + `NumberProperty`, + `StringProperty`, + `DerivedProperty`, + `DerivedStringProperty`, + `DynamicProperty`, + `TinyProperty`, + `EnumerationProperty`, + `StringUnionProperty`, + `ProfileColorProperty` + }, + not $name <: r"(?s)(?:.*(?:Property|PROPERTY)|property|_property)$", + register_diagnostic( + span = $name, + message = "Axon Property bindings must end in \"Property\" (e.g. massProperty, not mass).", + severity = "warn" + ) +} diff --git a/biome.json b/biome.json index f093ad4..20c80f1 100644 --- a/biome.json +++ b/biome.json @@ -174,6 +174,10 @@ "plugins": [ "./biome-plugins/no-native-tofixed.grit", "./biome-plugins/no-math-random.grit", + "./biome-plugins/no-math-round.grit", + "./biome-plugins/no-native-timer.grit", + "./biome-plugins/no-window-inner-size.grit", + "./biome-plugins/require-property-suffix.grit", "./biome-plugins/no-hardcoded-text.grit", { "path": "./biome-plugins/no-inline-color.grit", diff --git a/package.json b/package.json index f7f2702..9035a22 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,8 @@ { "name": "mol-scope", - "private": true, "version": "0.0.0", - "type": "module", + "private": true, "description": "A browser molecular viewer in the spirit of Jmol: explore small molecules, proteins, DNA and crystals in 3D, measure bonds and angles, and drive it with Jmol-style scripts.", - "license": "AGPL-3.0-or-later", - "repository": { - "type": "git", - "url": "https://github.com/OpenLyceum/MolScope.git" - }, "keywords": [ "simulation", "SceneryStack", @@ -22,33 +16,45 @@ "education", "pwa" ], + "homepage": "https://openlyceum.github.io/MolScope", + "repository": { + "type": "git", + "url": "https://github.com/OpenLyceum/MolScope.git" + }, + "license": "AGPL-3.0-or-later", + "type": "module", "scripts": { - "start": "vite", - "dev": "vite", "build": "tsc && vite build", "build:single": "tsc && vite build --mode single", - "preview": "vite preview", - "lint": "biome check --error-on-warnings .", - "format": "biome format --write .", - "fix": "biome check --write .", "check": "tsc --noEmit && tsc -p tsconfig.scripts.json --noEmit && tsc -p tsconfig.test.json --noEmit", - "check:unused": "knip", "check:architecture": "depcruise src", + "check:unused": "knip", + "clean": "rm -rf dist", + "dev": "vite", + "fix": "biome check --write .", + "format": "biome format --write .", + "icons": "node scripts/generate-icons.ts", + "knip": "knip", + "lint": "biome check --error-on-warnings .", + "prepare": "test \"$(git rev-parse --show-toplevel 2>/dev/null)\" = \"$PWD\" && git config core.hooksPath .githooks || true", + "preview": "vite preview", "release": "npm run check && npm run lint && npm run check:architecture && npm run build && npm test && npm version patch && git push && git push --tags", - "watch": "tsc --watch", + "start": "vite", "test": "vitest run", - "test:watch": "vitest", + "test:architecture": "node --test tests/*.node-test.ts", "test:fuzz": "node scripts/test-fuzz.ts", - "test:fuzz:quick": "node scripts/test-fuzz.ts 10", "test:fuzz:long": "node scripts/test-fuzz.ts 300", + "test:fuzz:quick": "node scripts/test-fuzz.ts 10", "test:soak": "npm run test:soak:headless && npm run test:soak:browser", - "test:soak:headless": "vitest run --config vitest.soak.config.ts", "test:soak:browser": "npx playwright test tests/soak/browser.spec.ts", - "icons": "node scripts/generate-icons.ts", - "clean": "rm -rf dist", - "prepare": "test \"$(git rev-parse --show-toplevel 2>/dev/null)\" = \"$PWD\" && git config core.hooksPath .githooks || true", - "knip": "knip", - "test:architecture": "node --test tests/*.node-test.ts" + "test:soak:headless": "vitest run --config vitest.soak.config.ts", + "test:watch": "vitest", + "watch": "tsc --watch" + }, + "overrides": { + "brace-expansion": "~5.0.12", + "lodash": "~4.18.1", + "three": "~0.125.2" }, "dependencies": { "scenerystack": "^3.0.0" @@ -71,11 +77,6 @@ "engines": { "node": ">=26" }, - "overrides": { - "lodash": "~4.18.1", - "three": "~0.125.2", - "brace-expansion": "~5.0.12" - }, "devEngines": { "runtime": { "name": "node", @@ -85,6 +86,5 @@ }, "allowScripts": { "@swc/core@1.16.22": true - }, - "homepage": "https://openlyceum.github.io/MolScope" + } } diff --git a/src/common/model/ColorSchemes.ts b/src/common/model/ColorSchemes.ts index 8d7b32a..1225308 100644 --- a/src/common/model/ColorSchemes.ts +++ b/src/common/model/ColorSchemes.ts @@ -7,6 +7,7 @@ * Colours are 0xRRGGBB integers so this module stays free of Scenery. */ +import { roundSymmetric } from "scenerystack/dot"; import type { Atom, Residue, Structure } from "./Structure.js"; import { ResidueKind, SecondaryStructure } from "./Structure.js"; @@ -142,9 +143,9 @@ export function parseColor(text: string): number | null { /** Linear blend between two 0xRRGGBB colours. */ function mixColors(c1: number, c2: number, t: number): number { - const r = Math.round(((c1 >> 16) & 255) * (1 - t) + ((c2 >> 16) & 255) * t); - const g = Math.round(((c1 >> 8) & 255) * (1 - t) + ((c2 >> 8) & 255) * t); - const b = Math.round((c1 & 255) * (1 - t) + (c2 & 255) * t); + const r = roundSymmetric(((c1 >> 16) & 255) * (1 - t) + ((c2 >> 16) & 255) * t); + const g = roundSymmetric(((c1 >> 8) & 255) * (1 - t) + ((c2 >> 8) & 255) * t); + const b = roundSymmetric((c1 & 255) * (1 - t) + (c2 & 255) * t); return (r << 16) | (g << 8) | b; } diff --git a/src/common/view/MoleculeRenderer.ts b/src/common/view/MoleculeRenderer.ts index 849c8b5..aed9197 100644 --- a/src/common/view/MoleculeRenderer.ts +++ b/src/common/view/MoleculeRenderer.ts @@ -1,3 +1,4 @@ +import { roundSymmetric } from "scenerystack/dot"; import { MOLECULE_RENDERER_SETTINGS } from "../../MolScopeConstants.js"; /** * MoleculeRenderer.ts @@ -318,7 +319,7 @@ export class MoleculeRenderer { // Start each half at the sphere surface so it does not paint over the ball's face. const trimA = bondTrim(this.sr[a] ?? 0, width, len); const trimB = bondTrim(this.sr[b] ?? 0, width, len); - const multiple = bondStrandCount(bond.order, Math.round(bond.order)); + const multiple = bondStrandCount(bond.order, roundSymmetric(bond.order)); const { strandWidth, spacing } = bondStrandLayout(width, multiple, line); this.addBondStrands(bond, a, b, { ax, @@ -962,9 +963,9 @@ export class MoleculeRenderer { /** Scales a colour's brightness (0 = black, 1 = unchanged). */ function shadeColor(color: number, factor: number): number { - const r = Math.round(((color >> 16) & 255) * factor); - const g = Math.round(((color >> 8) & 255) * factor); - const b = Math.round((color & 255) * factor); + const r = roundSymmetric(((color >> 16) & 255) * factor); + const g = roundSymmetric(((color >> 8) & 255) * factor); + const b = roundSymmetric((color & 255) * factor); return (Math.min(255, r) << 16) | (Math.min(255, g) << 8) | Math.min(255, b); } @@ -974,9 +975,9 @@ function lighten(color: number, amount: number): number { const g = (color >> 8) & 255; const b = color & 255; return ( - (Math.round(r + (255 - r) * amount) << 16) | - (Math.round(g + (255 - g) * amount) << 8) | - Math.round(b + (255 - b) * amount) + (roundSymmetric(r + (255 - r) * amount) << 16) | + (roundSymmetric(g + (255 - g) * amount) << 8) | + roundSymmetric(b + (255 - b) * amount) ); } diff --git a/src/common/view/ViewerControlPanel.ts b/src/common/view/ViewerControlPanel.ts index c186c66..e19e2c6 100644 --- a/src/common/view/ViewerControlPanel.ts +++ b/src/common/view/ViewerControlPanel.ts @@ -79,10 +79,10 @@ export class ViewerControlPanel extends MolScopePanel { const groupCombos = groups.map((group) => { const entries = model.entries.filter((e) => e.group === group); // Each combo owns a Property whose value is always one of its items. - const local = new Property( + const localProperty = new Property( entries.some((e) => e.id === model.entryIdProperty.value) ? model.entryIdProperty.value : CUSTOM_ENTRY_ID, ); - local.lazyLink((id) => { + localProperty.lazyLink((id) => { if (id !== CUSTOM_ENTRY_ID && id !== model.entryIdProperty.value) { model.loadEntry(id).catch(() => undefined); } @@ -94,12 +94,12 @@ export class ViewerControlPanel extends MolScopePanel { })), customChoice(CUSTOM_ENTRY_ID), ]; - const combo = comboBox(local, choices, listParent, a11y.structureSelectorStringProperty, inner); - return { group, local, combo, ids: new Set(entries.map((e) => e.id)) }; + const combo = comboBox(localProperty, choices, listParent, a11y.structureSelectorStringProperty, inner); + return { group, localProperty, combo, ids: new Set(entries.map((e) => e.id)) }; }); const syncCombos = (id: string) => { for (const g of groupCombos) { - g.local.value = g.ids.has(id) ? id : CUSTOM_ENTRY_ID; + g.localProperty.value = g.ids.has(id) ? id : CUSTOM_ENTRY_ID; } const entry = libraryEntry(id); if (entry && groups.includes(entry.group)) { @@ -383,7 +383,7 @@ export class ViewerControlPanel extends MolScopePanel { property.dispose(); } for (const g of groupCombos) { - g.local.dispose(); + g.localProperty.dispose(); } groupProperty.dispose(); styleProperty.dispose(); diff --git a/tests/biome-plugins.node-test.ts b/tests/biome-plugins.node-test.ts index 8238845..137cae6 100644 --- a/tests/biome-plugins.node-test.ts +++ b/tests/biome-plugins.node-test.ts @@ -63,6 +63,54 @@ test("no-math-random flags Math.random() and leaves dotRandom alone", () => { assert.deepEqual(lines(hits, "dotRandom"), [1]); }); +test("no-math-round flags Math.round() and leaves roundSymmetric alone", () => { + const hits = lint({ + "src/a.ts": "export const a = Math.round(1.5);\nexport const b = roundSymmetric(1.5);\n", + }); + assert.deepEqual(lines(hits, "roundSymmetric"), [1]); +}); + +test("no-native-timer flags bare and window timers, allows stepTimer", () => { + const hits = lint({ + "src/a.ts": [ + "setTimeout(() => {}, 0);", + "setInterval(() => {}, 0);", + "window.setTimeout(() => {}, 0);", + "window.setInterval(() => {}, 0);", + "stepTimer.setTimeout(() => {}, 0);", + "stepTimer.setInterval(() => {}, 0);", + "", + ].join("\n"), + }); + assert.deepEqual(lines(hits, "stepTimer"), [1, 2, 3, 4]); +}); + +test("no-window-inner-size flags window.innerWidth/Height", () => { + const hits = lint({ + "src/a.ts": "const w = window.innerWidth;\nconst h = window.innerHeight;\nconst d = dimensionProperty;\n", + }); + assert.deepEqual(lines(hits, "dimensionProperty"), [1, 2]); +}); + +test("require-property-suffix flags Property bindings without Property suffix", () => { + const hits = lint({ + "src/a.ts": [ + "const mass = new NumberProperty(1);", + "const massProperty = new NumberProperty(1);", + "const details = new DerivedProperty([x], (v) => v);", + "const detailsProperty = new DerivedProperty([x], (v) => v);", + "this.visible = new BooleanProperty(true);", + "this.visibleProperty = new BooleanProperty(true);", + // Class fields are not reliably matched by Biome GritQL yet. + "class D {", + " public readonly ignored = new NumberProperty(0);", + "}", + "", + ].join("\n"), + }); + assert.deepEqual(lines(hits, "Property"), [1, 3, 5]); +}); + test("no-hardcoded-text flags literal display words only", () => { const hits = lint({ "src/a.ts": [ @@ -116,6 +164,9 @@ test("no-inline-color flags hardcoded colors outside *Colors.ts", () => { }); test("plugins only run under src/", () => { - const hits = lint({ "scripts/a.ts": 'Math.random(); new Text("Mass"); new Color(1, 2, 3);\n' }); + const hits = lint({ + "scripts/a.ts": + 'Math.random(); Math.round(1); setTimeout(() => {}, 0); window.innerWidth; const mass = new NumberProperty(1); new Text("Mass"); new Color(1, 2, 3);\n', + }); assert.deepEqual(hits, []); });