@opendesignai/harness 0.1.0-alpha.0 → 0.2.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/ratchet.md CHANGED
@@ -7,28 +7,44 @@ It fails when:
7
7
  | Check | Fails when |
8
8
  | ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
9
  | `oxlint-suppressions.json`, per rule | the total count of any rule ID grew (summed over all files). Debt may move between files as long as the total does not grow. |
10
- | `oxlint-suppressions.json`, new rule IDs | a rule appears that the base did not have, unless `.oxlintrc.json` or the `@opendesignai/harness` version in `package.json` changed in the same change (both are owner-reviewed). |
11
- | `oxlint-suppressions.json`, new files | an entry names a file that the base commit does not have. New files do not get a baseline, also not in the adoption change or together with a new rule ID; a moved or renamed file counts as new until `od-harness baseline move` exists. |
10
+ | `oxlint-suppressions.json`, new rule IDs | a rule appears that the base did not have, unless the same change upgrades `@opendesignai/harness` or its `.oxlintrc.json` change turns that rule on ([below](#why-a-config-or-version-change-admits-new-rule-ids); both owner-reviewed). |
11
+ | `oxlint-suppressions.json`, new files | an entry names a file that the base commit does not have. New files do not get a baseline, also not in the adoption change or together with a new rule ID. A moved file keeps the entry of its old path ([moved files](#moved-files)). |
12
12
  | both baselines, stale entries | an entry names a file that no longer exists. |
13
- | `.harness/size-baseline.json` | an entry was raised, or a file was added. |
13
+ | `.harness/size-baseline.json` | an entry was raised, or a file was added (except a [moved file](#moved-files)). |
14
14
  | both baselines, new baseline file | the base commit has no such file, unless the same change adds `@opendesignai/harness` to `package.json` (the adoption change). Upgrading the harness or changing `.oxlintrc.json` does not count. |
15
15
 
16
16
  A baseline file may only appear in the adoption change: the change that adds `@opendesignai/harness` to `package.json`, where the base lists it in neither `dependencies` nor `devDependencies`. Then the comparison with the base is skipped and reported. Any later change that creates `oxlint-suppressions.json` or `.harness/size-baseline.json` fails, also one that upgrades the harness or changes `.oxlintrc.json`: a repository that was adopted without a baseline (no existing debt) keeps it that way, and the violations an upgrade or a config change brings are fixed in that change instead of frozen. This does not depend on review, so it holds even when a change is merged without the owner's approval, as long as the caller's workflow keeps `ratchet` on (turning a gate off is a reviewed workflow change).
17
17
 
18
18
  Paths are read relative to the directory `ratchet` runs in, both in the working tree and at the base commit, so it works from a `working-directory` inside a larger repository. `package.json` is read there too, so the adoption change adds `@opendesignai/harness` to the `package.json` of that directory (the `working-directory` of `gates.yml`, which also holds the lockfile).
19
19
 
20
+ ## Moved files
21
+
22
+ Entries may follow a file to a new path; [`od-harness baseline move`](baseline-move.md) rewrites them. `ratchet` accepts an entry for a path the base does not have as a move only when:
23
+
24
+ - git sees the rename between the base and the working tree: `git diff -M30% -l0 <base>`, over the whole change, at 30% similarity or more (below git's default of 50%, so a file that was also edited still counts) and without git's limit on the number of files it compares (`diff.renameLimit`). Nothing else makes a file a move: an unrelated new file never takes over the debt of a deleted one;
25
+ - the old path had an entry in the same baseline at the base and no longer exists (spelled exactly so, also on file systems that ignore case);
26
+ - the moved entry holds no more than the old one did (per rule, or in lines), and each old entry moves to one file only.
27
+
28
+ The rule totals are compared as always, so a move never lets a total grow. Accepted moves are listed in the output (`baseline entry moved from …`, `frozen size moved from …`); rejected ones say which condition failed.
29
+
20
30
  ## Why a config or version change admits new rule IDs
21
31
 
22
- The condition follows the harness plan: a rule ID may enter the baseline only in a change that also changes `.oxlintrc.json` or the `@opendesignai/harness` version in `package.json`. The ratchet does not check whether that change is what enabled the rule. Two things keep this from becoming a way around the gate:
32
+ A rule ID may enter the baseline only in the change that turns the rule on: an owner-reviewed upgrade of `@opendesignai/harness` or change to `.oxlintrc.json`.
33
+
34
+ - **The harness version changed** (`dependencies` or `devDependencies` of `package.json`; for a pnpm catalog reference, `catalog:`, the harness entries of the nearest `pnpm-workspace.yaml`): every new rule ID is admitted. Which rules an upgrade turns on cannot be told in CI (below).
35
+ - **Otherwise, `.oxlintrc.json` changed**: a new rule ID is admitted only when this change turns that rule on. The rule is on in the change's effective configuration, at the top level or in an override, and its settings differ from the base's: another severity or other options, or an override with other `files`. An unrelated edit (an `ignorePatterns` entry, another rule) admits nothing, and neither does restating a rule that a preset or a category already turns on.
36
+ - **Neither changed**: no new rule ID is admitted.
37
+
38
+ The effective configurations come from Oxlint 1.96.0: `oxlint -c <file> --print-config` prints a configuration file with `extends` resolved and categories expanded into rules; `overrides` keep their globs, so an override counts by its `files` and settings. For the base, `ratchet` writes the base commit to a temporary directory (as `unused` does) and links the working tree's `node_modules` into it, so the base's `.oxlintrc.json` extends the installed presets and loads the installed plugins. That is exact because the harness version did not change. If Oxlint cannot print either configuration (it cannot load a plugin, or it is not installed), `ratchet` compares the rule settings written in the two files instead, and says so in the output; then only rules the change sets itself are admitted. Only the file `--lint-config` names counts: nested `.oxlintrc.json` files are separate configurations, which Oxlint prints separately.
39
+
40
+ An upgrade keeps the broader condition: CI installs the change's dependencies only, so the base's configuration would be read with the new harness's presets, a rule the upgrade adds would look enabled at the base already, and the upgrade could not baseline it. Narrowing that case needs the rule list of every harness version in the package ([Next steps](../README.md#next-steps)). Two things keep the remaining room from becoming a way around the gate:
23
41
 
24
42
  - new files never enter a baseline (above), so new code cannot hide debt behind a new rule ID;
25
- - `.oxlintrc.json` and `package.json` belong to the platform owner in CODEOWNERS, so every change that admits a new rule ID is reviewed by the owner.
43
+ - `.oxlintrc.json`, `package.json` and `pnpm-workspace.yaml` belong to the platform owner in CODEOWNERS, so every change that admits a new rule ID is reviewed by the owner.
26
44
 
27
45
  This condition does not admit a new baseline file: only the adoption change may create one (above), so a repository without baselines cannot gain one through a config change or an upgrade, reviewed or not.
28
46
 
29
- A narrower condition is left to a later version.
30
-
31
- The version is read from `dependencies` or `devDependencies` in `package.json`. With a pnpm catalog (`"catalog:"`) the version lives in `pnpm-workspace.yaml`, so an upgrade does not count as a version change there; it admits new rule IDs only together with a change to `.oxlintrc.json`.
47
+ The version is read from `dependencies` or `devDependencies` in `package.json`. With a pnpm catalog (`"catalog:"`), the lines that name `@opendesignai/harness` in the nearest `pnpm-workspace.yaml` (from the working directory up to the repository root) are compared as well, so a catalog upgrade counts as a version change. Only the change that adds the harness to `package.json` is the adoption change, also with a catalog.
32
48
 
33
49
  ## Options
34
50
 
@@ -44,6 +60,6 @@ Exit codes: 0 pass, 1 a check failed, 2 usage error (for example an unknown ref;
44
60
 
45
61
  - **A rule's total grew**: restore `oxlint-suppressions.json` from the base, fix the violations Oxlint reports, then run `oxlint --prune-suppressions` (it can only shrink the file). Never run `oxlint --suppress-all` to get a change through.
46
62
  - **Stale entry**: run `oxlint --prune-suppressions` or `od-harness size --update`.
47
- - **New file in the baseline**: restore the entries from the base, fix the violations in the new file, then run `oxlint --prune-suppressions`. For a moved file, fix the violations at the new path.
63
+ - **New file in the baseline**: restore the entries from the base, fix the violations in the new file, then run `oxlint --prune-suppressions`. For a moved file, run `od-harness baseline move <old path> <new path>` instead; if the move is not accepted, the message names the condition that failed.
48
64
  - **New baseline file**: delete it and fix what `oxlint` or `od-harness size` reports. `oxlint --suppress-all` and `od-harness size --init` are for the adoption change only.
49
65
  - **Size baseline loosened**: restore the entry and move code out of the file.
@@ -12,7 +12,7 @@ const play = `/motion-api/games/${id}/play/index.html`;
12
12
  path.replace(/^\/api\//, "/motion-api/");
13
13
  ```
14
14
 
15
- The bare prefix (`"/api"`) also counts. Module specifiers, type-only literals and regular expressions are not reported.
15
+ The bare prefix (`"/api"`) also counts. Module specifiers, type-only literals (including the type of `x as …` and `x satisfies …`), literals in ambient declarations (`declare …`, which emit no code) and regular expressions are not reported.
16
16
 
17
17
  ## Why
18
18
 
@@ -12,7 +12,7 @@ throw new Error("请求失败");
12
12
  return <span>中文</span>;
13
13
  ```
14
14
 
15
- Comments, module specifiers and type-only literals are not reported. CJK punctuation alone (`,。`) is not reported.
15
+ Comments, module specifiers and type-only literals (including the type of `x as { "标题"(): void }` and `satisfies`) are not reported, nor are literals in ambient declarations (`declare const`, `declare class`, `declare module`, `declare global`), which emit no code. CJK punctuation alone (`,。`) is not reported.
16
16
 
17
17
  ## Why
18
18
 
@@ -20,10 +20,18 @@ An expression holds error message text when it is:
20
20
  - a `.message` member (`err.message`, `error?.message`);
21
21
  - an identifier matching `identifierPattern` (default, case-insensitive: `msg`, `errMsg`, `errorMessage`, `errText`, `errorText`, …);
22
22
  - `String(e)` where `e` matches `errorPattern` (default `e`, `err`, `error`, `ex`, `exc`, `exception`, `cause`);
23
+ - a call to a function named like a message getter (`getErrorMessage(e)`, `archiveErrorMessage(error)`, `errorText(err)`);
23
24
  - `toLowerCase()` / `trim()` / similar on any of the above, `x ?? ""`, or a conditional with such a branch;
24
- - a same-file variable initialised from any of the above (unless `trackAliases` is `false`).
25
+ - unless `trackAliases` is `false`, an alias in the same file:
26
+ - a variable initialised from any of the above, in any order (`const lower = text.toLowerCase()` may come before `const text = err.message`);
27
+ - a parameter of a same-file function that some call passes message text to (`isOutage(lower)` makes `lower` in `function isOutage(lower: string)` message text);
28
+ - a destructured field with the name of such a variable **only** when it is destructured from a call that receives an `errorPattern` identifier (`const { text } = errorFields(e)` when the file has `const text = err.message`); destructuring from unrelated objects (`const { text } = labels`) and imported bindings never fall back by name.
25
29
 
26
- Reported: `includes` / `startsWith` / `endsWith` / `indexOf` / `match` / `search` with a string or regex literal, `regex.test(message)`, and equality with a string literal.
30
+ Aliases follow scopes: a variable declared with something else (`const lower = name.toLowerCase()` in another function) is not message text because another variable of that name is, and neither is a parameter that no call passes message text to.
31
+
32
+ Reported: `includes` / `startsWith` / `endsWith` / `indexOf` / `match` / `search` with a string or regex literal, `regex.test(message)`, and equality with a non-empty string literal. Equality with `""` (`guard.message !== ""`, `x.message === ''`) checks whether there is a message, not its wording, and is not reported.
33
+
34
+ A `.message` member counts whatever its object is called. Error text travels as `failure.message`, `detail.message`, `event.message` (an `ErrorEvent`) or `normalized.message`; limiting the rule to `catch` parameters and `errorPattern` names would silently stop reporting those.
27
35
 
28
36
  ## Why
29
37
 
@@ -52,4 +60,4 @@ Adapters for third-party errors that expose nothing but text belong in one modul
52
60
 
53
61
  ## Limits
54
62
 
55
- A plain `message` or `text` identifier is not treated as error text unless it is assigned from one (chat messages are common). Alias tracking is per file and by name.
63
+ The rule has no type information, so a `message` field of an object that is not an error is still reported when compared with a non-empty string (`prompt.message === "Save?"`). A plain `message` or `text` identifier is not treated as error text unless it is assigned from one (chat messages are common). Alias tracking is per file and follows scopes, falling back by name only for fields destructured from a call passed an `errorPattern` identifier.
@@ -15,11 +15,15 @@ if (useI18n().locale.startsWith("zh")) { … "…" … }
15
15
  "Derived from the locale" means, looking through `!`, `&&`, `||`, parentheses and TypeScript wrappers:
16
16
 
17
17
  1. an identifier matching `aliasPattern` (default `^is(Zh|Chinese|Cn|CN|En|English)$`);
18
- 2. an equality comparison that mentions `locale` (an identifier or a `.locale` member such as `useI18n().locale`);
19
- 3. `startsWith` / `endsWith` / `includes` called on such a value;
20
- 4. a same-file `const`/`let` alias of any of the above (`const zh = locale.startsWith("zh")`), unless `trackAliases` is `false`.
18
+ 2. an equality comparison between a value that mentions `locale` (an identifier or a `.locale` member such as `useI18n().locale`) and a fixed value: a literal, a template without expressions, a constant name (`DEFAULT_LOCALE`, `Locale.ZhCN`), an imported binding or member on one (`zhCN`, `locales.zhCN`), or a same-file `const` bound to a string;
19
+ 3. `startsWith` / `endsWith` / `includes` matching the locale with something fixed: such a value matched against a fixed value (`locale.startsWith("zh")`, `locale.startsWith(ZH_PREFIX)`), or looked up in a list that can be read in the file (`["zh-CN", "zh-TW"].includes(locale)`, `"zh-CN,zh-TW".includes(locale)`, or a same-file `const` bound to either);
20
+ 4. a same-file `const`/`let` alias of any of the above (`const zh = locale.startsWith("zh")`, declared before or after its use), unless `trackAliases` is `false`. Aliases follow scopes: a same-named variable in another function, or a parameter that shadows the alias, is not the alias.
21
21
 
22
- A bare mention such as `/^zh/.test(locale)` does not count.
22
+ A bare mention such as `/^zh/.test(locale)` does not count, nor does comparing two local/parameter values that are not fixed (`next === locale`, `value !== locale`, `locale === settings.locale`): that asks whether they are the same locale, whatever it is, and picks no language.
23
+
24
+ The same holds for matching (3): `supported.includes(locale)`, `SUPPORTED_LOCALES.includes(locale)` (an imported or computed list, whose content the rule cannot read), `locale.startsWith(prefix)`, `path.endsWith(locale)` and a template with expressions are not reported. Nor are comparisons that do not ask which locale it is: its type or length (`typeof locale === "string"`, `locale.length === 2`), whether there is one (`locale === ""`, `locale != null`; a call compared with `null`, such as `locale.match(/^zh/) !== null`, still counts), and a position in a list that cannot be read (`supported.indexOf(locale) === 0`).
25
+
26
+ Comparing with **any** imported value (or member on an imported binding) counts as a locale branch—even if the import holds a mutable value such as `currentLocale`—because copy should come from the i18n catalog (`t()`) or a locale-keyed table rather than a branch on locale.
23
27
 
24
28
  ## Why
25
29
 
@@ -48,4 +52,4 @@ Inline `eslint-disable` / `oxlint-disable` comments for `od/*` rules are rejecte
48
52
 
49
53
  ## Limits
50
54
 
51
- Alias tracking is per file and by name, not by scope. Ported from the prototype of the linter evaluation ([ADR 0001](../decisions/0001-oxlint.md)), where ESLint and Oxlint reported identical lines on opengame (399) and openmotion (73).
55
+ Only values named `locale`, `.locale` members and the aliases above are followed: `navigator.language` or `userLocale === "zh"` is not seen, and `switch (locale)` is not checked. Alias tracking is per file and follows scopes. Ported from the prototype of the linter evaluation ([ADR 0001](../decisions/0001-oxlint.md)), where ESLint and Oxlint reported identical lines on opengame (399) and openmotion (73).
@@ -4,7 +4,17 @@ Preset: `base`
4
4
 
5
5
  ## What it reports
6
6
 
7
- `process.env` (and `process["env"]`) where `process` is the global. A local or imported `process` is not reported.
7
+ Reading `process.env` from the process object, in any of these forms:
8
+
9
+ ```ts
10
+ process.env.PORT; // also process["env"]
11
+ globalThis.process.env.PORT; // also window.process, self.process, global.process
12
+ import { env } from "node:process"; // also "process", `env as e`, and `export { env } from`
13
+ import process from "node:process"; // then process.env; also `import * as p from "process"`
14
+ const { env } = process; // also `{ env: e }` and `({ env } = process)`
15
+ ```
16
+
17
+ A local `process` (a parameter or variable) and a `process` imported from another module are not reported, nor are other members of `process` (`process.argv`).
8
18
 
9
19
  ## Why
10
20
 
@@ -33,3 +33,9 @@ The product registry or identity module that maps ids to manifests can be exempt
33
33
  ```
34
34
 
35
35
  Both default to the values shown. Setting an option replaces its default.
36
+
37
+ `products` defaults to the full product names, because the short ids `game` and `motion` are also ordinary words in product code. In a platform repository the short ids are product identities too (manifest `name`, `/api/<name>/`), so list them explicitly:
38
+
39
+ ```json
40
+ ["error", { "products": ["opengame", "openmotion", "game", "motion"] }]
41
+ ```
@@ -4,15 +4,17 @@ Preset: `base`
4
4
 
5
5
  ## What it reports
6
6
 
7
- References to the global `localStorage` or `sessionStorage`, directly or as `window.` / `globalThis.` / `self.` members:
7
+ References to the global `localStorage` or `sessionStorage`, directly, as `window.` / `globalThis.` / `self.` members (also computed, `window["localStorage"]`), or destructured from those objects:
8
8
 
9
9
  ```ts
10
10
  localStorage.getItem("k");
11
11
  const s = window.sessionStorage;
12
+ const t = globalThis["localStorage"];
13
+ const { localStorage: ls } = window;
12
14
  if (typeof sessionStorage !== "undefined") …
13
15
  ```
14
16
 
15
- Not reported: object keys and class fields named `localStorage`, parameters, imports and local variables that shadow the global, and type-only positions (`typeof localStorage` in a type).
17
+ Not reported: object keys, class members (fields, methods, `accessor`), enum members and labels (`localStorage:` and `break localStorage`) named `localStorage`; parameters, imports and local variables that shadow the global; type-only positions (`typeof localStorage` in a type, the type of `x as { localStorage(): void }`) and ambient declarations (`declare …`), which emit no code.
16
18
 
17
19
  ## Why
18
20
 
@@ -40,7 +40,9 @@ The split itself is configuration: the `shell` and `product` options in the lint
40
40
  ]
41
41
  ```
42
42
 
43
- - `shell`, `product`: repo-relative path patterns. `dir/` matches the directory and everything below it; globs support `**`, `*` and `?` (`dir/**` also matches `dir`); anything else is an exact path. A file is shell when it matches `shell` and does not match `product`.
44
- - `aliases`: import specifier prefix → repo-relative path prefix, for path aliases such as `@/`. An alias matches whole path segments: `"@"` matches `@` and `@/motion/x` but not packages such as `@scope/pkg` or `@motion/game`, and `"@/"` matches specifiers that start with `@/`. Other bare specifiers (packages) are never product paths.
43
+ - `shell`, `product`: repo-relative path patterns. `dir/` matches the directory and everything below it; globs support `**`, `*` and `?` (`dir/**` also matches `dir`); anything else is an exact path. A leading `./` is ignored (`./studio/src/` is `studio/src/`). A file is shell when it matches `shell` and does not match `product`.
44
+ - `aliases`: import specifier prefix → repo-relative path prefix, for path aliases such as `@/`. An alias matches whole path segments: `"@"` matches `@` and `@/motion/x` but not packages such as `@scope/pkg` or `@motion/game`, and `"@/"` matches specifiers that start with `@/`. The rest of the specifier is joined to the target as path segments, so a trailing slash on the key or the target does not matter (`"@/": "studio/src"` and `"@": "studio/src/"` resolve `@/motion/x` to `studio/src/motion/x`). Other bare specifiers (packages) are never product paths.
45
+
46
+ A bundler query on the specifier (`./game/logo.svg?url`, `./shader.glsl?raw`) is removed before resolving: it names the same module.
45
47
 
46
48
  Paths are relative to the directory the linter runs in, so run Oxlint from the repository root.
@@ -4,20 +4,21 @@ Preset: `base`
4
4
 
5
5
  ## What it reports
6
6
 
7
- - An empty `catch` block (comments do not count as handling).
8
- - `.catch(handler)` where the handler only produces `null`, `undefined`, `void …`, `false`, `{}` or `[]`, or has an empty body.
7
+ - An empty `catch` block. Comments, `;` and empty blocks do not count as handling.
8
+ - A rejection handler, `.catch(handler)` or the second argument of `.then(onFulfilled, handler)`, that has an empty body or only produces a constant: a literal (`null`, `false`, `0`, `""`, `"none"`), `undefined`, `void …`, a template literal without expressions, `{}` or `[]`, or no value at all (`return;`).
9
9
 
10
10
  ```ts
11
11
  try {
12
12
  await save();
13
13
  } catch {}
14
14
  const state = await readState().catch(() => null);
15
+ const config = await load().then(parse, () => ({}));
15
16
  ```
16
17
 
17
18
  Not reported:
18
19
 
19
- - a `try` block that only calls cleanup functions (`close`, `cancel`, `abort`, `destroy`, `dispose`, `release`, `rm`, `unlink`, `removeItem`, …), and `.catch()` on such a call: `body.cancel().catch(() => {})`;
20
- - handlers that return a real fallback value (`.catch(() => defaultConfig)`);
20
+ - a `try` block that only calls cleanup functions (`close`, `cancel`, `abort`, `destroy`, `dispose`, `release`, `rm`, `unlink`, `removeItem`, …), and `.catch()` / `.then()` on such a call: `body.cancel().catch(() => {})`;
21
+ - handlers that use the error or return a real fallback value (`.catch(() => defaultConfig)`);
21
22
  - a handler marked with a `// fail-open: <reason>` comment inside it, or on the line of (or just above) the `catch`.
22
23
 
23
24
  ## Why
package/docs/size.md CHANGED
@@ -39,6 +39,7 @@ od-harness size --init # adoption only: create the baseline from the curren
39
39
  - **New file over budget**: split it into smaller modules by responsibility. New files cannot be added to the baseline.
40
40
  - **Frozen file grew**: move the code you added, or more, into a new or existing module.
41
41
  - **Baseline not tightened**: run `od-harness size --update` and commit `.harness/size-baseline.json`.
42
+ - **Frozen file moved or renamed**: run [`od-harness baseline move <old path> <new path>`](baseline-move.md) instead of `--update`, so the frozen size moves with the file; the file is then judged by the entry under its new path.
42
43
 
43
44
  ## Exclusions
44
45
 
package/docs/unused.md ADDED
@@ -0,0 +1,76 @@
1
+ # od-harness unused
2
+
3
+ No new unused files, exports or dependencies. `od-harness unused --base <ref>` runs [knip](https://knip.dev) on the working tree and on the base commit (in CI: `"$HARNESS_BASE_REF"`, the PR base) and fails on findings the base does not have. Existing findings are tolerated; there is no baseline file.
4
+
5
+ ```text
6
+ od-harness unused --base <ref>
7
+ ```
8
+
9
+ Exit codes: 0 nothing new, 1 new findings (or a new tag that hides an export, below), 2 usage or environment error (an unknown ref, no `package.json`, knip failed or printed no report).
10
+
11
+ ## What counts
12
+
13
+ | knip issue type | Reported as |
14
+ | ------------------------------------------------------------- | ----------------- |
15
+ | `files` | unused file |
16
+ | `exports` | unused export |
17
+ | `dependencies`, `devDependencies`, `optionalPeerDependencies` | unused dependency |
18
+
19
+ Unused types, enum members, unlisted or unresolved imports and duplicate exports are not checked. These are the issue types of the maintainability report openmotion and opengame ran before, plus unused `devDependencies`, which knip reports in a field of its own.
20
+
21
+ A finding is identified by its type, its file (relative to the directory od-harness runs in) and its name; line numbers do not matter. A finding is new when the working tree has it more often than the base. Before comparing, every base finding of a file that git sees as renamed (`git diff --find-renames <base>`) moves to the new path, so moving a file or a directory keeps its findings. Locally, stage a move (`git mv` or `git add`) so that git sees it.
22
+
23
+ New findings are also those a change causes elsewhere: deleting the last import of an export makes that export a new unused export. Moving an unused export that the base already has into another file (not a file git sees as renamed) makes it new as well, since it is identified by its file: delete it instead of moving it.
24
+
25
+ ### Tags that hide exports
26
+
27
+ knip never reports an export whose comment has `@public`, `@beta` or `@alias` (knip's `isAlwaysIgnored`; no option turns it off). knip reads these tags in block comments, `/* … */` as well as `/** … */`, and in line comments on a line of their own (`// @public`, also indented); a line comment after code on its line does not count. Comments with only spaces, tabs and line breaks between them form a group, and a tag in any of them applies to the code that follows the group. Such a tag would take a new export out of this gate without review, so `od-harness unused` fails when the change adds or edits, in a JavaScript or TypeScript file:
28
+
29
+ - a comment with one of these tags, or
30
+ - the declaration such a comment documents: every line from the tagged comment to the line where the code after its group starts, up to the closing brace of a multi-line `export { … }` list. This catches a new export put under an existing tag, also with another comment in between.
31
+
32
+ Only comments count. od-harness finds them with the parser knip reads the tags with (oxc-parser, at the version knip depends on), so `/**` or `//` in a string, a template literal, a regular expression or JSX text opens no comment: a glob such as `"src/**"` or test data that holds `/** @public */` is not a tag.
33
+
34
+ Only files with the extensions `.js`, `.jsx`, `.mjs`, `.cjs`, `.ts`, `.tsx`, `.mts` and `.cts` are checked. Their changed lines come from `git diff --text <base>`, so a `-diff` or `binary` attribute in `.gitattributes` does not hide them. knip also reads tags in the scripts of files it compiles, such as `.vue` components in a repository that depends on Vue; a tag in such a file is not caught.
35
+
36
+ Tagged exports the change does not touch are left alone. Other tags do not hide an export in od-harness's run (knip 6.50.0: `@internal` outside production mode, `@knipignore`, `@lintignore`); a `tags` entry in the knip configuration that excludes a tag is an exemption like any other, reviewed by the owner.
37
+
38
+ ### Files that .gitignore excludes
39
+
40
+ knip does not analyse files that `.gitignore` excludes, also tracked ones (`git add -f`), so a file the change adds or edits there, or an existing file the change newly ignores, would escape the gate. `od-harness unused` lists the tracked JavaScript and TypeScript files that ignore rules exclude (`git ls-files --cached --ignored --exclude-standard`, which also reads `.git/info/exclude` and `core.excludesFile` locally) and fails when the change adds or edits one of them, or edits a `.gitignore` file anywhere in the repository. Fix: change the rule so it no longer matches the file, or add a `!path` exception after it, so knip analyses the file. A rule that excludes a parent directory (`dir/`) cannot be undone with `!path`, because git does not look inside an excluded directory: exclude its contents instead (`dir/*`), then add `!dir/file`. A file knip must not analyse is then excluded in the knip configuration (`ignore`, or `entry` if it runs on its own), which the owner reviews. The knip configuration alone does not exempt a file that `.gitignore` excludes: this check reads only the ignore rules, so the rule has to change as well.
41
+
42
+ ## Configuration
43
+
44
+ knip runs with the repository's own configuration (`knip.json`, `knip.jsonc`, `.knip.json`, `.knip.jsonc`, `knip.ts`, `knip.js`, `knip.config.ts`, `knip.config.js` or `package.json#knip`) in the directory od-harness runs in; without one, knip's defaults apply.
45
+
46
+ Both sides run with the working tree's configuration: od-harness copies the configuration files into the base checkout (and the `knip` field of `package.json`), so only code changes count. The change that adds the knip configuration (for example the adoption change) does not turn every existing finding into a new one, and a configuration change neither creates nor hides findings by itself. A `knip.ts` that imports other local files is copied alone.
47
+
48
+ The knip configuration is where exemptions live, so it belongs to the platform owner in CODEOWNERS.
49
+
50
+ ## How the base is analysed
51
+
52
+ The base commit is written to a temporary directory with a temporary git index (`git read-tree` and `git checkout-index`; the repository and its index are not touched, no hooks run, Git LFS objects stay pointers). Every directory that holds a tracked `package.json` and has `node_modules` in the working tree gets a link to it, so knip resolves packages and loads plugin configurations (Vite, Vitest, …) at the base with the dependencies CI installed for the head. knip needs those dependencies: without `node_modules` in the working tree, it cannot load such configuration files and fails (exit 2, "install the dependencies first"). In `gates.yml` the install step comes first.
53
+
54
+ When knip fails on the base with the head's dependencies, typically because the change removed a package that a configuration file of the base imports (a Vite plugin), od-harness removes the links and installs the base's own dependencies in the checkout from its lockfile, as the maintainability report's CI did with `npm ci --prefix <base dir>`: the nearest `pnpm-lock.yaml` (`pnpm install --frozen-lockfile --ignore-scripts`) or `package-lock.json` (`npm ci --ignore-scripts --no-audit --no-fund`) from the working directory up to the repository root. Then knip runs on the base once more, and the output says so. This fallback needs the network and takes as long as a frozen install of the base (about 2 s for a small project with a warm npm cache; a large repository takes as long as its CI install); it only runs when the first attempt failed. If the base still cannot be analysed, or has no lockfile, `unused` stops with exit 2 and says which: the knip configuration of the change is applied to the base too, so a configuration change the base cannot satisfy belongs in a change of its own.
55
+
56
+ ## How to fix a failure
57
+
58
+ The report lists the new findings per type, with a fix and the exemption for each:
59
+
60
+ - **Unused file**: import it where it is needed, or delete it. A file that runs on its own (a script, a worker, a configuration) is an entry point: add it to `entry` in the knip configuration (owner review).
61
+ - **Unused export**: delete the export, or the code, if nothing needs it, or import it where it is meant to be used. Do not export code for later. An export used where knip cannot see it goes into the knip configuration (`entry`, `ignore`, `ignoreExportsUsedInFile`), reviewed by the owner.
62
+ - **Tag that hides an export** (`@public`, `@beta`, `@alias`): remove the tag, then treat the export as above. These tags are not an exemption; the knip configuration is.
63
+ - **Tracked file that `.gitignore` excludes**: change the rule so it no longer matches the file, or add a `!path` exception (for a file in an excluded directory, exclude `dir/*` instead of `dir/`, then add `!dir/file`); then, if knip must not analyse the file, exclude it in the knip configuration. The knip configuration alone is not enough while `.gitignore` still excludes the file.
64
+ - **Unused dependency**: remove it from `package.json` and the lockfile, or import it. A dependency used where knip cannot see it goes into `ignoreDependencies` (owner review).
65
+
66
+ ## Why knip is a dependency of od-harness
67
+
68
+ knip and jscpd are `dependencies` of `@opendesignai/harness`, pinned exactly, not peer dependencies like Oxlint:
69
+
70
+ - only od-harness runs them, never the repository's own scripts, so nothing in the repository has to agree with their version;
71
+ - the comparison runs both sides with the same binary, and the three repositories get the same results from the same harness version;
72
+ - an upgrade of either tool is a harness release, tested here, instead of a change in every repository.
73
+
74
+ A repository that also runs knip itself can keep its own copy at any version; od-harness uses its own.
75
+
76
+ oxc-parser is a dependency for the same reason, pinned to the version knip depends on (a test checks that they match): `unused` reads comments with it, so the tags `unused` finds are the ones knip reads.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@opendesignai/harness",
3
- "version": "0.1.0-alpha.0",
4
- "description": "OpenDesign harness: od/* lint rules for Oxlint (ESLint plugin format), presets, file size budget and baseline ratchet",
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "OpenDesign harness: od/* lint rules for Oxlint (ESLint plugin format), presets, file size budget, baseline ratchet and incremental duplication and unused-code gates",
5
5
  "keywords": [
6
6
  "eslint-plugin",
7
7
  "harness",
@@ -38,14 +38,16 @@
38
38
  "tag": "alpha"
39
39
  },
40
40
  "dependencies": {
41
- "@eslint-community/eslint-plugin-eslint-comments": "4.8.1"
41
+ "@eslint-community/eslint-plugin-eslint-comments": "4.8.1",
42
+ "jscpd": "5.4.3",
43
+ "knip": "6.50.0",
44
+ "oxc-parser": "0.160.0"
42
45
  },
43
46
  "devDependencies": {
44
47
  "@od-harness/ts-eslint-parser": "0.0.0",
45
48
  "@types/node": "26.6.11",
46
49
  "@typescript-eslint/types": "8.74.0",
47
50
  "eslint": "10.16.0",
48
- "knip": "6.50.0",
49
51
  "oxfmt": "0.81.0",
50
52
  "oxlint": "1.96.0",
51
53
  "tsdown": "0.23.8",
@@ -1,5 +1,5 @@
1
1
  {
2
- "options": { "reportUnusedDisableDirectives": "error" },
2
+ "options": { "reportUnusedDisableDirectives": "error", "denyWarnings": true },
3
3
  "plugins": ["eslint", "typescript", "unicorn", "oxc", "react"],
4
4
  "categories": {
5
5
  "correctness": "error"
@@ -25,11 +25,13 @@
25
25
  "react/use-memo": "off",
26
26
  "react/incompatible-library": "off",
27
27
  "react/static-components": "off",
28
+ "unicorn/no-abusive-eslint-disable": "error",
28
29
  "eslint-comments/no-restricted-disable": [
29
30
  "error",
30
31
  "od/*",
31
- "react/rules-of-hooks",
32
- "react-hooks/rules-of-hooks"
32
+ "eslint-comments/*",
33
+ "rules-of-hooks",
34
+ "no-abusive-eslint-disable"
33
35
  ]
34
36
  },
35
37
  "overrides": [