From f7e885c2477b28b23c3ac8cbcbc2100cc98db8a3 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Mon, 23 Nov 2026 23:58:06 -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. --- AGENTS.md | 4 ++++ package.json | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index a8758be..1348205 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -91,3 +91,7 @@ decisions: [`doc/implementation-notes.md`](doc/implementation-notes.md). ## PWA After `npm run build`, the sim is installable offline via Workbox (`dist/manifest.webmanifest`). + +## Compliance carve-outs + +None. diff --git a/package.json b/package.json index bdd2e7a..b291fdd 100644 --- a/package.json +++ b/package.json @@ -86,5 +86,6 @@ }, "allowScripts": { "@swc/core@1.16.22": true - } + }, + "homepage": "https://openlyceum.github.io/TitrationLab" } From 0564eaf4ad90534b209e07c7e80b96d75fb965ea Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 10:08:23 -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 36a3eb1ce97157766e7769ac38becbee9b916fca Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 12:19:21 -0500 Subject: [PATCH 3/4] Type-check localized titration labels --- src/common/view/formatValues.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/common/view/formatValues.ts b/src/common/view/formatValues.ts index 5039f7d..02ef748 100644 --- a/src/common/view/formatValues.ts +++ b/src/common/view/formatValues.ts @@ -29,11 +29,6 @@ const SUPERSCRIPTS: Record = { "9": "⁹", }; -/** Typed lookup in a getNestedStringProperties group (keys are suffixed "StringProperty"). */ -function lookup(group: object, key: K): ReadOnlyProperty { - return (group as Record>)[`${key}StringProperty`] as ReadOnlyProperty; -} - /** Fixed decimals with a true minus sign. */ export function fixed(value: number, decimals: number): string { return toFixed(value, decimals).replace("-", MINUS); @@ -62,7 +57,7 @@ export function scientific(value: number, significant = 2): string { } export function analyteNameProperty(id: AnalyteId | "unknownAcid"): ReadOnlyProperty { - return lookup(StringManager.getInstance().getAnalyteNames(), id); + return StringManager.getInstance().getAnalyteNames()[`${id}StringProperty`]; } /** "Acetic acid, CH3COOH" (RichText), following the locale. */ @@ -77,7 +72,7 @@ export function analyteLabelProperty(analyte: Analyte): TReadOnlyProperty { - return lookup(StringManager.getInstance().getIndicatorNames(), id); + return StringManager.getInstance().getIndicatorNames()[`${id}StringProperty`]; } /** Indicator name, or "None". */ @@ -88,7 +83,7 @@ export function indicatorName(indicator: Indicator | null): string { } export function colorName(color: PerceivedColor): string { - return lookup(StringManager.getInstance().getColorNames(), color).value; + return StringManager.getInstance().getColorNames()[`${color}StringProperty`].value; } /** Name of a region; numbered when the analyte has more than one equivalence point. */ @@ -119,7 +114,7 @@ export function regionName(region: Region, analyte: Analyte): string { /** RichText statement of a textbook approximation. */ export function methodText(method: ApproximationMethod): string { - return lookup(StringManager.getInstance().getCommonStrings().methods, method).value; + return StringManager.getInstance().getCommonStrings().methods[`${method}StringProperty`].value; } /** "Volume of NaOH added (mL)" for the analyte's titrant. */ From fa285312e03c1314f667bbc95ecb5cc1deb81be5 Mon Sep 17 00:00:00 2001 From: martin veillette Date: Tue, 24 Nov 2026 15:24:45 -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/TitrationCurve.ts | 4 +- src/indicators/view/IndicatorsScreenView.ts | 4 +- src/lab/view/BuretteNode.ts | 4 +- src/lab/view/LabScreenView.ts | 4 +- src/lab/view/PHMeterNode.ts | 4 +- tests/biome-plugins.node-test.ts | 53 +++++++++++++++++- 12 files changed, 174 insertions(+), 41 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 b291fdd..b74b739 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,8 @@ { "name": "titration-lab", - "private": true, "version": "0.0.0", - "type": "module", + "private": true, "description": "Acid–base titration for General Chemistry: a burette-and-indicator lab with an unknown, exact titration curves for strong, weak and polyprotic acids and bases, and how to choose an indicator.", - "license": "AGPL-3.0-or-later", - "repository": { - "type": "git", - "url": "https://github.com/OpenLyceum/TitrationLab.git" - }, "keywords": [ "simulation", "SceneryStack", @@ -23,33 +17,45 @@ "education", "pwa" ], + "homepage": "https://openlyceum.github.io/TitrationLab", + "repository": { + "type": "git", + "url": "https://github.com/OpenLyceum/TitrationLab.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" @@ -72,11 +78,6 @@ "engines": { "node": ">=26" }, - "overrides": { - "lodash": "~4.18.1", - "three": "~0.125.2", - "brace-expansion": "~5.0.12" - }, "devEngines": { "runtime": { "name": "node", @@ -86,6 +87,5 @@ }, "allowScripts": { "@swc/core@1.16.22": true - }, - "homepage": "https://openlyceum.github.io/TitrationLab" + } } diff --git a/src/common/model/TitrationCurve.ts b/src/common/model/TitrationCurve.ts index e4a87b9..6bc2f21 100644 --- a/src/common/model/TitrationCurve.ts +++ b/src/common/model/TitrationCurve.ts @@ -9,7 +9,7 @@ import { TITRATION_CURVE_SETTINGS } from "../../TitrationLabConstants.js"; * Volumes are in mL and concentrations in mol/L; amounts are returned in mmol (mL × mol/L). */ -import { Vector2 } from "scenerystack/dot"; +import { roundSymmetric, Vector2 } from "scenerystack/dot"; import { KEY_POINT_TOLERANCE, PKW, STOICHIOMETRIC_TOLERANCE } from "../../TitrationLabConstants.js"; import { type Analyte, analyteMixture, isStrong, isTitratedWithBase, titrantMixture } from "./Analytes.js"; import { alphaFractions, type Mixture, mix, solvePH } from "./ChargeBalanceSolver.js"; @@ -228,7 +228,7 @@ export function regionAt(setup: TitrationSetup, titrantVolume: number): Region { const totalVolume = setup.analyteVolume + titrantVolume; const progress = (setup.titrantConcentration * titrantVolume) / amount; const base = isTitratedWithBase(analyte); - const whole = Math.round(progress); + const whole = roundSymmetric(progress); const atWhole = Math.abs(progress - whole) <= STOICHIOMETRIC_TOLERANCE * Math.max(1, progress); if (isStrong(analyte)) { diff --git a/src/indicators/view/IndicatorsScreenView.ts b/src/indicators/view/IndicatorsScreenView.ts index e376cc5..5982b94 100644 --- a/src/indicators/view/IndicatorsScreenView.ts +++ b/src/indicators/view/IndicatorsScreenView.ts @@ -9,7 +9,7 @@ import { INDICATORS_SCREEN_VIEW_SETTINGS } from "../../TitrationLabConstants.js" */ import { DerivedProperty } from "scenerystack/axon"; -import { Dimension2 } from "scenerystack/dot"; +import { Dimension2, roundSymmetric } from "scenerystack/dot"; import { optionize } from "scenerystack/phet-core"; import { StringUtils } from "scenerystack/phetcommon"; import { HBox, Node, Text, VBox } from "scenerystack/scenery"; @@ -73,7 +73,7 @@ export class IndicatorsScreenView extends ScreenView { keyboardStep: INDICATORS_SCREEN_VIEW_SETTINGS.PH_SLIDER_KEYBOARD_STEP, shiftKeyboardStep: INDICATORS_SCREEN_VIEW_SETTINGS.PH_SLIDER_SHIFT_KEYBOARD_STEP, pageKeyboardStep: INDICATORS_SCREEN_VIEW_SETTINGS.PH_SLIDER_PAGE_KEYBOARD_STEP, - constrainValue: (value: number) => Math.round(value * 20) / 20, + constrainValue: (value: number) => roundSymmetric(value * 20) / 20, accessibleName: strings.solutionPHStringProperty, }); for (let pH = PH_RANGE.min; pH <= PH_RANGE.max; pH += 2) { diff --git a/src/lab/view/BuretteNode.ts b/src/lab/view/BuretteNode.ts index ce3d3ac..4d5b408 100644 --- a/src/lab/view/BuretteNode.ts +++ b/src/lab/view/BuretteNode.ts @@ -234,8 +234,8 @@ export class BuretteNode extends Node { readingText.top = lens.y + LENS_RADIUS + BURETTE_NODE_SETTINGS.CONSTRUCTOR_TOP_OFFSET; }); - const openFraction = new DerivedProperty([model.flowRateProperty], (rate) => rate / FLOW_RATE_RANGE.max); - openFraction.link((fraction) => { + const openFractionProperty = new DerivedProperty([model.flowRateProperty], (rate) => rate / FLOW_RATE_RANGE.max); + openFractionProperty.link((fraction) => { handle.rotation = (fraction * Math.PI) / 2; }); } diff --git a/src/lab/view/LabScreenView.ts b/src/lab/view/LabScreenView.ts index 31e39c7..194fdbe 100644 --- a/src/lab/view/LabScreenView.ts +++ b/src/lab/view/LabScreenView.ts @@ -239,8 +239,8 @@ export class LabScreenView extends ScreenView { chart.chartTransform.modelToViewXY(0, 0).plusXY(CHART_WIDTH / 2, -CHART_HEIGHT / 2), ); }); - const hintVisible = new DerivedProperty([model.meterInFlaskProperty], (inFlask) => !inFlask); - hintVisible.link((visible) => { + const hintVisibleProperty = new DerivedProperty([model.meterInFlaskProperty], (inFlask) => !inFlask); + hintVisibleProperty.link((visible) => { hint.visible = visible && model.measuredPoints.length === 0; }); diff --git a/src/lab/view/PHMeterNode.ts b/src/lab/view/PHMeterNode.ts index 22cc0d6..0d37f38 100644 --- a/src/lab/view/PHMeterNode.ts +++ b/src/lab/view/PHMeterNode.ts @@ -25,7 +25,7 @@ export class PHMeterNode extends Node { public constructor(pHProperty: TReadOnlyProperty, meterInProperty: TReadOnlyProperty) { super(); const common = StringManager.getInstance().getCommonStrings(); - const reading = new DerivedProperty( + const readingProperty = new DerivedProperty( [pHProperty, meterInProperty, common.noReadingStringProperty], (pH, inFlask, noReading) => (inFlask ? formatPH(pH) : noReading), ); @@ -40,7 +40,7 @@ export class PHMeterNode extends Node { fill: TitrationLabColors.meterScreenColorProperty, }, ); - const value = new Text(reading, { + const value = new Text(readingProperty, { font: new PhetFont({ size: PH_METER_NODE_SETTINGS.VALUE_FONT_SIZE, weight: "bold", family: "monospace" }), fill: TitrationLabColors.meterTextColorProperty, maxWidth: WIDTH - PH_METER_NODE_SETTINGS.VALUE_MAX_WIDTH_OFFSET, 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, []); });