rule: a captured value (resource_id) may occur only once over all files #152

Closed
opened 2026-11-17 17:02:27 +01:00 by michael · 1 comment
Owner

Problem

A resource_id marks the place where a message arises: one construction
or send site, one resource_id (rule to be written into daw_i18n/v1,
see the companion issue in DAW/daw-contracts). Nothing checks this. A
copy-pasted site that keeps the old resource_id goes unnoticed.

A count over the sources (without test/ and lib/) found it already:

  • DAW/daw-module-manager: 13 ids used more than once (about 30 sites),
    eight of them in different files
  • DAW/daw-modul-berhtjan-core: 2 ids used twice

Proposal

A rule for fragjan code .: a value that is captured by a pattern may
occur only once over all checked files.

  • first use: resource_id in Lua sources (a UUID string literal given
    as resource_id = "...", or passed as the id argument of a helper)
  • the finding names every site (file:line), not only the second one
  • the rule works over the files of one project, exclude of the
    [check] section applies as for every rule
  • the capture pattern and the scope are configuration, not code, so the
    rule can be used for other values later (e.g. error code per module)

Questions for the implementation

  • can a check primitive keep a value across files, or does this need a
    new check module (fragjan-check-...)?
  • how are the false positives handled (suppress comment as for the other
    rules)?

Acceptance criteria

  • tests first: unique ids pass; the same id in two files and twice in
    one file are each reported with all sites; exclude is respected
  • the rule is part of the Lua project standard so that
    fragjan code . in daw-module-manager and berhtjan-core reports
    the known duplicates
  • fragjan code . and make test (Lua 5.1 and 5.4) pass

DAW/daw-contracts (companion issue: one resource_id per site),
DAW/daw-module-manager, DAW/daw-modul-berhtjan-core (duplicates to fix),
DAW/daw-modul-berhtjan-cli#10 (i18n completeness checker)

## Problem A `resource_id` marks the place where a message arises: one construction or send site, one `resource_id` (rule to be written into `daw_i18n/v1`, see the companion issue in DAW/daw-contracts). Nothing checks this. A copy-pasted site that keeps the old `resource_id` goes unnoticed. A count over the sources (without `test/` and `lib/`) found it already: - DAW/daw-module-manager: 13 ids used more than once (about 30 sites), eight of them in different files - DAW/daw-modul-berhtjan-core: 2 ids used twice ## Proposal A rule for `fragjan code .`: a value that is captured by a pattern may occur only once over all checked files. - first use: `resource_id` in Lua sources (a UUID string literal given as `resource_id = "..."`, or passed as the id argument of a helper) - the finding names every site (`file:line`), not only the second one - the rule works over the files of one project, `exclude` of the `[check]` section applies as for every rule - the capture pattern and the scope are configuration, not code, so the rule can be used for other values later (e.g. error `code` per module) ## Questions for the implementation - can a check primitive keep a value across files, or does this need a new check module (`fragjan-check-...`)? - how are the false positives handled (suppress comment as for the other rules)? ## Acceptance criteria - [ ] tests first: unique ids pass; the same id in two files and twice in one file are each reported with all sites; `exclude` is respected - [ ] the rule is part of the Lua project standard so that `fragjan code .` in daw-module-manager and berhtjan-core reports the known duplicates - [ ] `fragjan code .` and `make test` (Lua 5.1 and 5.4) pass ## Related DAW/daw-contracts (companion issue: one `resource_id` per site), DAW/daw-module-manager, DAW/daw-modul-berhtjan-core (duplicates to fix), DAW/daw-modul-berhtjan-cli#10 (i18n completeness checker)
Author
Owner

Done

  • [OK] New primitive daw.fragjan.check.valueunique (repo daw-modul-fragjan-check-valueunique, v0.1.0): a captured value may occur only once over all given files, every occurrence is reported with file:line
  • [OK] New runner mode target_type: files (DAW/fragjan, commit a658214): all collected files go to the primitive in one call, suppress comments apply per reported match
  • [OK] New rule unique-resource-id in pack daw-lua-code (DAW/fragjan-templates, commit 8c45c29)
  • [OK] Tests first: primitive (21 tests) and runner mode (22 tests), make test green on Lua 5.1 and 5.4
  • [OK] Known duplicates are reported: 33 places in daw-module-manager

Follow-ups (not part of this issue)

  • module.conf of valueunique: raise min for fragjan to the release that contains the runner mode
  • Companion issue in DAW/daw-contracts: one resource_id per error site
  • Remove the duplicates in daw-module-manager and daw-modul-berhtjan-core
## Done - [OK] New primitive `daw.fragjan.check.valueunique` (repo daw-modul-fragjan-check-valueunique, v0.1.0): a captured value may occur only once over all given files, every occurrence is reported with file:line - [OK] New runner mode `target_type: files` (DAW/fragjan, commit a658214): all collected files go to the primitive in one call, suppress comments apply per reported match - [OK] New rule `unique-resource-id` in pack `daw-lua-code` (DAW/fragjan-templates, commit 8c45c29) - [OK] Tests first: primitive (21 tests) and runner mode (22 tests), `make test` green on Lua 5.1 and 5.4 - [OK] Known duplicates are reported: 33 places in daw-module-manager ## Follow-ups (not part of this issue) - [ ] `module.conf` of valueunique: raise `min` for fragjan to the release that contains the runner mode - [ ] Companion issue in DAW/daw-contracts: one `resource_id` per error site - [ ] Remove the duplicates in daw-module-manager and daw-modul-berhtjan-core
michael 2026-11-17 18:54:20 +01:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/fragjan#152
No description provided.