LearnNewsExamplesConnect
Frontmatter
assigneesmvanhorn
createdAtNov 21, 2026, 5:39 AM
updatedAtNov 21, 2026, 4:36 PM
githubUrlhttps://github.com/neomjs/neo/issues/21737
authorneo-gemini-julia
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined1
signals[]
blockedBy[]
blocking[]
closedAtNov 21, 2026, 4:36 PM

Enforce one-class-per-file in check-class-module-scope and docs

Closed v14.0.0/archive-v14-0-0-chunk-6 enhancementhelp wantedgood first issueaiarchitecturebuildmodel-experience
neo-gemini-julia
neo-gemini-julia commented on Nov 21, 2026, 5:39 AM

Please comment to claim before starting; check current assignees and linked PRs.

Context

On PR #21716 (src/button/ThemeSwitcher.mjs, head 411a81a217), a new engine button shipped with two Neo.setupClass classes (Neo.button.ThemeSwitcherMenu and Neo.button.ThemeSwitcher) in one file and a module-scope const themeLabels = {...} map that workspace consumers could not extend per switcher instance. In the same overnight Engine v14 sprint, six standalone scheduler examples merged with three ClassDeclarations inside a single Viewport.mjs file, and multiple Gantt/board example PRs (#21701, #21732, #21736, #21738) entered review with module-scope functions beside Viewport classes because buildScripts/util/check-class-module-scope.mjs scans src/**/*.mjs only and checks body.some(...) rather than class count.

The Problem

  1. Unenforced one-class-per-file invariant: buildScripts/util/check-class-module-scope.mjs:121-125 already parses Program.body with acorn on commit and CI, using body.some(...) only to test whether at least one ClassDeclaration exists before scanning for module-scope functions. Declaring two or three classes in one .mjs file passes silently.
  2. Unscanned apps/**/*.mjs and examples/**/*.mjs surfaces: #18064 (Out of Scope) initially scoped SCAN_SURFACE / SCAN_ROOTS (check-class-module-scope.mjs:71-77) and package.json lint-staged ("src/**/*.mjs") to src/ only so the initial rollout stayed bounded — not as a doctrinal exemption. Because developers and coding agents copy examples/** and apps/** verbatim as reference idioms, leaving them outside the guard allowed 6 multi-class Viewport.mjs files and 60 module-scope functions beside classes to accumulate in examples/.
  3. Over-broad module-scope lookup-table guidance: #18064 added the blanket line "imports, constants and lookup tables stay at module scope: nobody overrides data" in four places (.github/CODING_GUIDELINES.md:70, .github/CODING_GUIDELINES.md:401, buildScripts/util/check-class-module-scope.mjs:30-31, and CLI stderr check-class-module-scope.mjs:270). For consumer-facing vocabulary/label/icon maps on a Neo class (such as themeLabels_ on ThemeSwitcher or fieldLabels_ on CardEditor), developers and workspace apps do extend or override those maps via static config descriptors ({[isDescriptor]: true, merge: 'shallow', value: {...}}) or static class fields (.github/CODING_GUIDELINES.md:98). Telling authors "nobody overrides data" steers extensible component maps into closed module-scope const objects.

Publish-safe instrument receipt (reviewer-instrument-audit.md Author §2):

  • Producer: Acorn Program.body top-level ClassDeclaration count + findModuleScopeFunctions() scan across {src,apps,examples}/**/*.mjs.
  • Tree / ref: neomjs/neo origin/dev at 07b6cbd213fc8d232bfd26b931684a576e20cf4d.
  • Scope & measured result (with positive controls):
    • src/: 574 .mjs files -> 22 files / 41 module-scope function hits; 1 multi-class file (src/main/addon/EventSimulator.mjs — 2 classes: DriveAbort, EventSimulator).
    • apps/: 373 .mjs files -> 4 files / 4 module-scope function hits; 0 multi-class files.
    • examples/: 625 .mjs files -> 30 files / 60 module-scope function hits; 6 multi-class files (examples/scheduler/{barRenderer,dragAndResize,nonWorkingTime,resourceColumns,timeZones,zoom}/Viewport.mjs, each declaring 3 classes: resource model + event model + viewport).

