@hublo/sentinel 1.7.0-alpha.3 → 1.7.0-alpha.30
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/README.md +3 -0
- package/dist/bin/sentinel.js +88 -81
- package/dist/{chunk-P6KTBQ2Q.js → chunk-2PRJJRJI.js} +24 -15
- package/dist/{chunk-THTXP2QU.js → chunk-APBEGLRI.js} +6 -6
- package/dist/chunk-APBEGLRI.js.map +1 -0
- package/dist/{chunk-F6ART7RH.js → chunk-HYXFUUF5.js} +14959 -6817
- package/dist/{chunk-4YQXLPJ5.js → chunk-LVY5NPOC.js} +2 -2
- package/dist/chunk-PXTU5MPW.js +9 -0
- package/dist/chunk-PXTU5MPW.js.map +1 -0
- package/dist/chunk-SHF46ALB.js +190 -0
- package/dist/chunk-SHF46ALB.js.map +1 -0
- package/dist/chunk-TMVKYXZ3.js +18 -0
- package/dist/chunk-TMVKYXZ3.js.map +1 -0
- package/dist/chunk-XYOIXC6A.js +126 -0
- package/dist/chunk-XYOIXC6A.js.map +1 -0
- package/dist/{chunk-ZNANJEMK.js → chunk-YUZB4LRJ.js} +35 -16
- package/dist/chunk-YUZB4LRJ.js.map +1 -0
- package/dist/chunk-ZZMYV576.js +297 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -5
- package/dist/{migrate-NWQ3LYER.js → migrate-X7PB2X7R.js} +237 -228
- package/dist/roles/arch/config.d.ts +25 -0
- package/dist/roles/arch/config.js +8 -0
- package/dist/roles/arch/config.js.map +1 -0
- package/dist/roles/build/nest/toolchain.js +3 -3
- package/dist/roles/code-churn/config.d.ts +92 -0
- package/dist/roles/code-churn/config.js +10 -0
- package/dist/roles/code-churn/config.js.map +1 -0
- package/dist/roles/sql/config.d.ts +68 -0
- package/dist/roles/sql/config.js +8 -0
- package/dist/roles/sql/config.js.map +1 -0
- package/dist/roles/static-analysis/config.js +2 -1
- package/dist/roles/test/setup/file-boundary.js +3 -3
- package/dist/roles/test/setup/jest-parity.js +4 -4
- package/dist/roles/test/setup/workspace-entry.js +2 -2
- package/dist/{validate-4V3EGTXN.js → validate-4GMB32V7.js} +2 -2
- package/docs/arch-adoption.md +201 -0
- package/docs/code-churn-adoption.md +237 -0
- package/docs/sql-adoption.md +672 -0
- package/docs/static-analysis-adoption.md +1 -1
- package/docs/static-analysis-study.md +49 -10
- package/docs/typescript-adoption.md +47 -6
- package/docs/typescript-traces.md +546 -6
- package/docs/using-sentinel.md +4 -2
- package/package.json +17 -1
- package/dist/chunk-THTXP2QU.js.map +0 -1
- package/dist/chunk-ZNANJEMK.js.map +0 -1
- /package/dist/{chunk-4YQXLPJ5.js.map → chunk-LVY5NPOC.js.map} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
interface CodeChurnDefaults {
|
|
2
|
+
/** The two durations the figure is made of, in days. */
|
|
3
|
+
window: {
|
|
4
|
+
/**
|
|
5
|
+
* How long after a line is written a change to it counts as rework. 21 days, the window
|
|
6
|
+
* Sourcegraph uses ("code rewritten or deleted within three weeks of being written"); DevStats
|
|
7
|
+
* gives 14 to 21. A change after it is maintenance, not rework, and is not counted.
|
|
8
|
+
*/
|
|
9
|
+
reworkDays: number;
|
|
10
|
+
/**
|
|
11
|
+
* How far back the lines that are measured were written, in days, ending `reworkDays` before
|
|
12
|
+
* the newest commit read. The period stops there so every line it holds has had its full
|
|
13
|
+
* window: a line written yesterday cannot have been rewritten yet, and counting it would lower
|
|
14
|
+
* the figure for a reason that has nothing to do with the code.
|
|
15
|
+
*/
|
|
16
|
+
periodDays: number;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A commit that touches more files than this IN THE MODULE is a sweep, a formatter run or a
|
|
20
|
+
* rename sweep, and its lines are not counted. Counted in the module and not in the repository,
|
|
21
|
+
* which was measured: see `churn.ts`, "What is not counted".
|
|
22
|
+
*/
|
|
23
|
+
maxFilesPerCommit: number;
|
|
24
|
+
/**
|
|
25
|
+
* Where a module's figure stands, in percent, and below how many added lines it has none.
|
|
26
|
+
*
|
|
27
|
+
* Calibrated on hublo/monorepo `main` f12da701121 (2026-07-28 to 2026-10-26): of the 113 sentinel
|
|
28
|
+
* modules, 33 added no line and 44 fewer than 500 (26 in the median), where one rewrite moves the
|
|
29
|
+
* figure by points; over the 36 others, the 25th, 75th and 90th percentiles are 3.1, 11.4 and
|
|
30
|
+
* 15.9%, rounded DOWN to 3, 11 and 16. They say where a module stands among those modules, never
|
|
31
|
+
* whether its code is good, and are recalibrated by a sweep at each stable release.
|
|
32
|
+
*/
|
|
33
|
+
levels: {
|
|
34
|
+
/** Below this many lines added in the period, the module is `quiet`: no percentage stated. */
|
|
35
|
+
minimumAdded: number;
|
|
36
|
+
/** Under this, `low`. */
|
|
37
|
+
low: number;
|
|
38
|
+
/** Over this, `above`. Between `low` and it, `usual`. */
|
|
39
|
+
above: number;
|
|
40
|
+
/** Over this, `watch`. */
|
|
41
|
+
watch: number;
|
|
42
|
+
};
|
|
43
|
+
/** The files whose lines are measured, as globs relative to the module. */
|
|
44
|
+
include: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Measure the tests too. OFF by default: the figure is about the product code, and a test
|
|
47
|
+
* rewritten with the code it checks is the expected case, not rework. A module that decides
|
|
48
|
+
* otherwise sets it to true, and the report says so.
|
|
49
|
+
*/
|
|
50
|
+
includeTests: boolean;
|
|
51
|
+
/** What counts as a test, by path. The list the sql role measured, extended to JavaScript. */
|
|
52
|
+
tests: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Files never measured, whatever `include` says: generated and built output. `*.gen.*` is
|
|
55
|
+
* TanStack Router's `routeTree.gen.ts`, regenerated on every route change (career, console and
|
|
56
|
+
* host-admin on hublo/monorepo): measured, it was one of host-admin's most changed files.
|
|
57
|
+
*/
|
|
58
|
+
ignore: string[];
|
|
59
|
+
/** How many files the report lists, highest churn first. */
|
|
60
|
+
listed: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type DeepPartial<T> = {
|
|
64
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
65
|
+
};
|
|
66
|
+
/** What a module's config file passes. Everything is optional, including the file itself. */
|
|
67
|
+
interface CodeChurnInput {
|
|
68
|
+
/** The module's own directory, normally `import.meta.dirname`. */
|
|
69
|
+
root?: string;
|
|
70
|
+
/** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */
|
|
71
|
+
overrides?: DeepPartial<CodeChurnDefaults>;
|
|
72
|
+
}
|
|
73
|
+
interface ResolvedCodeChurnConfig extends CodeChurnDefaults {
|
|
74
|
+
/** The module's directory, or null when its config file did not say. */
|
|
75
|
+
root: string | null;
|
|
76
|
+
/** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */
|
|
77
|
+
moved: string[];
|
|
78
|
+
}
|
|
79
|
+
/** Resolve a module's declaration against this role's defaults. */
|
|
80
|
+
declare function defineCodeChurn(input?: CodeChurnInput): ResolvedCodeChurnConfig;
|
|
81
|
+
/**
|
|
82
|
+
* The settings of a resolved config that cannot be measured with, one sentence each naming the
|
|
83
|
+
* setting and the value. Empty when the config is usable.
|
|
84
|
+
*
|
|
85
|
+
* ⛔ Checked rather than trusted: a negative window runs the period into the future, a `listed` of
|
|
86
|
+
* -1 drops the last file through `slice(0, -1)`, a cap of 0 makes every commit a sweep, an empty
|
|
87
|
+
* `include` measures nothing, levels that do not rise put every module in two bands at once, and
|
|
88
|
+
* none of them says so. Each one is a figure that looks right.
|
|
89
|
+
*/
|
|
90
|
+
declare function invalidSettings(config: CodeChurnDefaults): string[];
|
|
91
|
+
|
|
92
|
+
export { type CodeChurnInput, type ResolvedCodeChurnConfig, defineCodeChurn, invalidSettings };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** A rule's level. `off` is a module's decision, and the report prints it as one. */
|
|
2
|
+
type Severity = 'off' | 'warn' | 'error';
|
|
3
|
+
interface SqlDefaults {
|
|
4
|
+
/** The migration files squawk reads, as globs relative to the module. */
|
|
5
|
+
migrations: {
|
|
6
|
+
/**
|
|
7
|
+
* ⛔ `migration.sql` BY NAME, and that is what keeps the rollback scripts out. Beside the 871
|
|
8
|
+
* migrations sit 385 `down.sql`, 2 `drop.sql` and one `donw.sql`: scripts a human runs by hand,
|
|
9
|
+
* which Prisma never applies. Reading them would report every `DROP` they are made of, for a
|
|
10
|
+
* file that never reaches production through a deploy. Naming the file Prisma applies, rather
|
|
11
|
+
* than excluding the others, also keeps out the misspelling nobody would think to exclude.
|
|
12
|
+
*/
|
|
13
|
+
include: string[];
|
|
14
|
+
/** Migrations a module chooses not to read. Empty by default. */
|
|
15
|
+
exclude: string[];
|
|
16
|
+
};
|
|
17
|
+
/** What the `Unsafe` rule reads. */
|
|
18
|
+
unsafe: {
|
|
19
|
+
/**
|
|
20
|
+
* Read the tests too. ON by default: 203 of the 226 `Unsafe` calls are in tests, and a call
|
|
21
|
+
* that is safe today is not safe by construction tomorrow. A module that decides otherwise sets
|
|
22
|
+
* it to false, and the report says so; the decision is the team's.
|
|
23
|
+
*/
|
|
24
|
+
includeTests: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* What counts as a test, by PATH. Measured on the monorepo before it was written: the filter
|
|
27
|
+
* `*.spec.*` alone let 149 test calls through as production, because `*.integration-spec.ts`,
|
|
28
|
+
* `*.steps.ts`, `tests/database/` and `*.test-util.ts` are all test code and none of them
|
|
29
|
+
* matches it.
|
|
30
|
+
*/
|
|
31
|
+
tests: string[];
|
|
32
|
+
};
|
|
33
|
+
/** Directories never read, whatever the includes say. */
|
|
34
|
+
ignore: string[];
|
|
35
|
+
/**
|
|
36
|
+
* The PostgreSQL version squawk checks against, since some rules depend on it.
|
|
37
|
+
*
|
|
38
|
+
* 16.8 is the version the monorepo pins (`postgres:16.8`, in its integration tests and its
|
|
39
|
+
* database tooling). The role reads what the repository declares and never asks production.
|
|
40
|
+
*/
|
|
41
|
+
pgVersion: string;
|
|
42
|
+
/**
|
|
43
|
+
* Each rule's level, by name. Empty means every rule at its default, `warn` in this version: the
|
|
44
|
+
* role refuses nothing while its adoption runs.
|
|
45
|
+
*/
|
|
46
|
+
rules: Record<string, Severity>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type DeepPartial<T> = {
|
|
50
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
51
|
+
};
|
|
52
|
+
/** What a module's config file passes. Everything is optional, including the file itself. */
|
|
53
|
+
interface SqlInput {
|
|
54
|
+
/** The module's own directory, normally `import.meta.dirname`. */
|
|
55
|
+
root?: string;
|
|
56
|
+
/** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */
|
|
57
|
+
overrides?: DeepPartial<SqlDefaults>;
|
|
58
|
+
}
|
|
59
|
+
interface ResolvedSqlConfig extends SqlDefaults {
|
|
60
|
+
/** The module's directory, or null when its config file did not say. */
|
|
61
|
+
root: string | null;
|
|
62
|
+
/** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */
|
|
63
|
+
moved: string[];
|
|
64
|
+
}
|
|
65
|
+
/** Resolve a module's declaration against this role's defaults. */
|
|
66
|
+
declare function defineSql(input?: SqlInput): ResolvedSqlConfig;
|
|
67
|
+
|
|
68
|
+
export { type ResolvedSqlConfig, type SqlInput, defineSql };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
alreadyInstalled
|
|
3
3
|
} from "../../../chunk-NUOQXAYR.js";
|
|
4
|
+
import {
|
|
5
|
+
fromModule
|
|
6
|
+
} from "../../../chunk-ELZHIN6E.js";
|
|
4
7
|
import {
|
|
5
8
|
CURRENT_FILE_MOCKS,
|
|
6
9
|
PHASE,
|
|
7
10
|
SHARED_WORKER
|
|
8
11
|
} from "../../../chunk-H3GSGAX2.js";
|
|
9
|
-
import {
|
|
10
|
-
fromModule
|
|
11
|
-
} from "../../../chunk-ELZHIN6E.js";
|
|
12
12
|
|
|
13
13
|
// src/roles/test/setup/file-boundary.ts
|
|
14
14
|
import { afterAll, afterEach, vi } from "vitest";
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
installWorkspaceSetup
|
|
3
|
+
} from "../../../chunk-LVY5NPOC.js";
|
|
1
4
|
import {
|
|
2
5
|
clearDeepMocks,
|
|
3
6
|
resetDeepMocks
|
|
@@ -5,11 +8,8 @@ import {
|
|
|
5
8
|
import {
|
|
6
9
|
alreadyInstalled
|
|
7
10
|
} from "../../../chunk-NUOQXAYR.js";
|
|
8
|
-
import {
|
|
9
|
-
installWorkspaceSetup
|
|
10
|
-
} from "../../../chunk-4YQXLPJ5.js";
|
|
11
11
|
import "../../../chunk-ELZHIN6E.js";
|
|
12
|
-
import "../../../chunk-
|
|
12
|
+
import "../../../chunk-YUZB4LRJ.js";
|
|
13
13
|
|
|
14
14
|
// src/roles/test/setup/jest-parity.ts
|
|
15
15
|
import { expect, vi } from "vitest";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
pinWorkspaceTimezone
|
|
3
|
-
} from "../../../chunk-
|
|
3
|
+
} from "../../../chunk-LVY5NPOC.js";
|
|
4
4
|
import "../../../chunk-ELZHIN6E.js";
|
|
5
|
-
import "../../../chunk-
|
|
5
|
+
import "../../../chunk-YUZB4LRJ.js";
|
|
6
6
|
|
|
7
7
|
// src/roles/test/setup/workspace-entry.ts
|
|
8
8
|
await pinWorkspaceTimezone();
|
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
readTestAdoption,
|
|
8
8
|
resolveVitest,
|
|
9
9
|
suiteOf
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-2PRJJRJI.js";
|
|
11
11
|
import "./chunk-ZFG6P27V.js";
|
|
12
|
-
import "./chunk-ZNANJEMK.js";
|
|
13
12
|
import "./chunk-O7REVMOC.js";
|
|
14
13
|
import "./chunk-H4HAFJFZ.js";
|
|
15
14
|
import "./chunk-QXFCZON7.js";
|
|
15
|
+
import "./chunk-YUZB4LRJ.js";
|
|
16
16
|
|
|
17
17
|
// src/roles/test/validate.ts
|
|
18
18
|
import { execFileSync } from "node:child_process";
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# Architecture check adoption cheat sheet
|
|
2
|
+
|
|
3
|
+
`sentinel --arch` checks a module against an architecture decision of its repository: which
|
|
4
|
+
folder may import which, which names a view may not import, which calls a view may not make. Only
|
|
5
|
+
a violation a branch ADDS to a rule at `error` fails the run: what the module had where the branch
|
|
6
|
+
left main never does, and nothing is recorded to get there.
|
|
7
|
+
|
|
8
|
+
## Adopt a module in two steps
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
# 1. write the module's config, its scripts and the pinned devDependency
|
|
12
|
+
cd apps/front/host-admin
|
|
13
|
+
npx --yes @hublo/sentinel@<version> --init --arch
|
|
14
|
+
|
|
15
|
+
# 2. fetch what step 1 declared, and commit pnpm-lock.yaml with the rest
|
|
16
|
+
pnpm install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Nothing to choose. The repository's `sentinel.arch.json` says which decision governs this module,
|
|
20
|
+
and `--init` writes:
|
|
21
|
+
|
|
22
|
+
| File | What it holds |
|
|
23
|
+
| ----------------- | ---------------------------------------------------------------------------------------- |
|
|
24
|
+
| `arch.config.mjs` | `defineArch`, and in comments each rule of the decision with its level in this module |
|
|
25
|
+
| `package.json` | the `arch`, `arch:json` and `arch:html` scripts, the nx target, `@hublo/sentinel` pinned |
|
|
26
|
+
|
|
27
|
+
The shape of `static-analysis.config.mjs` and `sql.config.mjs`. An existing `arch.config.mjs` is
|
|
28
|
+
the team's and a re-init never rewrites it. If the map applies no decision to the module, `--init`
|
|
29
|
+
says so and writes nothing. An `arch.config.json` or `arch.baseline.json` left by an earlier beta
|
|
30
|
+
is removed: nothing reads them any more.
|
|
31
|
+
|
|
32
|
+
## Everyday use
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm run arch # fails on a violation this branch adds at error
|
|
36
|
+
pnpm run arch:json # arch-report/arch.json, for a machine
|
|
37
|
+
pnpm run arch:html # arch-report/arch.html: each rule, its decision, its status, what to do
|
|
38
|
+
sentinel --run --arch --output markdown # arch-report/arch.md, the pull-request section
|
|
39
|
+
sentinel --inspect --arch # the rule set, and each rule's level here
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
A run prints the files per role (a role with no file usually means a path with a typo in the
|
|
43
|
+
rule set), what it compared with, then one line per rule, then each NEW violation with its file,
|
|
44
|
+
what it reaches and the section of the decision that forbids it:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
architecture ADR 0050: the vertical feature slice is the unit of frontend architecture 5543 files
|
|
48
|
+
compared with origin/main at 310bfc2: only what this branch adds can fail
|
|
49
|
+
✗ G1 A view or route never calls a query client: fetching goes through a hook. 1 new, 4 known
|
|
50
|
+
src/modules/contracts/components/ArchProbeG1.tsx → @tanstack/react-query#useQuery
|
|
51
|
+
why: RFC #19934, Governance readiness, G1
|
|
52
|
+
✓ G2a The api layer never imports a view, not even a type. 0 new, 3 known
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Compared with where the branch left main
|
|
56
|
+
|
|
57
|
+
The module is analysed twice: on the branch (the working tree, uncommitted files included) and at
|
|
58
|
+
the merge base, read from git without touching the checkout. The base is `NX_BASE` in CI and
|
|
59
|
+
`origin/main` elsewhere, as for the sql role. When git cannot say what the base is (no
|
|
60
|
+
`origin/main`, a shallow clone), the run fails and says which command fixes it: comparing with
|
|
61
|
+
nothing would report every violation the module has as new.
|
|
62
|
+
|
|
63
|
+
- A violation is compared by what it is: the rule, the file that breaks it, what it reaches. Not
|
|
64
|
+
by a count, so fixing one and adding another in the same change still fails.
|
|
65
|
+
- A file the branch only moves keeps its violations known, through git's rename detection: a pull
|
|
66
|
+
request reorganising files into feature slices does what the decision asks. Locally, git sees the
|
|
67
|
+
move only once it is staged: move with `git mv`, or `git add` both paths, or the moved file's
|
|
68
|
+
violations read as new until then. CI always sees the commit.
|
|
69
|
+
- A violation the branch removes is gone from the next run, and the report says how many were.
|
|
70
|
+
There is nothing to commit for it.
|
|
71
|
+
- A rule the decision adds is measured on both sides, so the module's existing violations of it
|
|
72
|
+
are known on the day it lands.
|
|
73
|
+
- A file the branch makes unparsable fails the run; one main could not parse either is said, and
|
|
74
|
+
does not fail the branch.
|
|
75
|
+
|
|
76
|
+
## A rule's level in one module
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
// arch.config.mjs
|
|
80
|
+
import { defineArch } from '@hublo/sentinel/arch'
|
|
81
|
+
|
|
82
|
+
export default defineArch({
|
|
83
|
+
root: import.meta.dirname,
|
|
84
|
+
overrides: { severity: { G3: 'warn' } },
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`warn` reports without failing, `off` skips the rule. A name that is not a rule of the set is
|
|
89
|
+
refused, so a typo cannot leave a rule at `error` while you believe it is a warning. The level
|
|
90
|
+
comes from the module's config, then the map, then the rule set.
|
|
91
|
+
|
|
92
|
+
## For the repository: the rules and the map
|
|
93
|
+
|
|
94
|
+
The rules belong to the repository that took the decision, next to its ADR, so a decision and
|
|
95
|
+
its check change in the same pull request and this package needs no release.
|
|
96
|
+
|
|
97
|
+
A rule set (`docs/adr/0050-....rules.json`), in dependency-cruiser's vocabulary plus `roles`:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"name": "ADR 0050: ...",
|
|
102
|
+
"exclude": ["^(?!src/)", "\\.(test|spec|stories)\\.[cm]?[jt]sx?$"],
|
|
103
|
+
"roles": [
|
|
104
|
+
{ "name": "route", "path": "^src/routes/" },
|
|
105
|
+
{ "name": "api", "path": ["(^|/)(services|queries|mutations)/"] },
|
|
106
|
+
{ "name": "view", "path": "\\.(tsx|svelte)$", "exports": "component" }
|
|
107
|
+
],
|
|
108
|
+
"forbidden": [
|
|
109
|
+
{
|
|
110
|
+
"name": "G2a",
|
|
111
|
+
"severity": "error",
|
|
112
|
+
"comment": "The api layer never imports a view.",
|
|
113
|
+
"from": { "role": "api" },
|
|
114
|
+
"to": { "role": "view" }
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Roles are decided first match wins, by path (regular expressions relative to the module) and,
|
|
121
|
+
for `exports: "component"`, by the file's default or same-named export. A file no role matches is
|
|
122
|
+
`unclassified`: counted, never flagged. A role must have a `path` or `exports`.
|
|
123
|
+
|
|
124
|
+
An import is followed to the file that DEFINES each imported name, through barrels
|
|
125
|
+
(`export { x } from`, `export * from`), and that file's role is what a rule reads. Aliases come from
|
|
126
|
+
the workspace's `tsconfig.base.json`, the module's own `tsconfig.json`, and SvelteKit's `$lib` and
|
|
127
|
+
`kit.alias`. An alias that resolves to nothing is reported, not taken for a package.
|
|
128
|
+
|
|
129
|
+
Which kind of rule a `to` makes:
|
|
130
|
+
|
|
131
|
+
| `to` | Forbids |
|
|
132
|
+
| ---------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
133
|
+
| `role` / `path` (`pathNot`, `dependencyTypesNot: ["type-only"]`) | importing a file of that side, inside the module or in a shared library |
|
|
134
|
+
| `module` + `names` | importing those names from that package, as a value |
|
|
135
|
+
| `calls` (+ `module`, a regular expression) | calling those globals, or importing a matching client as a value; `typeImports: true` counts an `import type` of it too |
|
|
136
|
+
| `role` / `path` + `slice: "other"` | the same import, only when it lands in another slice of the module |
|
|
137
|
+
| `classNames` (a regular expression) | a class string written in a `className` or `class` attribute |
|
|
138
|
+
|
|
139
|
+
A rule that states what a file, a class or a directory must BE uses one of these keys instead of
|
|
140
|
+
`to`, one per rule:
|
|
141
|
+
|
|
142
|
+
| Key | Requires | Example |
|
|
143
|
+
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
|
|
144
|
+
| `file` | `name` (a regex on its base name), `exportsItsName`, `exportStar: false`, `interfaceAndSymbol: true`, or `allowed: false` (it does not belong there) | `{ "exportsItsName": { "strip": "\\.controller\\.ts$", "case": "pascal", "append": "Controller" } }` |
|
|
145
|
+
| `bindings` | `binds: "nothing"` (no `{ provide, useClass }`), or `"own-slice"` (only tokens of its own slice) | the application module binds no port |
|
|
146
|
+
| `class` | `implements` / `injects` counted (`to`, `min`, `max`), or exactly these `publicMethods`; `name`, a regex, keeps only the exported classes it names | `{ "name": "UseCase$", "publicMethods": ["execute"] }` |
|
|
147
|
+
| `imports` | `count` of distinct files of `to` (`min`, `max`), or `all`: it imports each kind at once | a route imports exactly one entry view |
|
|
148
|
+
| `inbound` | `slices.min`: at least that many other slices import it | a file in `shared` used by two slices |
|
|
149
|
+
| `directory` | `names` forbidden, `under: "slice"` (directly under a slice root), `withSibling` | no `domain/` beside an `infrastructure/` |
|
|
150
|
+
|
|
151
|
+
A slice is what the rule set's `slices` says: regular expressions with one capture group, the slice
|
|
152
|
+
root, first match wins. Only a file of the same module has a slice; a shared library has none, so it
|
|
153
|
+
is never "another slice". A rule that reads slices in a set that declares none is refused.
|
|
154
|
+
|
|
155
|
+
A violation of these rules names what is wrong in words that stay the same while the violation
|
|
156
|
+
does (`class FooAdapter`, `directory domain`), so a moved count is not a new violation; the count
|
|
157
|
+
is shown beside it.
|
|
158
|
+
|
|
159
|
+
The map (`sentinel.arch.json`, at the workspace root), first match wins:
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"decisions": [
|
|
164
|
+
{
|
|
165
|
+
"modules": ["apps/front/hr-management"],
|
|
166
|
+
"rules": "docs/adr/0050-....rules.json",
|
|
167
|
+
"severity": { "G3": "warn" }
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"modules": ["apps/front/*", "libs/front/*"],
|
|
171
|
+
"rules": "docs/adr/0050-....rules.json"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
"notices": [{ "modules": ["apps/nest/backends-for-frontends/planning"], "text": "..." }]
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
A decision's `severity` is read on every run and never copied into a module, so moving it for a
|
|
179
|
+
family of modules is one reviewed change of the map; a module's own `arch.config.mjs` overrides
|
|
180
|
+
it. Notices are said at adoption and change nothing.
|
|
181
|
+
|
|
182
|
+
A rule set, a map or a module config with a defect is refused before anything runs.
|
|
183
|
+
|
|
184
|
+
`calls` names GLOBALS (`fetch`), never a method: `this.db.$transaction()` is not a call of
|
|
185
|
+
`$transaction`, and a rule listing it is said to have found it only as a method.
|
|
186
|
+
|
|
187
|
+
A module the map gives no decision (neither a front nor a BFF, say) is not checked, and `--init`
|
|
188
|
+
says so. To check it, write its rule set (next to the document that decides its architecture) and
|
|
189
|
+
give it a decision in the map: `{ "modules": ["apps/nest/microservices/network"], "rules":
|
|
190
|
+
"apps/nest/microservices/network/agents/implementation/architecture.rules.json" }`. Paths in a
|
|
191
|
+
violation are the module's for the importing file and the workspace's for its target, since a
|
|
192
|
+
target can be in a shared library.
|
|
193
|
+
|
|
194
|
+
## What the role will not do
|
|
195
|
+
|
|
196
|
+
- Analyse a module whose files did not change: in CI, the modules analysed are those whose own
|
|
197
|
+
files a pull request touches. A shared library that changes can create a violation in a module
|
|
198
|
+
downstream that is not analysed then.
|
|
199
|
+
- Read markup: a `.svelte` file is checked through its `<script>` blocks.
|
|
200
|
+
- Decide a design question no file and import can answer (is this the right boundary for a
|
|
201
|
+
feature). Those stay with the reviewers, as the decisions themselves say.
|