@jterrazz/test 13.0.2 → 14.0.1
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 +20 -20
- package/dist/checker.js +1079 -895
- package/dist/index.d.ts +18 -17
- package/dist/index.js +23 -23
- package/dist/literate.js +26 -21
- package/dist/match.js +44 -7
- package/dist/oxlint.cjs +193 -43
- package/dist/oxlint.js +193 -43
- package/dist/spec-document.js +85 -6
- package/package.json +1 -1
- package/schema/spec.schema.json +1 -1
package/dist/oxlint.cjs
CHANGED
|
@@ -10,7 +10,7 @@ let node_url = require("node:url");
|
|
|
10
10
|
* Cached filesystem probes for the fs-anchored rules (a9w, c2, c6, c7, i2).
|
|
11
11
|
*
|
|
12
12
|
* Rules only ever look at directories NEXT TO files oxlint is already
|
|
13
|
-
* visiting (a feature's `
|
|
13
|
+
* visiting (a feature's `_requests/`, `_seeds/`, `_expected/`, a sibling module
|
|
14
14
|
* file), so the probe set is small — but several rules probe the same feature
|
|
15
15
|
* directory, and oxlint lints many files per process. A module-level cache
|
|
16
16
|
* keeps each `readdir`/`stat` to one syscall per lint run.
|
|
@@ -341,7 +341,7 @@ const RULE_DOCS = {
|
|
|
341
341
|
},
|
|
342
342
|
"c1-domain-structure": {
|
|
343
343
|
channel: "statique",
|
|
344
|
-
convention: "La forme de l’arbre `specs/` se déclare via l’option `depth` : `facet-domain` (défaut — `*.test.ts` à la profondeur facet/domain, `*.specification.ts` au root de la facette), `facet` (test au root de la facette OU un dossier domaine plus bas, jamais plus profond), `mirror` (test à toute profondeur ≥ 1, nommé d’après son dossier), `off`.",
|
|
344
|
+
convention: "La forme de l’arbre `specs/` se déclare via l’option `depth` : `facet-domain` (défaut — `*.test.ts` à la profondeur facet/domain, `*.specification.ts` au root de la facette), `facet` (test au root de la facette OU un dossier domaine plus bas, jamais plus profond), `mirror` (test à toute profondeur ≥ 1, nommé d’après son dossier), `off`. Dans tous les modes, `off` compris : un dossier à underscore initial est du SOL, jamais un domaine — aucune spec ne vit dedans. Une exception, et une seule : le sol peut être du CODE, et un `<module>.test.ts` posé À CÔTÉ du `<module>.ts` qu’il teste y est légal (c’est la loi I2) ; un test sans module voisin, ou un `*.specification.ts`, reste une violation.",
|
|
345
345
|
family: "C",
|
|
346
346
|
id: "C1",
|
|
347
347
|
rationale: "Une profondeur fixe rend la place de chaque fichier prévisible et détectable statiquement."
|
|
@@ -360,9 +360,16 @@ const RULE_DOCS = {
|
|
|
360
360
|
id: "C11",
|
|
361
361
|
rationale: "Une donnée n’existe que servie par un contrat — un fichier sans propriétaire est du poids mort qu’aucun test ne charge."
|
|
362
362
|
},
|
|
363
|
+
"c13-underscored-ground": {
|
|
364
|
+
channel: "statique",
|
|
365
|
+
convention: "Sous `specs/`, le sol d’une spec porte un underscore initial : `_fixtures/`, `_expected/`, `_requests/`, `_seeds/`. Un dossier `fixtures/`, `expected/`, `requests/` ou `seeds/` est un nom d’avant la 14 — erreur nommant le renommage.",
|
|
366
|
+
family: "C",
|
|
367
|
+
id: "C13",
|
|
368
|
+
rationale: "Aucun résolveur ne lit plus le nom sans underscore : gardé tel quel, l’arbre devient invisible plutôt que faux, et l’échec arrive une étape plus loin que sa cause."
|
|
369
|
+
},
|
|
363
370
|
"c2-http-only-requests": {
|
|
364
371
|
channel: "statique",
|
|
365
|
-
convention: "`
|
|
372
|
+
convention: "`_requests/` ne contient que des fichiers `.http` ; toute autre extension est une erreur.",
|
|
366
373
|
family: "C",
|
|
367
374
|
id: "C2",
|
|
368
375
|
rationale: "Une entrée de requête est un `.http` complet — homogénéiser le dossier interdit les formats ad hoc."
|
|
@@ -379,11 +386,11 @@ const RULE_DOCS = {
|
|
|
379
386
|
convention: "L’argument de `toMatch` porte son extension (`'help.txt'`), sauf pour les snapshots d’arborescence (dossiers) ; un sujet fichier sans extension est une erreur.",
|
|
380
387
|
family: "C",
|
|
381
388
|
id: "C6",
|
|
382
|
-
rationale: "L’extension fait partie du nom du fichier attendu — l’omettre casse la résolution `
|
|
389
|
+
rationale: "L’extension fait partie du nom du fichier attendu — l’omettre casse la résolution `_expected/`."
|
|
383
390
|
},
|
|
384
391
|
"c7-seeds-sql-only": {
|
|
385
392
|
channel: "statique",
|
|
386
|
-
convention: "`
|
|
393
|
+
convention: "`_seeds/` ne contient que des `*.sql` ; tout autre fichier est une erreur.",
|
|
387
394
|
family: "C",
|
|
388
395
|
id: "C7",
|
|
389
396
|
rationale: "`.seed()` porte l’état des bases uniquement — pas de seed-handler ni de dispatch par préfixe."
|
|
@@ -425,7 +432,7 @@ const RULE_DOCS = {
|
|
|
425
432
|
},
|
|
426
433
|
"d9w-single-use-ref": {
|
|
427
434
|
channel: "statique",
|
|
428
|
-
convention: "Une ref de capture (`match.ref`, `{{kind#ref}}`) qui n’apparaît qu’une seule fois dans tout le fichier (code + fixtures `
|
|
435
|
+
convention: "Une ref de capture (`match.ref`, `{{kind#ref}}`) qui n’apparaît qu’une seule fois dans tout le fichier (code + fixtures `_expected/` référencées) porte un nom inutilement → warning.",
|
|
429
436
|
family: "D",
|
|
430
437
|
id: "D9",
|
|
431
438
|
rationale: "Une ref ne se justifie que si elle asserte l’égalité sur au moins deux occurrences."
|
|
@@ -567,7 +574,7 @@ const RULE_DOCS = {
|
|
|
567
574
|
const CHECKER_PASSES = [
|
|
568
575
|
{
|
|
569
576
|
channel: "checker",
|
|
570
|
-
convention: "Tout `{{token}}` dans une fixture `
|
|
577
|
+
convention: "Tout `{{token}}` dans une fixture `_expected/` — ou dans un flux attendu d’un document `<cas>.spec.yaml` — appartient au vocabulaire figé ; un token inconnu est une erreur.",
|
|
571
578
|
family: "D",
|
|
572
579
|
id: "D4",
|
|
573
580
|
name: "d4-unknown-token",
|
|
@@ -575,7 +582,7 @@ const CHECKER_PASSES = [
|
|
|
575
582
|
},
|
|
576
583
|
{
|
|
577
584
|
channel: "checker",
|
|
578
|
-
convention: "Une ref malformée d’un kind connu (`{{iso8601#}}`, `{{uuid #id}}`) dans un fichier texte sous `
|
|
585
|
+
convention: "Une ref malformée d’un kind connu (`{{iso8601#}}`, `{{uuid #id}}`) dans un fichier texte sous `_expected/` est une erreur.",
|
|
579
586
|
family: "D",
|
|
580
587
|
id: "D4",
|
|
581
588
|
name: "d4-malformed-ref",
|
|
@@ -583,7 +590,7 @@ const CHECKER_PASSES = [
|
|
|
583
590
|
},
|
|
584
591
|
{
|
|
585
592
|
channel: "checker",
|
|
586
|
-
convention: "La première ligne d’un `.http` de profondeur 1 suit sa grammaire : requête (`MÉTHODE /path`) sous `
|
|
593
|
+
convention: "La première ligne d’un `.http` de profondeur 1 suit sa grammaire : requête (`MÉTHODE /path`) sous `_requests/`, statut (`HTTP/1.1 <status>`) sous `_expected/`.",
|
|
587
594
|
family: "D",
|
|
588
595
|
id: "D4b",
|
|
589
596
|
name: "d4b-http-first-line",
|
|
@@ -679,7 +686,7 @@ const CHECKER_PASSES = [
|
|
|
679
686
|
},
|
|
680
687
|
{
|
|
681
688
|
channel: "checker",
|
|
682
|
-
convention: "Un token connu dans un fichier sous `
|
|
689
|
+
convention: "Un token connu dans un fichier sous `_requests/` → warning : les requêtes sont des entrées, jamais matchées.",
|
|
683
690
|
family: "D",
|
|
684
691
|
id: "D10",
|
|
685
692
|
name: "d10w-tokens-in-requests",
|
|
@@ -687,12 +694,28 @@ const CHECKER_PASSES = [
|
|
|
687
694
|
},
|
|
688
695
|
{
|
|
689
696
|
channel: "checker",
|
|
690
|
-
convention: "Aucune fixture morte : tout fichier sous `
|
|
697
|
+
convention: "Aucune fixture morte : tout fichier sous `_seeds/`/`_requests/`/`_fixtures/` et toute entrée de premier niveau de `_expected/` doit être référencée ; un dossier de feature sans `*.test.ts` ni `*.spec.yaml` est orphelin (warning si argument non littéral). Un `<cas>.spec.yaml` référence les fixtures nommées par ses entrées `fixture:`.",
|
|
691
698
|
family: "C",
|
|
692
699
|
id: "C9",
|
|
693
700
|
name: "c9-dead-fixtures",
|
|
694
701
|
rationale: "Le miroir de C8 — une fixture que rien ne référence est du poids mort qui trompe le lecteur."
|
|
695
702
|
},
|
|
703
|
+
{
|
|
704
|
+
channel: "checker",
|
|
705
|
+
convention: "Une fixture du pool est PARTAGÉE, ou elle est locale : un dossier de `<specs>/_fixtures/` référencé (`$FIXTURES/<nom>`) depuis un seul dossier de spec — deux documents d’une même feuille comptent pour un — doit vivre à côté de cette feuille, en `<feuille>/_fixtures/<nom>/`, référencé par la forme relative. Zéro référence reste l’erreur de fixture morte (C9). Corrigé par `--fix` : le dossier est déplacé et les littéraux réécrits.",
|
|
706
|
+
family: "C",
|
|
707
|
+
id: "C14",
|
|
708
|
+
name: "c14-pool-fixture-shared",
|
|
709
|
+
rationale: "Une fixture d’un seul scénario garée dans le pool se lit comme du sol partagé : chacun suppose qu’un autre en dépend et personne n’ose y toucher."
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
channel: "checker",
|
|
713
|
+
convention: "Une fixture locale ne se lit que depuis son propre dossier : un chemin `fixture:`/`.fixture()` contenant `..`, ou dont la cible sort du `_fixtures/` de la spec qui le nomme, est une erreur — le sol partagé par plusieurs feuilles va dans le pool `$FIXTURES`.",
|
|
714
|
+
family: "C",
|
|
715
|
+
id: "C15",
|
|
716
|
+
name: "c15-local-fixture-reach",
|
|
717
|
+
rationale: "Une feuille qui pioche dans les fixtures d’une voisine, c’est le pool par une autre porte, sans la visibilité du pool : la voisine casse une spec à deux dossiers de là sans le savoir."
|
|
718
|
+
},
|
|
696
719
|
{
|
|
697
720
|
channel: "checker",
|
|
698
721
|
convention: "Canal principal de B5 : les runners docker-aware sont inférés de l’option `docker:` du fichier de specification importé, puis chaque résultat `.exec()` lié sans `await using` est signalé.",
|
|
@@ -1236,16 +1259,58 @@ const a9wRedundantRoot = {
|
|
|
1236
1259
|
}
|
|
1237
1260
|
};
|
|
1238
1261
|
//#endregion
|
|
1262
|
+
//#region src/core/specification/shared/ground.ts
|
|
1263
|
+
/**
|
|
1264
|
+
* The GROUND a row of specs stands on — the naming law of a spec tree.
|
|
1265
|
+
*
|
|
1266
|
+
* In a row of specs, a MEMBER is a spec: `<aspect>.test.ts`, `<case>.spec.yaml`,
|
|
1267
|
+
* `<name>.specification.ts`, and the facet/domain folders that hold them.
|
|
1268
|
+
* Everything else in that row is what the members STAND ON — inert material the
|
|
1269
|
+
* framework resolves BY PATH, never imported, never executed — and it carries a
|
|
1270
|
+
* LEADING UNDERSCORE. A spec's own folder never does.
|
|
1271
|
+
*
|
|
1272
|
+
* Four names, and only four: `_fixtures/` (file state), `_expected/` (goldens),
|
|
1273
|
+
* `_requests/` (inputs), `_seeds/` (database state). `contracts/` is NOT ground —
|
|
1274
|
+
* a contract is TypeScript a spec imports, behaviour composed with the spec's own,
|
|
1275
|
+
* so it stays a member. `docker/` is not ground either: it sits at the PROJECT
|
|
1276
|
+
* root beside `package.json`, outside any row of specs.
|
|
1277
|
+
*
|
|
1278
|
+
* This module is the single home of those names. Every resolver, matcher, lint
|
|
1279
|
+
* rule and checker pass reads them from here, so the runtime and the static
|
|
1280
|
+
* channels cannot disagree about where a spec's ground lives.
|
|
1281
|
+
*/
|
|
1282
|
+
/** Goldens: every expected fixture, flat, extension included. */
|
|
1283
|
+
const GROUND_EXPECTED = "_expected";
|
|
1284
|
+
/** File state copied into a working directory by `.fixture()`. */
|
|
1285
|
+
const GROUND_FIXTURES = "_fixtures";
|
|
1286
|
+
/** Inputs: complete `.http` request documents. */
|
|
1287
|
+
const GROUND_REQUESTS = "_requests";
|
|
1288
|
+
/** Database state: `.sql` fragments loaded by `.seed()`. */
|
|
1289
|
+
const GROUND_SEEDS = "_seeds";
|
|
1290
|
+
/**
|
|
1291
|
+
* The pre-14 name of each ground directory → the name it carries now. Kept for
|
|
1292
|
+
* ONE purpose: naming the rename in a diagnostic (`c13-underscored-ground`).
|
|
1293
|
+
* Nothing resolves through it — an un-underscored directory is invisible to
|
|
1294
|
+
* every resolver, which is exactly why it must be reported rather than tolerated.
|
|
1295
|
+
*/
|
|
1296
|
+
const RENAMED_GROUND_DIRS = {
|
|
1297
|
+
expected: GROUND_EXPECTED,
|
|
1298
|
+
fixtures: GROUND_FIXTURES,
|
|
1299
|
+
requests: GROUND_REQUESTS,
|
|
1300
|
+
seeds: GROUND_SEEDS
|
|
1301
|
+
};
|
|
1302
|
+
//#endregion
|
|
1239
1303
|
//#region src/core/specification/shared/fixtures.ts
|
|
1240
1304
|
/**
|
|
1241
1305
|
* Fixture path resolution + copy semantics for the `cli` facet's `.fixture()`.
|
|
1242
1306
|
*
|
|
1243
1307
|
* A fixture path is one of two shapes:
|
|
1244
1308
|
*
|
|
1245
|
-
* - `$FIXTURES/<rest>` — the shared pool at `<specs-root>/
|
|
1309
|
+
* - `$FIXTURES/<rest>` — the shared pool at `<specs-root>/_fixtures/<rest>`,
|
|
1246
1310
|
* where `<specs-root>` is the nearest ancestor directory named `specs`.
|
|
1247
|
-
* - `<path>` (no marker) — feature-local, at `<test-dir>/
|
|
1311
|
+
* - `<path>` (no marker) — feature-local, at `<test-dir>/_fixtures/<path>`.
|
|
1248
1312
|
*
|
|
1313
|
+
* The leading underscore is the ground rule of a spec tree ({@link GROUND_FIXTURES}).
|
|
1249
1314
|
* Any other `$`-prefixed marker is a usage error (listed against the known
|
|
1250
1315
|
* markers). Copy semantics mirror rsync's trailing-slash rule (see
|
|
1251
1316
|
* {@link copyPlan}).
|
|
@@ -1539,6 +1604,14 @@ const TEST_SUFFIX = ".test.ts";
|
|
|
1539
1604
|
const SPECIFICATION_SUFFIX = ".specification.ts";
|
|
1540
1605
|
const DEFAULT_DEPTH = "facet-domain";
|
|
1541
1606
|
/**
|
|
1607
|
+
* Whether a file is the unit test of the module it sits beside — `x.test.ts`
|
|
1608
|
+
* next to `x.ts`, which is the whole of I2's pairing. This is what tells a
|
|
1609
|
+
* ground MODULE's test from a spec that wandered into the ground.
|
|
1610
|
+
*/
|
|
1611
|
+
function testsItsNeighbour(filename) {
|
|
1612
|
+
return filename.endsWith(TEST_SUFFIX) && isFile(`${filename.slice(0, -8)}.ts`);
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1542
1615
|
* CONVENTIONS C1' — the shape of a spec tree, DECLARED by the consumer.
|
|
1543
1616
|
*
|
|
1544
1617
|
* A project states which shape its `specs/` tree has; the rule checks that one.
|
|
@@ -1580,7 +1653,18 @@ const DEFAULT_DEPTH = "facet-domain";
|
|
|
1580
1653
|
* specs root. Specification files are unconstrained: a mirror has no facet
|
|
1581
1654
|
* level to anchor them to.
|
|
1582
1655
|
*
|
|
1583
|
-
* `depth: 'off'` — no
|
|
1656
|
+
* `depth: 'off'` — no DEPTH check; the tree's shape is guarded elsewhere.
|
|
1657
|
+
*
|
|
1658
|
+
* The ground clause holds in every mode, `off` included: a directory whose name
|
|
1659
|
+
* carries a LEADING UNDERSCORE is ground — what the specs of a row stand on —
|
|
1660
|
+
* and never a domain, so no SPEC may live inside one. That is not a question of
|
|
1661
|
+
* depth, which is why no project's declared shape switches it off.
|
|
1662
|
+
*
|
|
1663
|
+
* Ground is not always inert, though: it may be CODE the specs stand on — the
|
|
1664
|
+
* build of the subject under test, a harness the runner spawns. A `<module>.ts`
|
|
1665
|
+
* there keeps its own unit test under I2's law, `<module>.test.ts` NEXT to it,
|
|
1666
|
+
* and the clause lets that one pair through. Nothing else: a test with no module
|
|
1667
|
+
* beside it, or a `*.specification.ts`, is a spec that wandered into the ground.
|
|
1584
1668
|
*
|
|
1585
1669
|
* Module tests under `src/` follow the neighbour rule (I2) and are out of scope
|
|
1586
1670
|
* in every mode.
|
|
@@ -1588,12 +1672,23 @@ const DEFAULT_DEPTH = "facet-domain";
|
|
|
1588
1672
|
const c1DomainStructure = {
|
|
1589
1673
|
create(context) {
|
|
1590
1674
|
const depth = context.options[0]?.depth ?? DEFAULT_DEPTH;
|
|
1591
|
-
if (depth === "off") return {};
|
|
1592
1675
|
return { Program(node) {
|
|
1593
1676
|
const anchor = specsAnchor(context.filename);
|
|
1594
1677
|
if (anchor === void 0) return;
|
|
1595
1678
|
const base = anchor.relative.at(-1) ?? "";
|
|
1596
1679
|
const nesting = anchor.relative.length - 1;
|
|
1680
|
+
if (base.endsWith(TEST_SUFFIX) || base.endsWith(SPECIFICATION_SUFFIX)) {
|
|
1681
|
+
const ground = anchor.relative.slice(0, -1).find((segment) => segment.startsWith("_"));
|
|
1682
|
+
if (ground !== void 0) {
|
|
1683
|
+
if (!testsItsNeighbour(context.filename)) context.report({
|
|
1684
|
+
data: { ground },
|
|
1685
|
+
messageId: "specInGround",
|
|
1686
|
+
node
|
|
1687
|
+
});
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
if (depth === "off") return;
|
|
1597
1692
|
if (depth === "facet") {
|
|
1598
1693
|
if (base.endsWith(TEST_SUFFIX)) {
|
|
1599
1694
|
if (nesting < 1) context.report({
|
|
@@ -1652,6 +1747,7 @@ const c1DomainStructure = {
|
|
|
1652
1747
|
defaultOptions: [{ depth: DEFAULT_DEPTH }],
|
|
1653
1748
|
docs: RULE_DOCS["c1-domain-structure"],
|
|
1654
1749
|
messages: {
|
|
1750
|
+
specInGround: "A spec must not live under \"{{ground}}/\" — a leading underscore marks GROUND (what the specs of a row stand on: _fixtures/, _expected/, _requests/, _seeds/), never a domain (C1 — see docs/10-linting.md). Ground that is CODE keeps its own unit test: `<module>.test.ts` NEXT to the `<module>.ts` it tests (I2), and nothing else.",
|
|
1655
1751
|
specNotAtFacetRoot: "A `*.specification.ts` must sit at the facet root: `specs/<facet>/<name>.specification.ts` (C1 — see docs/10-linting.md).",
|
|
1656
1752
|
testAtFacetRoot: "A `*.test.ts` must live in a domain folder: `specs/<facet>/<domain>/<aspect>.test.ts` — tests directly at the facet root are forbidden (C1 — see docs/10-linting.md).",
|
|
1657
1753
|
testAtSpecsRoot: "A `*.test.ts` must live in a directory under specs/ — with `depth: \"mirror\"` the tree mirrors a structure, and the specs root mirrors nothing (C1 — see docs/10-linting.md).",
|
|
@@ -1709,7 +1805,7 @@ const c10ContractsBoundary = {
|
|
|
1709
1805
|
};
|
|
1710
1806
|
//#endregion
|
|
1711
1807
|
//#region src/lint/rules/c11-contract-data-pairing.ts
|
|
1712
|
-
const TEST_FILE$
|
|
1808
|
+
const TEST_FILE$12 = /\.test\.[cm]?[jt]sx?$/;
|
|
1713
1809
|
/** The provider folders that may carry data files. */
|
|
1714
1810
|
const PROVIDERS$1 = [
|
|
1715
1811
|
"anthropic",
|
|
@@ -1733,7 +1829,7 @@ function ownerOf(entry) {
|
|
|
1733
1829
|
const c11ContractDataPairing = {
|
|
1734
1830
|
create(context) {
|
|
1735
1831
|
const file = context.physicalFilename;
|
|
1736
|
-
if (!TEST_FILE$
|
|
1832
|
+
if (!TEST_FILE$12.test(file) || !segments(file).includes("specs")) return {};
|
|
1737
1833
|
return { Program(node) {
|
|
1738
1834
|
const contractsDir = (0, node_path.join)((0, node_path.dirname)(file), "contracts");
|
|
1739
1835
|
for (const provider of PROVIDERS$1) {
|
|
@@ -1763,13 +1859,66 @@ const c11ContractDataPairing = {
|
|
|
1763
1859
|
}
|
|
1764
1860
|
};
|
|
1765
1861
|
//#endregion
|
|
1862
|
+
//#region src/lint/rules/c13-underscored-ground.ts
|
|
1863
|
+
const TEST_FILE$11 = /\.test\.[cm]?[jt]sx?$/;
|
|
1864
|
+
/**
|
|
1865
|
+
* CONVENTIONS C13 — the ground of a spec carries a leading underscore. A
|
|
1866
|
+
* directory named `fixtures/`, `expected/`, `requests/` or `seeds/` under
|
|
1867
|
+
* `specs/` is a pre-14 name: since `@jterrazz/test` 14.0.0 the four are
|
|
1868
|
+
* `_fixtures/`, `_expected/`, `_requests/` and `_seeds/`, with no compatibility
|
|
1869
|
+
* fallback.
|
|
1870
|
+
*
|
|
1871
|
+
* The catch this rule exists for: a consumer that upgrades and keeps the old
|
|
1872
|
+
* names loses nothing loudly. Every resolver — `.fixture()`, `.seed()`,
|
|
1873
|
+
* `.request()`, `toMatch()` — looks under the underscored name, finds nothing,
|
|
1874
|
+
* and the tree becomes invisible rather than wrong. The failure that follows is
|
|
1875
|
+
* "fixture does not exist" on every spec at once, one step removed from the
|
|
1876
|
+
* cause; this rule states the cause and the rename.
|
|
1877
|
+
*
|
|
1878
|
+
* Anchored on the feature's visited test file, exactly as C2/C7/C11 are: the
|
|
1879
|
+
* spec's own sibling directories are probed, plus the `$FIXTURES` pool at the
|
|
1880
|
+
* nearest specs root. A DOMAIN folder named after the ground it holds
|
|
1881
|
+
* (`specs/api/requests/_requests/`) is never a probe target — only what sits
|
|
1882
|
+
* beside a spec is.
|
|
1883
|
+
*/
|
|
1884
|
+
const c13UnderscoredGround = {
|
|
1885
|
+
create(context) {
|
|
1886
|
+
const file = context.physicalFilename;
|
|
1887
|
+
const anchor = specsAnchor(file);
|
|
1888
|
+
if (!TEST_FILE$11.test(file) || anchor === void 0) return {};
|
|
1889
|
+
return { Program(node) {
|
|
1890
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1891
|
+
const probe = (parent, legacy) => {
|
|
1892
|
+
const path = (0, node_path.join)(parent, legacy);
|
|
1893
|
+
if (seen.has(path) || !isDirectory(path)) return;
|
|
1894
|
+
seen.add(path);
|
|
1895
|
+
context.report({
|
|
1896
|
+
data: {
|
|
1897
|
+
ground: RENAMED_GROUND_DIRS[legacy],
|
|
1898
|
+
legacy
|
|
1899
|
+
},
|
|
1900
|
+
messageId: "notUnderscored",
|
|
1901
|
+
node
|
|
1902
|
+
});
|
|
1903
|
+
};
|
|
1904
|
+
for (const legacy of Object.keys(RENAMED_GROUND_DIRS)) probe((0, node_path.dirname)(file), legacy);
|
|
1905
|
+
probe(anchor.directory, "fixtures");
|
|
1906
|
+
} };
|
|
1907
|
+
},
|
|
1908
|
+
meta: {
|
|
1909
|
+
docs: RULE_DOCS["c13-underscored-ground"],
|
|
1910
|
+
messages: { notUnderscored: "The directory \"{{legacy}}/\" is a pre-14 ground name — rename it to \"{{ground}}/\" (`git mv {{legacy}} {{ground}}`). What a spec stands on carries the underscore; a spec's own folder never does, and no resolver reads the un-underscored name (C13 — see docs/10-linting.md)." },
|
|
1911
|
+
type: "problem"
|
|
1912
|
+
}
|
|
1913
|
+
};
|
|
1914
|
+
//#endregion
|
|
1766
1915
|
//#region src/lint/rules/c2-http-only-requests.ts
|
|
1767
1916
|
const TEST_FILE$10 = /\.test\.[cm]?[jt]sx?$/;
|
|
1768
1917
|
/**
|
|
1769
|
-
* CONVENTIONS C2 — `
|
|
1918
|
+
* CONVENTIONS C2 — `_requests/` contains only `.http` files (a request file is
|
|
1770
1919
|
* a COMPLETE request: method, path, headers, body). Anchored on the feature's
|
|
1771
1920
|
* visited test file: when `<feature>/<feature>.test.ts` is linted, its sibling
|
|
1772
|
-
* `
|
|
1921
|
+
* `_requests/` directory is probed (cached readdir) and any non-`.http` entry
|
|
1773
1922
|
* is reported on the test file.
|
|
1774
1923
|
*/
|
|
1775
1924
|
const c2HttpOnlyRequests = {
|
|
@@ -1777,7 +1926,7 @@ const c2HttpOnlyRequests = {
|
|
|
1777
1926
|
const file = context.physicalFilename;
|
|
1778
1927
|
if (!TEST_FILE$10.test(file) || !segments(file).includes("specs")) return {};
|
|
1779
1928
|
return { Program(node) {
|
|
1780
|
-
const requestsDir = (0, node_path.join)((0, node_path.dirname)(file),
|
|
1929
|
+
const requestsDir = (0, node_path.join)((0, node_path.dirname)(file), GROUND_REQUESTS);
|
|
1781
1930
|
for (const entry of listDirectory(requestsDir) ?? []) if (!entry.endsWith(".http")) context.report({
|
|
1782
1931
|
data: { entry },
|
|
1783
1932
|
messageId: "notHttp",
|
|
@@ -1787,7 +1936,7 @@ const c2HttpOnlyRequests = {
|
|
|
1787
1936
|
},
|
|
1788
1937
|
meta: {
|
|
1789
1938
|
docs: RULE_DOCS["c2-http-only-requests"],
|
|
1790
|
-
messages: { notHttp: "
|
|
1939
|
+
messages: { notHttp: "_requests/{{entry}} is not a .http file — _requests/ contains only complete .http request files (C2 — see docs/10-linting.md)." },
|
|
1791
1940
|
type: "problem"
|
|
1792
1941
|
}
|
|
1793
1942
|
};
|
|
@@ -2045,11 +2194,11 @@ function subjectIsDirectory(toMatchCallee) {
|
|
|
2045
2194
|
/**
|
|
2046
2195
|
* CONVENTIONS C6 — the extension is part of the fixture name and mandatory in
|
|
2047
2196
|
* `toMatch` (`'help.txt'`, never `'help'`) — except for directory-tree
|
|
2048
|
-
* snapshots, which are directories under `
|
|
2197
|
+
* snapshots, which are directories under `_expected/`.
|
|
2049
2198
|
*
|
|
2050
2199
|
* The directory exception is resolved two ways: statically, when the expect
|
|
2051
2200
|
* subject visibly chains `.directory(…)`; else on disk, when
|
|
2052
|
-
* `
|
|
2201
|
+
* `_expected/<name>/` exists next to the spec (cached stat).
|
|
2053
2202
|
*/
|
|
2054
2203
|
const c6ToMatchExtension = {
|
|
2055
2204
|
create(context) {
|
|
@@ -2063,7 +2212,7 @@ const c6ToMatchExtension = {
|
|
|
2063
2212
|
if (name === void 0 || name.length === 0) return;
|
|
2064
2213
|
if ((name.split("/").at(-1) ?? "").includes(".")) return;
|
|
2065
2214
|
if (subjectIsDirectory(callee)) return;
|
|
2066
|
-
if (isDirectory((0, node_path.join)((0, node_path.dirname)(file), "
|
|
2215
|
+
if (isDirectory((0, node_path.join)((0, node_path.dirname)(file), "_expected", name))) return;
|
|
2067
2216
|
context.report({
|
|
2068
2217
|
data: { name },
|
|
2069
2218
|
messageId: "missingExtension",
|
|
@@ -2073,7 +2222,7 @@ const c6ToMatchExtension = {
|
|
|
2073
2222
|
},
|
|
2074
2223
|
meta: {
|
|
2075
2224
|
docs: RULE_DOCS["c6-tomatch-extension"],
|
|
2076
|
-
messages: { missingExtension: "toMatch(\"{{name}}\") is missing its extension — the extension is part of the fixture name (\"help.txt\", never \"help\"); only directory-tree snapshots (
|
|
2225
|
+
messages: { missingExtension: "toMatch(\"{{name}}\") is missing its extension — the extension is part of the fixture name (\"help.txt\", never \"help\"); only directory-tree snapshots (_expected/<name>/) omit it (C6 — see docs/10-linting.md)." },
|
|
2077
2226
|
type: "problem"
|
|
2078
2227
|
}
|
|
2079
2228
|
};
|
|
@@ -2081,17 +2230,17 @@ const c6ToMatchExtension = {
|
|
|
2081
2230
|
//#region src/lint/rules/c7-seeds-sql-only.ts
|
|
2082
2231
|
const TEST_FILE$7 = /\.test\.[cm]?[jt]sx?$/;
|
|
2083
2232
|
/**
|
|
2084
|
-
* CONVENTIONS C7 — `.seed()` carries DATABASE state only: `
|
|
2233
|
+
* CONVENTIONS C7 — `.seed()` carries DATABASE state only: `_seeds/` contains
|
|
2085
2234
|
* nothing but `*.sql` fragments. File state goes through `.fixture()`; there
|
|
2086
2235
|
* is no seed handler and no prefix dispatch. Anchored on the feature's visited
|
|
2087
|
-
* test file (cached readdir of the sibling `
|
|
2236
|
+
* test file (cached readdir of the sibling `_seeds/`).
|
|
2088
2237
|
*/
|
|
2089
2238
|
const c7SeedsSqlOnly = {
|
|
2090
2239
|
create(context) {
|
|
2091
2240
|
const file = context.physicalFilename;
|
|
2092
2241
|
if (!TEST_FILE$7.test(file) || !segments(file).includes("specs")) return {};
|
|
2093
2242
|
return { Program(node) {
|
|
2094
|
-
const seedsDir = (0, node_path.join)((0, node_path.dirname)(file),
|
|
2243
|
+
const seedsDir = (0, node_path.join)((0, node_path.dirname)(file), GROUND_SEEDS);
|
|
2095
2244
|
for (const entry of listDirectory(seedsDir) ?? []) if (!entry.endsWith(".sql")) context.report({
|
|
2096
2245
|
data: { entry },
|
|
2097
2246
|
messageId: "notSql",
|
|
@@ -2101,18 +2250,18 @@ const c7SeedsSqlOnly = {
|
|
|
2101
2250
|
},
|
|
2102
2251
|
meta: {
|
|
2103
2252
|
docs: RULE_DOCS["c7-seeds-sql-only"],
|
|
2104
|
-
messages: { notSql: "
|
|
2253
|
+
messages: { notSql: "_seeds/{{entry}} is not a .sql file — _seeds/ carries database state only; file state goes through .fixture() (C7 — see docs/10-linting.md)." },
|
|
2105
2254
|
type: "problem"
|
|
2106
2255
|
}
|
|
2107
2256
|
};
|
|
2108
2257
|
//#endregion
|
|
2109
2258
|
//#region src/lint/rules/c8-referenced-fixture-exists.ts
|
|
2110
2259
|
const TEST_FILE$6 = /\.test\.[cm]?[jt]sx?$/;
|
|
2111
|
-
/** The
|
|
2260
|
+
/** The ground directory each fixture-referencing verb reads from. */
|
|
2112
2261
|
const VERB_ROOTS = {
|
|
2113
|
-
request:
|
|
2114
|
-
seed:
|
|
2115
|
-
toMatch:
|
|
2262
|
+
request: GROUND_REQUESTS,
|
|
2263
|
+
seed: GROUND_SEEDS,
|
|
2264
|
+
toMatch: GROUND_EXPECTED
|
|
2116
2265
|
};
|
|
2117
2266
|
/**
|
|
2118
2267
|
* A fixture reference is a filename/path, never inline content. `.seed()` also
|
|
@@ -2124,15 +2273,15 @@ function looksLikePath(value) {
|
|
|
2124
2273
|
}
|
|
2125
2274
|
/** Resolve the on-disk target a `.fixture()` literal points at, if determinable. */
|
|
2126
2275
|
function resolveFixture(argument, featureDir, specsDir) {
|
|
2127
|
-
if (argument.startsWith("$FIXTURES/")) return (0, node_path.join)(specsDir,
|
|
2276
|
+
if (argument.startsWith("$FIXTURES/")) return (0, node_path.join)(specsDir, GROUND_FIXTURES, argument.slice(10));
|
|
2128
2277
|
if (argument.startsWith("$")) return;
|
|
2129
|
-
return (0, node_path.join)(featureDir,
|
|
2278
|
+
return (0, node_path.join)(featureDir, GROUND_FIXTURES, argument);
|
|
2130
2279
|
}
|
|
2131
2280
|
/**
|
|
2132
2281
|
* CONVENTIONS C8 — a fixture referenced by a literal must exist on disk under
|
|
2133
|
-
* its
|
|
2134
|
-
* `.fixture(x)`→
|
|
2135
|
-
* `specs/
|
|
2282
|
+
* its ground root: `.request(x)`→`_requests/x`, `.seed(x)`→`_seeds/x`,
|
|
2283
|
+
* `.fixture(x)`→the leaf's `_fixtures/` (or the `$FIXTURES/` pool at the nearest
|
|
2284
|
+
* `specs/_fixtures/`), `toMatch(x)`→`_expected/x` (file or tree snapshot). A typo
|
|
2136
2285
|
* that would fail only at runtime is caught statically. Non-literal arguments
|
|
2137
2286
|
* are out of static reach and skipped.
|
|
2138
2287
|
*/
|
|
@@ -2154,7 +2303,7 @@ const c8ReferencedFixtureExists = {
|
|
|
2154
2303
|
if (target !== void 0 && !isFile(target) && !isDirectory(target)) context.report({
|
|
2155
2304
|
data: {
|
|
2156
2305
|
path: value,
|
|
2157
|
-
root:
|
|
2306
|
+
root: GROUND_FIXTURES
|
|
2158
2307
|
},
|
|
2159
2308
|
messageId: "missing",
|
|
2160
2309
|
node: args[0]
|
|
@@ -2178,7 +2327,7 @@ const c8ReferencedFixtureExists = {
|
|
|
2178
2327
|
},
|
|
2179
2328
|
meta: {
|
|
2180
2329
|
docs: RULE_DOCS["c8-referenced-fixture-exists"],
|
|
2181
|
-
messages: { missing: "Referenced fixture \"{{path}}\" does not exist on disk under its
|
|
2330
|
+
messages: { missing: "Referenced fixture \"{{path}}\" does not exist on disk under its ground {{root}}/ root (C8 — see docs/10-linting.md). Create it or fix the reference." },
|
|
2182
2331
|
type: "problem"
|
|
2183
2332
|
}
|
|
2184
2333
|
};
|
|
@@ -2592,7 +2741,7 @@ const d6wTransformTokenEquivalent = {
|
|
|
2592
2741
|
},
|
|
2593
2742
|
meta: {
|
|
2594
2743
|
docs: RULE_DOCS["d6w-transform-token-equivalent"],
|
|
2595
|
-
messages: { tokenEquivalent: "This transform only rewrites output into known token literals — write the tokens in the
|
|
2744
|
+
messages: { tokenEquivalent: "This transform only rewrites output into known token literals — write the tokens in the _expected/ fixture instead; transform is an escape hatch for uncovered noise (D6 — see docs/10-linting.md)." },
|
|
2596
2745
|
type: "suggestion"
|
|
2597
2746
|
}
|
|
2598
2747
|
};
|
|
@@ -2661,7 +2810,7 @@ function refsInFixture(target) {
|
|
|
2661
2810
|
* `{{uuid#order}}`) earns its keep only when it is asserted more than once (the
|
|
2662
2811
|
* point of a capture is the equality check on later occurrences). Aggregating
|
|
2663
2812
|
* per file — code `match.ref` literals plus the `{{kind#ref}}` tokens of the
|
|
2664
|
-
* `
|
|
2813
|
+
* `_expected/` fixtures the file references — a ref that appears exactly once
|
|
2665
2814
|
* everywhere is a plain matcher wearing a name.
|
|
2666
2815
|
*/
|
|
2667
2816
|
const d9wSingleUseRef = {
|
|
@@ -2689,7 +2838,7 @@ const d9wSingleUseRef = {
|
|
|
2689
2838
|
if (memberPropertyName(node.callee) === "toMatch") {
|
|
2690
2839
|
const name = stringValue(node.arguments?.[0]);
|
|
2691
2840
|
if (name !== void 0) {
|
|
2692
|
-
const target = (0, node_path.join)(featureDir,
|
|
2841
|
+
const target = (0, node_path.join)(featureDir, GROUND_EXPECTED, name.replace(/\/+$/, ""));
|
|
2693
2842
|
for (const ref of refsInFixture(target)) {
|
|
2694
2843
|
bump(ref);
|
|
2695
2844
|
if (!fixtureNodes.has(ref)) fixtureNodes.set(ref, node);
|
|
@@ -3543,6 +3692,7 @@ const plugin = {
|
|
|
3543
3692
|
"c1-domain-structure": c1DomainStructure,
|
|
3544
3693
|
"c10-contracts-boundary": c10ContractsBoundary,
|
|
3545
3694
|
"c11-contract-data-pairing": c11ContractDataPairing,
|
|
3695
|
+
"c13-underscored-ground": c13UnderscoredGround,
|
|
3546
3696
|
"c2-http-only-requests": c2HttpOnlyRequests,
|
|
3547
3697
|
"c4-contract-shape": c4ContractShape,
|
|
3548
3698
|
"c6-tomatch-extension": c6ToMatchExtension,
|