gitoria

kunibert

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf97a0e5ff97a0e5fMerge branch 'hl-standard' into mainKunibertf97a0e5f/rules/HL-STANDARD.md

11.6 KB

  1. # Hybriel + hl:web usage standard
  2. 2026-11-09 · Checked against hybriel `ea3966e8f6996e62f16b63a05def0c89579b4096`.
  3. Replaces CODE-ORDER; merges its rules below; the primer remains the explanation.
  4. References: [SPEC.md](../SPEC.md) (truth), [HL-PRIMER.md](HL-PRIMER.md), [COMPONENTS.md](../COMPONENTS.md).
  5. ## Part A — Language (owner Anton)
  6. Wrong → right pairs show intent; style violations can compile. Spot commands find review candidates, not proofs; run from the app root.
  7. **L1.** Do not end a statement with `;` (classic `for` clauses and braced hybrid entries may use it).
  8. `x = 1;` → `x = 1`
  9. Spot: `rg -n ';\s*$' -g '*.hl'`
  10. **L2.** Use `let` only for a name reassigned later; otherwise use a plain declaration.
  11. `let n = items.length` → `n = items.length`
  12. Spot: `rg -n '\blet\b' -g '*.hl'` (check subsequent writes).
  13. **L3.** Call functions directly: calls await automatically; do not add `async`, `await` or Promise `.then` chains.
  14. `await save()` → `save()`
  15. Spot: `rg -n '\b(async|await)\b|\.then\(' -g '*.hl'`
  16. **L4.** Function values require parenthesized parameters and a block body.
  17. `n => n + 1` → `(n) => { return n + 1 }`
  18. Spot: `rg -n '=>' -g '*.hl'`
  19. **L5.** Handle expected failures with value forms (`JSON.tryParse`, `tryFetch`, `tryReadFile`) or `on Error(e)`, never `try`/`catch`/`throw`.
  20. `try { JSON.parse(t) }` → `JSON.tryParse(t)`
  21. Spot: `rg -n '\b(try|catch|throw)\b' -g '*.hl'`
  22. **L6.** Build strings with `+` or `join`; interpolation is literal text and `\n` is two characters (write a real newline).
  23. `"a ${b}"` → `'a ' + b`
  24. Spot: `rg -n '\$\{|\\n' -g '*.hl'`
  25. **L7.** Name literal fields with `=` or `=name`; bare names are ordered entries, not named-field shorthand.
  26. `{ id, name }` → `{ =id =name }`
  27. Spot: `rg -n '\{\s*\w+\s*,' -g '*.hl'` (destructuring differs).
  28. **L8.** Read needed outer values before a same-named literal entry shadows them for later entries.
  29. `card(app) { return { app = app.id n = app.name } }` → `card(app) { name = app.name return { app = app.id n = name } }`
  30. Spot: review literals in entry order (#292).
  31. **L9.** Test an ordered hybrid's length for emptiness; even an empty hybrid is true.
  32. `if (rows) { echo('nonempty') }` → `if (rows.length > 0) { echo('nonempty') }`
  33. Spot: `rg -n 'if\s*\(\w+\)' -g '*.hl'`
  34. **L10.** Declare known types and convert numeric text with `toNumber` (Number or null), never arithmetic coercion.
  35. `"42" - 0` → `Number n = toNumber("42")`
  36. Spot: `rg -n 'toNumber| - 0' -g '*.hl'` (review parameter/member types).
  37. **L11.** Hybrids and Bytes copy on assignment/call; to change the caller's variable, use a mutable binding and `&` at both ends.
  38. `fill(&list) { list.push(1) } let list = [] fill(list)` → `fill(&list) { list.push(1) } let list = [] fill(&list)`
  39. Spot: `rg -n '&' -g '*.hl'` (compare caller and parameter).
  40. **L12.** Put members at file root: one file is one class, root statements run at construction; no class wrapper, `constructor`, `__construct` or `on start()` entry hook.
  41. `class Home { name = "Home" }` → `String name = "Home"`
  42. Spot: `rg -n '\bclass\b|\b(__construct|constructor)\b|on start\(' -g '*.hl'`
  43. **L13.** Pass cross-realm values as emit arguments; a server face's last `session` parameter belongs to the server, never the peer.
  44. `emit server save()` / `on server save(session) { echo(id) }` → `emit server save(id)` / `on server save(String id, session) { echo(id) }`
  45. Spot: `rg -n 'emit |on .*session' -g '*.hl'` (review reads of members written by the other realm).
  46. The following merge CODE-ORDER's creator rules (2026-10-03), including L2 above. Creator: "why is `let` in all projects constantly misused? let is needed to make a variable overwritable … why is the project.hl cluttered with deeper process functions? why are .hl files scattered in the project roots?" — and on patterns: "i dont really want to rewrite code or add complexity with higher concepts, its enough if things that belong together land in the same file … one file that holds the central logic, so it gets that at one look and stuff it can look up additionally goes in helper files."
  47. **L14.** Keep `project.hl` a map: config, routes/wiring and a short index with one line per feature naming its file; put process/helper functions elsewhere.
  48. `helper(String s) { return s.toUpperCase() }` in `project.hl` → `import { helper } from './lib/util.hl'`
  49. Spot: `rg -n '^\s*(static\s+)?([A-Z]\w*\s+)?\w+\(' project.hl` (also review function literals).
  50. **L15.** Keep only `project.hl` as root `.hl`; use `components/` for UI, `lib/` for logic, `tools/` for CLI tools and `tests/` for gates.
  51. `// root: tool.hl` → `// tools/tool.hl`
  52. Spot: `find . -maxdepth 1 -name '*.hl' -print`
  53. **L16.** Keep one topic's central logic and all writes to its tables in `lib/<topic>.hl`, readable at one look; move formatting/parsing/noise and shared helpers to `lib/util.hl` or `lib/<topic>-helpers.hl`, never copy them.
  54. `// components/posts.hl: save logic` → `// lib/posts.hl: save logic`
  55. Spot: review `lib/shows.hl`, `lib/watches.hl`, `lib/sync.hl` by topic; shared env/date/path helpers belong in `lib/util.hl` once.
  56. **L17.** Keep API endpoints, faces and page handlers thin: check input/session, call the topic function, return; no business logic in `api.hl`, `project.hl` or components.
  57. `on server save(String title) { return title.trim() }` → `on server save(String title) { return saveTitle(title) }`
  58. Spot: review handlers; line count alone does not establish thinness.
  59. **L18.** Group plainly by topic without models/repository/services layers, factories or service classes; cleanups preserve behavior, page output and green gates before/after.
  60. `// services/posts.hl: makeService()` → `// lib/posts.hl: save()`
  61. Spot: `find . -type d \( -name models -o -name repository -o -name services \)`; compare gates and page output for cleanups.
  62. Creator: “i ment one central logic per topic … i would also move out noise from it or functions shared between topics … the api is probably just a wrapper that then calls a function from the topic.”
  63. **L19.** Use `echo` for browser output; bare `print`/`log` are native-only builtins and the JS target refuses them.
  64. `print(x)` → `echo(x)`
  65. Spot: `rg -n '\b(print|log)\(' -g '*.hl'` (exclude `console.log` and user bindings).
  66. ## Part B — Framework (owner Arachne)
  67. F1-F21 are checked against the current build. A wrong form marked "refused at build" does not boot; the others compile and need review. Run Spots from the app root.
  68. **F1.** Going somewhere is a link with a real address.
  69. `span { "Post" on click() { navigate(url) } }` → `a { href = url "Post" }`
  70. **F2.** Doing something is a `button` with `type = "button"`.
  71. `b { "✕" on click() { del(id) } }` → `button { type = "button" "✕" on click() { del(id) } }`
  72. **F3.** No `on click` on `b`, `span`, `div`, `li`, `ol`, a custom element, or an `a` without `href`.
  73. Spot: `rg -n '(^|\s)(b|span|div|li|ol|p|[a-z]+-[a-z-]+) \{[^}]*on click' -g '*.hl'`; `rg -n '\ba \{[^}]*on click' -g '*.hl' | rg -v href`; `rg -n -B3 'on click' -g '*.hl'` (element on the line above).
  74. **F4.** Every state a user can return to (page, tab, filter, search, selected row, page number) is in the URL: a route parameter or `route.query`; `navigate(path)` adds a history entry, `navigate(path, replace = true)` replaces it.
  75. `tab = 'songs'` in a handler → route `/artists/:id/:tab`, link `a { href = songsUrl }`; read `route.query.q` (`route = null` member).
  76. **F5.** Reload, Back, Forward and "open in new tab" on any URL show the same state. Checked in the e2e test (F21).
  77. **F6.** The app's own pages are left with `navigate`, never `location.assign`, `location.href =` or `location.replace`; `location.reload()` only on `r.stale` in `on client reconnected(r)`.
  78. `window.location.assign('/')` → `navigate('/')` (`import { navigate } from 'hl:web'`)
  79. Spot: `rg -n 'location\.(assign|replace|href\s*=)' -g '*.hl'`
  80. **F7.** Input is a `form` with named, labelled controls and a submit button; Enter submits; the handler is `on submit(e)`.
  81. `input` + `button { on click() { add() } }` → `form { on submit(e) { add() } label { "Search" input { name = "q" } } button { "Add" } }`
  82. **F8.** State changes are member writes; the framework patches the page.
  83. `document.createElement('li')`, `innerHTML` → `rows.push({ id = 1 title = t })` with `for (r of rows) { li { r.title } }` in the View.
  84. **F9.** No `document.*` or `innerHTML` to find or write app state; a direct DOM write is only a transient gesture effect on the event's own element.
  85. Spot: `rg -n 'document\.|innerHTML' -g '*.hl'`
  86. **F10.** No hand-written JavaScript: no `assets/*.js` logic, no `script { … }` with code, no JS in string members, no `window.*` as state or mailbox. The only exception is F11.
  87. `script { src = '/assets/pwa.js' }` → `.hl` handlers and members
  88. Spot: `rg -n 'script \{|window\.' -g '*.hl'`; `ls assets/*.js`
  89. **F11.** JavaScript is allowed only as an unmodified third-party module, imported at the root of a component by `import js Name from 'module'` (or `import js { a, b } from 'module'`; SPEC.md "import js"); its version is recorded next to the import. App logic, state, DOM building and event wiring stay in `.hl`.
  90. own `main.js` calling the library → `import js Chart from 'chart.js' // 4.4.1` in the `.hl` component
  91. **F12.** Offline, install and push come from the manifest: `offline = [ Page ]`, `offlineFallback`, `offlineFiles`, `appIcons`, `pushKey`. No own service worker.
  92. `{ pattern = "/sw.js" … }` → `offline = [ Home ]` `offlineFallback = Home`
  93. Spot: `rg -n 'sw\.js|serviceWorker' -g '*.hl'`
  94. **F13.** Connection state is `__hlOnline = true`, `__hlReach = 'connecting'` and `on client reachability(r)` / `on client reconnected(r)`; never `window.__hl*`.
  95. `window.__hlAttempt(fetch('/api/online'))` → `__hlReach = 'connecting'` and `if (__hlReach == 'down') { … }`
  96. Spot: `rg -n 'window\.__hl' -g '*.hl'`
  97. **F14.** A component's look lives in its own `Style { }`; no inline `style =`; mobile first (390 px).
  98. `p { style = 'color:red' }` → `Style { warn { color = 'red' } }` and `p { Style.warn }`
  99. Spot: `rg -n "(^|[\s{])style\s*=\s*['\"]" -g '*.hl'`
  100. **F15.** Server data comes from member initializers that read a server import; later changes are `emit client …` (with an `audience` entry for other tabs). No load-on-mount emit, no polling.
  101. `setInterval(() => { reload() }, 5000)` → `all = db.list()` and `on client changed(rows) { all = rows }`
  102. Spot: `rg -n 'setInterval|setTimeout' -g '*.hl'`
  103. **F16.** A component reaches its host with `$parent.fn(x)` in a handler (never in the View or an initializer, never a write); values go in as component arguments (`Row { title = r.title }`); no cross-file emit.
  104. `emit rowPicked()` handled in the host's file → `$parent.pick(rid)`
  105. **F17.** One file is one component; layout through `parent './main.hl'` (the parent declares `slot = null`); routes are in the manifest with `component =`; who is logged in is the `session = null` member.
  106. parsing the cookie → `session = null`, then `session.user`
  107. **F18.** Lists are `for (r of rows)` in the View over records with an `id`, changed by `push`, `upsert(record)` and one-argument `remove(id)`.
  108. `list = list.map((q) => { return q })` in a handler → `rows.upsert(row)`; `rows.remove(rid)`
  109. Spot: `rg -n '\w+ = \w+\.(map|filter)\(' -g '*.hl'`
  110. **F19.** A View attribute is a literal, a member or a field path. Refused at build.
  111. `href = '/posts/' + id` → root `postUrl = '/posts/' + id`, then `href = postUrl`
  112. **F20.** If the framework cannot do it: stop, file a hybriel ticket, wait; a workaround is a finding. Open gaps: mount event (#236), modal dialog (#329).
  113. comment "framework gap" above a bypass → the ticket number in the report, no bypass
  114. **F21.** Each app has a real-browser e2e test that covers F5, keyboard use (Tab, Enter) and, for an `offline` app, an offline reload that still shows the shell.

Branches

Latest commits

  • f97a0e5fMerge branch 'hl-standard' into mainKunibert
  • 9710e39fType STANDARD as String (L10, Kunibert review)mre
  • 4140b664|||PR Review against HL-STANDARD and cite rule ids (gitoria#50 step 3)mre
  • 75c6888drecords: gitoria#50 step 1 connected and provenmre
  • aa6d997frecords: gitoria#50 connect plan, Anton reportmre
  • 8a190ba7Records: kunibert#18 and #15 donemre
  • 2eee9dbbMerge branch 'revendor-day44' into mainKunibert
  • e96721cb|||PR Re-vendor plugins from Hybriel day44 (hl:fetch redirect fix)mre
  • 0c67ab8cLog: kunibert repo ping provenmre
  • b6f3039cLog: kunibert repo connectedmre
  • b143c3c7CONDUCTOR: push recipemre
  • 7a1279eeRule: conductor merges own utility PRs after green reviewmre
  • 4038b3e0Log: kunibert#18 openedmre
  • 18543db1Log: day42 fetch fix, re-vendor pendingmre
  • 81a12f96Statusmre
  • 6ce706abRecords: neutral wording, split cleanupmre
  • 81a4d31bDocs: neutral wordingKunibert
  • 8205b05eRecords: #17 livemre
  • c3391204Answer fresh reviews under open threadsKunibert
  • a0f3d147Records: #16 livemre