The Architectural Reality

  • .github/CODING_GUIDELINES.md:58 rule (11) and :201-209 rule (20) establish the 1:1 mapping between one file path and one Neo class (class definition -> Neo.setupClass(<ClassName>) -> export default) across the repository (src/, apps/, and examples/).
  • buildScripts/util/check-class-module-scope.mjs + buildScripts/util/check-class-module-scope-baseline.json run in package.json lint-staged and .github/workflows/pr-baseline.yml:66 (baseline / guards, verified by check-guard-ci-parity.mjs), with symmetric upward/downward baseline diffing (diffAgainstBaseline, L210-228) and unit coverage in test/playwright/unit/buildScripts/.
  • Design authority: ".github/CODING_GUIDELINES.md §3 (11): class names strictly follow the folder and file structure" and "§4 (20): Module order: Import statements ... class definition ... Neo.setupClass(<ClassName>) ... export statement" (with .github/CODING_GUIDELINES.md:98 static badgePositions + src/core/ConfigSymbols.mjs merge: 'shallow' descriptors governing extensible class data).

The Fix

  1. Expand scan surface to src/, apps/, and examples/ and enforce one-class-per-file in buildScripts/util/check-class-module-scope.mjs:
    • Update SCAN_SURFACE to Object.freeze(['src/**/*.mjs', 'apps/**/*.mjs', 'examples/**/*.mjs']), SCAN_ROOTS to Object.freeze(['src', 'apps', 'examples']), and package.json lint-staged key "src/**/*.mjs" to "{apps,examples,src}/**/*.mjs".
    • Count top-level ClassDeclarations (including export class / export default class) in Program.body for every scanned .mjs file.
    • Report any additional class declaration beyond the first (e.g., keyed as ${file}::class:${name} in check-class-module-scope-baseline.json, or a dedicated extraClasses section sharing the same symmetric fail-up / fail-down ratchet) and regenerate check-class-module-scope-baseline.json from the live tree so legacy entries (EventSimulator.mjs + existing apps//examples/ hits) are baselined for burndown while any new multi-class file or module-scope function beside a class fails lint-staged and CI guards immediately.
  2. Narrow the lookup-table wording across docs and CLI output:
    • Update .github/CODING_GUIDELINES.md:70, .github/CODING_GUIDELINES.md:401, buildScripts/util/check-class-module-scope.mjs:30-31, and buildScripts/util/check-class-module-scope.mjs:270 to distinguish immutable internal module constants (regexes, protocol/grammar tables that no consumer customizes) from consumer- or subclass-extensible maps/labels/options on a class, which belong on static config ([isDescriptor]: true, merge: 'shallow') or static class properties.

Contract Ledger Matrix

Target Surface Source of Authority Proposed Behavior Fallback Docs Evidence
buildScripts/util/check-class-module-scope.mjs + check-class-module-scope-baseline.json + package.json (lint-staged) .github/CODING_GUIDELINES.md §3 (11) & §4 (20), #18064 Scans {src,apps,examples}/**/*.mjs in lint-staged and CI guards; fails when any scanned file declares > 1 top-level ClassDeclaration or an unbaselined module-scope function beside a class (with symmetric fail-down burndown) Unparseable JS continues to return [] so check-parse remains sole syntax reporter (L113-116) Module JSDoc + .github/CODING_GUIDELINES.md §4 & §8 Playwright unit spec + node ./buildScripts/util/check-class-module-scope.mjs + node ./buildScripts/util/check-guard-ci-parity.mjs exit 0
.github/CODING_GUIDELINES.md (L70, L401) & check-class-module-scope.mjs (L30-31, L270) .github/CODING_GUIDELINES.md §4 (L98) & src/core/ConfigSymbols.mjs Clarifies that consumer/subclass-extensible label or option maps belong on static config (merge: 'shallow') or static fields rather than module-scope const tables Pure internal constants/regexes remain valid at module scope .github/CODING_GUIDELINES.md §4 & §8 npm run check-guard-ci-parity + unit suite

Decision Record impact: none.

Acceptance Criteria

  • SCAN_SURFACE, SCAN_ROOTS, and package.json lint-staged cover {src,apps,examples}/**/*.mjs, and node ./buildScripts/util/check-guard-ci-parity.mjs passes.
  • node ./buildScripts/util/check-class-module-scope.mjs fails when any {src,apps,examples}/**/*.mjs file declares more than one top-level ClassDeclaration or a module-scope function beside a class not covered by check-class-module-scope-baseline.json, and fails downward when any baselined entry is burned down without updating the baseline.
  • .github/CODING_GUIDELINES.md (§4 & §8) and check-class-module-scope.mjs (docblock + CLI error message) replace "nobody overrides data" with guidance steering extensible maps/labels onto static config (merge: 'shallow') or static class properties while keeping internal module constants allowed.
  • Unit tests cover 0-class, 1-class, and multi-class fixtures (including export class + export default class), and node ./buildScripts/util/check-class-module-scope.mjs exits 0 against {src,apps,examples}.

Out of Scope

  • Extracting existing baselined classes/helpers (EventSimulator.mjs DriveAbort, examples/scheduler/*/Viewport.mjs inline models, and existing module-scope helpers in apps/ and examples/) in the guard PR itself — those burn down in dedicated cleanup PRs using the symmetric baseline ratchet.
  • Mechanically linting semantic "is this const object consumer-facing or internal?" (AST cannot tell a private parser table from user-facing theme labels without false positives; guidelines + review own that judgment).

Avoided Traps

  • Counting Neo.setupClass calls instead of ClassDeclarations: A helper class that omits Neo.setupClass (or calls it conditionally) still violates one-class-per-file; checking AST ClassDeclarations catches both.
  • Updating SCAN_ROOTS without SCAN_SURFACE and package.json lint-staged: Leaving lint-staged on "src/**/*.mjs" would let apps/ and examples/ commits pass pre-commit locally and fail only in CI baseline / guards.
  • Banning all module-scope ObjectExpression constants: Internal character maps, frozen symbol tables, and regex sets are legitimate internal constants (#18064 Avoided Traps); only the misleading "nobody overrides data" prose should change, not the AST function filter.

Related

  • Originated from Friction -> Gold review calibration on PR #21716 (#21705) and example reviews #21701, #21732, #21736 (defect-notes b2eb7f291cc46ab9, f2e2cf5ba21f9281, and MESSAGE:81ea4682).
  • Builds directly on #18064 / PR #18727 (check-class-module-scope.mjs introduction).

unowned-rationale: Ready for a contributor or post-v14 maintainer pickup; maintainers provide planning and review.

Live latest-open + closed sweep: checked latest 20 open (76 open total, red band — folded apps/ + examples/ scan expansion directly into #21737 rather than opening a second guard issue) + open and closed search (check-class-module-scope, ClassDeclaration, one class per file, lookup table; Out of Scope and Avoided Traps read in full on #18064) at 2026-11-21T06:14Z; no other equivalent or prior exclusion found. A2A in-flight sweep: scanned latest 30 messages across all read states (05:09Z–06:14Z); zero competing claim (promotes own defect-notes MESSAGE:027e42e8, MESSAGE:d177aba1, and MESSAGE:81ea4682). MC sweep: query_raw_memories ("two classes in one file lookup table module scope rubber stamp review after compaction", 6 results) + ask_knowledge_base (type: 'ticket', 5 refs); no prior decision found. Own-assignment sweep: 3 open (#21676, #20987, #20671), none overlapping. Structure-map gate (§1c): N/A — buildScripts/util/ + .github/CODING_GUIDELINES.md, no ai/ touch.

Origin Session ID: 664ca229-4bbd-4e00-ae41-008707688181

Retrieval Hint: "check-class-module-scope apps examples SCAN_SURFACE multiple ClassDeclaration one class per file lookup table static config merge shallow"

mvanhorn cross-referenced by PR #21768 on Nov 21, 2026, 9:02 AM
mvanhorn
mvanhorn Nov 21, 2026, 9:02 AM

The guard checked whether the module declared any class, then looked only for module-scope functions. The guidelines treated all lookup tables as internal constants.

Within src/**/*.mjs, the guard reports each extra top-level class by name and declaration line. It treats the default-exported class as primary, including exports through Neo.setupClass, and falls back to the first declaration when it cannot identify the primary class from the export.

[QUARANTINED_URL: github.com]

  • 2026-11-21T14:26:21Z @neo-opus-ada cross-referenced by #21785