@jterrazz/test 15.1.1 → 15.2.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/dist/ambiguity.js +23 -4
- package/dist/artifacts.js +68 -160
- package/dist/browser/index.js +2477 -0
- package/dist/checker.js +9 -3
- package/dist/index.d.ts +807 -497
- package/dist/index.js +3034 -2770
- package/dist/intercept.js +108 -58
- package/dist/oxlint.cjs +434 -21
- package/dist/oxlint.d.cts +13 -1
- package/dist/oxlint.d.ts +13 -1
- package/dist/oxlint.js +434 -21
- package/dist/playwright.adapter.js +95 -22
- package/dist/queue.js +1 -1
- package/dist/vitest.d.ts +100 -2
- package/dist/vitest.js +375 -3
- package/package.json +37 -5
package/dist/oxlint.cjs
CHANGED
|
@@ -173,9 +173,6 @@ function walk(root, visit) {
|
|
|
173
173
|
} else if (isNode(value)) walk(value, visit);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
|
-
function isNode(value) {
|
|
177
|
-
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
178
|
-
}
|
|
179
176
|
/** The source start offset of a node or comment (oxlint `start`, else `range[0]`). */
|
|
180
177
|
function nodeStart(node) {
|
|
181
178
|
if (node === void 0) return -1;
|
|
@@ -222,6 +219,27 @@ function importSourceVisitor(onSource) {
|
|
|
222
219
|
ImportExpression: fromSourceField
|
|
223
220
|
};
|
|
224
221
|
}
|
|
222
|
+
/** Is this value an AST node — an object carrying a `type` string? */
|
|
223
|
+
function isNode(value) {
|
|
224
|
+
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* A node's child by key, or `undefined` when the key holds something else.
|
|
228
|
+
*
|
|
229
|
+
* Every rule reaches for `node.parent`, `node.id`, `node.value`; the node shape
|
|
230
|
+
* types them as `unknown`, so each reach was an assertion of its own. One
|
|
231
|
+
* guarded read is the same answer, checked once.
|
|
232
|
+
*/
|
|
233
|
+
function child(node, key) {
|
|
234
|
+
const value = node?.[key];
|
|
235
|
+
return isNode(value) ? value : void 0;
|
|
236
|
+
}
|
|
237
|
+
/** The name of an identifier node, or `undefined` for anything else. */
|
|
238
|
+
function identifierName(node) {
|
|
239
|
+
if (node?.type !== "Identifier") return;
|
|
240
|
+
const { name } = node;
|
|
241
|
+
return typeof name === "string" ? name : void 0;
|
|
242
|
+
}
|
|
225
243
|
//#endregion
|
|
226
244
|
//#region src/lint/manifest.ts
|
|
227
245
|
/**
|
|
@@ -350,7 +368,7 @@ const RULE_DOCS = {
|
|
|
350
368
|
},
|
|
351
369
|
"c1-domain-structure": {
|
|
352
370
|
channel: "statique",
|
|
353
|
-
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.",
|
|
371
|
+
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. Un `.test.tsx` est hors de portée : une unité rendue se spécifie à côté de son composant, jamais dans un arbre facette/domaine — c’est I2 qui tient son voisinage.",
|
|
354
372
|
family: "C",
|
|
355
373
|
id: "C1",
|
|
356
374
|
rationale: "Une profondeur fixe rend la place de chaque fichier prévisible et détectable statiquement."
|
|
@@ -467,6 +485,36 @@ const RULE_DOCS = {
|
|
|
467
485
|
id: "D15",
|
|
468
486
|
rationale: "Un statut isolé ne fige que le code de réponse et jette tout le reste du payload ; le golden complet capture la forme entière et sa grammaire de tokens (complète d12w, qui exige un amas de sondes de corps et manque le cas de la sonde de statut solitaire)."
|
|
469
487
|
},
|
|
488
|
+
"e5-no-simulated-dom": {
|
|
489
|
+
channel: "statique",
|
|
490
|
+
convention: "Un fichier de test ne déclare pas de DOM simulé : la pragma `@vitest-environment happy-dom|jsdom` est une erreur. Portée : les rôles qui EXÉCUTENT un test (`module`, `component`, `specification`) — une config de projet est le domaine de E5b.",
|
|
491
|
+
facet: "component",
|
|
492
|
+
family: "E",
|
|
493
|
+
fix: "Déplacer le test à côté de son composant en `.test.tsx` et le faire collecter par le projet `component()`.",
|
|
494
|
+
id: "E5",
|
|
495
|
+
rationale: "Un DOM simulé se comporte PRESQUE comme un navigateur, et ce qui est livré est jugé par un vrai : la facette component rend dans le Chromium que la facette website pilote déjà.",
|
|
496
|
+
reach: "tests"
|
|
497
|
+
},
|
|
498
|
+
"e5b-no-simulated-dom-config": {
|
|
499
|
+
channel: "statique",
|
|
500
|
+
convention: "Une config vitest ne déclare pas de DOM simulé : `environment: 'happy-dom'|'jsdom'` est une erreur ; `'node'` et `'edge-runtime'` nomment un vrai runtime et restent hors de portée.",
|
|
501
|
+
facet: "component",
|
|
502
|
+
family: "E",
|
|
503
|
+
fix: "Supprimer `environment` et collecter le rendu avec `component()` ; les tests de module restent sous node.",
|
|
504
|
+
id: "E5b",
|
|
505
|
+
rationale: "La pragma (E5) n’engage qu’un fichier ; la config engage tout ce que le projet collecte — c’est ainsi qu’un dépôt hérite d’un DOM simulé que personne n’a choisi test par test.",
|
|
506
|
+
reach: "config"
|
|
507
|
+
},
|
|
508
|
+
"e6-component-project-helper": {
|
|
509
|
+
channel: "statique",
|
|
510
|
+
convention: "Un projet navigateur vient de `component()` : dans une config vitest, une clé `browser` sous `test` qui n'est pas dans un appel à `component(...)` est une erreur. Une clé `browser` ailleurs (un `define`, un enregistrement d'env) n'est pas un bloc de projet et reste hors de portée.",
|
|
511
|
+
facet: "component",
|
|
512
|
+
family: "E",
|
|
513
|
+
fix: "Remplacer le bloc par `component({ vite })` et ne garder que ce qui appartient au projet.",
|
|
514
|
+
id: "E6",
|
|
515
|
+
rationale: "Le provider épinglé à la version exacte du runner, le service worker servi depuis l’installation du framework, la transformation JSX du Vite courant, le pré-bundling d’un cache froid et les dossiers d’artefacts sont autant de runs qui passent ici et échouent sur la machine suivante.",
|
|
516
|
+
reach: "config"
|
|
517
|
+
},
|
|
470
518
|
"f1-no-subpath-import": {
|
|
471
519
|
channel: "statique",
|
|
472
520
|
convention: "Tout s’importe depuis `@jterrazz/test` ; un import de `@jterrazz/test/<subpath>` est une erreur, sauf les subpaths que la map `exports` du paquet publie — `@jterrazz/test/oxlint` (plugin de lint) et `@jterrazz/test/vitest` (surface de configuration du runner) — exemptés partout. La liste est LUE du manifeste, jamais recopiée dans la règle.",
|
|
@@ -502,6 +550,26 @@ const RULE_DOCS = {
|
|
|
502
550
|
id: "F5",
|
|
503
551
|
rationale: "Cantonner les fixtures aux tests empêche la donnée de test de fuir dans le code de prod."
|
|
504
552
|
},
|
|
553
|
+
"f6-no-foreign-test-runtime": {
|
|
554
|
+
channel: "statique",
|
|
555
|
+
convention: "Un fichier de test n’importe pas de second runtime de test : `@testing-library/*`, `happy-dom`, `jsdom`, `vitest/browser`, `vitest-browser-*` et `@vitest/browser*` sont des erreurs. Portée : les rôles qui EXÉCUTENT un test (`module`, `component`, `specification`) — la config d’un projet fixture et un module de providers sous `specs/` nomment légitimement l’adaptateur.",
|
|
556
|
+
facet: "component",
|
|
557
|
+
family: "F",
|
|
558
|
+
fix: "Passer par la facette qui remplace le seam : `component.render()`, le vocabulaire d’éléments et le visiteur.",
|
|
559
|
+
id: "F6",
|
|
560
|
+
rationale: "Un test qui importe l’adaptateur parle le dialecte de l’adaptateur : un dépôt finit avec autant de vocabulaires que de seams. Les groupes livrés sont ceux que la facette component REMPLACE ; le reste de la famille suit la vague de règles.",
|
|
561
|
+
reach: "tests"
|
|
562
|
+
},
|
|
563
|
+
"g4-no-dom-in-module-test": {
|
|
564
|
+
channel: "statique",
|
|
565
|
+
convention: "Un test de module ne touche aucun global du DOM : `document`, `window`, `navigator`, `HTMLElement` référencés en position de VALEUR dans un fichier de rôle `module` HORS de `specs/` sont une erreur. Un nom en position de type (`x as HTMLElement`) et un garde `typeof window` n’atteignent aucun document et restent hors de portée ; tant que le rôle `spec` n’existe pas, `module` couvre aussi les `.test.ts` de `specs/`, que la règle laisse donc passer.",
|
|
566
|
+
facet: "component",
|
|
567
|
+
family: "G",
|
|
568
|
+
fix: "Renommer le test en `.test.tsx` à côté du composant qu’il rend, et le faire collecter par `component()`.",
|
|
569
|
+
id: "G4",
|
|
570
|
+
rationale: "Un test de module tourne sous node, où `document` n’existe pas : un test qui en réclame un ne teste pas un module, il rend quelque chose — et il a désormais un endroit où aller.",
|
|
571
|
+
reach: "module"
|
|
572
|
+
},
|
|
505
573
|
"i1-layer-boundaries": {
|
|
506
574
|
channel: "statique",
|
|
507
575
|
convention: "Le projet DÉCLARE ses couches sous `src/` via l’option `layers` (paquets autorisés, imports internes, un dossier = une dépendance, seams) ; tout import hors des arêtes déclarées est une erreur. Sans carte de couches, la règle est inerte.",
|
|
@@ -511,9 +579,11 @@ const RULE_DOCS = {
|
|
|
511
579
|
},
|
|
512
580
|
"i2-sibling-test-naming": {
|
|
513
581
|
channel: "statique",
|
|
514
|
-
convention: "Le test de `<fichier>.ts` est `<fichier>.test.ts` à côté de lui ; un `.test.ts` mal nommé, ou un dossier `__tests__/`, est une erreur.",
|
|
582
|
+
convention: "Le test de `<fichier>.ts` est `<fichier>.test.ts` à côté de lui ; un `.test.ts` mal nommé, ou un dossier `__tests__/`, est une erreur. Une unité RENDUE obéit à la même loi où qu’elle vive : un `.test.tsx` est voisin du `.tsx` qu’il rend, ou du `.ts` du hook ou de la fonction DOM dont il porte l’hôte.",
|
|
515
583
|
family: "I",
|
|
584
|
+
fix: "Poser le test à côté de l’unité qu’il couvre, sous le même basename.",
|
|
516
585
|
id: "I2",
|
|
586
|
+
reach: "tests",
|
|
517
587
|
rationale: "Des tests voisins (parité avec le `foo_test.go` de Go) gardent test et code ensemble et découvrables."
|
|
518
588
|
},
|
|
519
589
|
"i4-no-vi-mock-in-src": {
|
|
@@ -844,14 +914,19 @@ function sortKey(entry) {
|
|
|
844
914
|
];
|
|
845
915
|
}
|
|
846
916
|
[
|
|
847
|
-
...Object.entries(RULE_DOCS).map(([name, doc]) =>
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
917
|
+
...Object.entries(RULE_DOCS).map(([name, doc]) => {
|
|
918
|
+
const entry = {
|
|
919
|
+
channel: doc.channel,
|
|
920
|
+
convention: doc.convention,
|
|
921
|
+
family: doc.family,
|
|
922
|
+
id: doc.id,
|
|
923
|
+
name,
|
|
924
|
+
rationale: doc.rationale
|
|
925
|
+
};
|
|
926
|
+
if ("fix" in doc) entry.fix = doc.fix;
|
|
927
|
+
if ("reach" in doc) entry.reach = doc.reach;
|
|
928
|
+
return entry;
|
|
929
|
+
}),
|
|
855
930
|
...CHECKER_PASSES,
|
|
856
931
|
...RUNTIME_RULES,
|
|
857
932
|
...PROCESS_RULES
|
|
@@ -863,6 +938,55 @@ function sortKey(entry) {
|
|
|
863
938
|
return av.localeCompare(bv);
|
|
864
939
|
});
|
|
865
940
|
//#endregion
|
|
941
|
+
//#region src/lint/role.ts
|
|
942
|
+
/** The four ground names — what the specs of a row stand ON, never a spec. */
|
|
943
|
+
const GROUND = /* @__PURE__ */ new Set([
|
|
944
|
+
"_expected",
|
|
945
|
+
"_fixtures",
|
|
946
|
+
"_requests",
|
|
947
|
+
"_seeds"
|
|
948
|
+
]);
|
|
949
|
+
/** A vitest config, whatever extension the project writes it in. */
|
|
950
|
+
const CONFIG = /^vitest\.config\.[cm]?[jt]s$/u;
|
|
951
|
+
/**
|
|
952
|
+
* The kind of file this path names.
|
|
953
|
+
*
|
|
954
|
+
* The suffix decides, and the order matters: a `*.specification.ts` is a
|
|
955
|
+
* specification wherever it sits, ground swallows anything under it that is not
|
|
956
|
+
* a test of its own module, and `.tsx` versus `.ts` is what tells a RENDERED
|
|
957
|
+
* unit from a plain one — the same distinction the two project helpers collect
|
|
958
|
+
* on, so a file is judged by the rules of the project that actually runs it.
|
|
959
|
+
*/
|
|
960
|
+
function roleOf(filename) {
|
|
961
|
+
const parts = segments(filename);
|
|
962
|
+
const base = parts.at(-1) ?? "";
|
|
963
|
+
const inSpecs = isUnderSpecs(filename);
|
|
964
|
+
if (base.endsWith(".specification.ts") || base.endsWith(".specification.tsx")) return {
|
|
965
|
+
inSpecs,
|
|
966
|
+
role: "specification"
|
|
967
|
+
};
|
|
968
|
+
if (CONFIG.test(base)) return {
|
|
969
|
+
inSpecs,
|
|
970
|
+
role: "config"
|
|
971
|
+
};
|
|
972
|
+
if (base.endsWith(".test.tsx")) return {
|
|
973
|
+
inSpecs,
|
|
974
|
+
role: "component"
|
|
975
|
+
};
|
|
976
|
+
if (base.endsWith(".test.ts")) return {
|
|
977
|
+
inSpecs,
|
|
978
|
+
role: "module"
|
|
979
|
+
};
|
|
980
|
+
if (parts.slice(0, -1).some((segment) => GROUND.has(segment))) return {
|
|
981
|
+
inSpecs,
|
|
982
|
+
role: "ground"
|
|
983
|
+
};
|
|
984
|
+
return {
|
|
985
|
+
inSpecs,
|
|
986
|
+
role: "other"
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
//#endregion
|
|
866
990
|
//#region src/lint/rules/a1-specification-file.ts
|
|
867
991
|
const SPECIFICATION_SUFFIX$2 = ".specification.ts";
|
|
868
992
|
/**
|
|
@@ -873,10 +997,15 @@ const SPECIFICATION_SUFFIX$2 = ".specification.ts";
|
|
|
873
997
|
* Framework-internal unit tests of the constructors themselves (this repo's
|
|
874
998
|
* `src/**\/*.test.ts`) disable the rule via a config override — for consumers
|
|
875
999
|
* the rule is universal.
|
|
1000
|
+
*
|
|
1001
|
+
* The A family does not reach a `component`-role file. A rendered unit has no
|
|
1002
|
+
* runner to create: no server to start, no database to isolate, no binary to
|
|
1003
|
+
* find — which is why the component facet has no constructor and no
|
|
1004
|
+
* specification file for A1 to point at.
|
|
876
1005
|
*/
|
|
877
1006
|
const a1SpecificationFile = {
|
|
878
1007
|
create(context) {
|
|
879
|
-
if (context.filename.endsWith(SPECIFICATION_SUFFIX$2)) return {};
|
|
1008
|
+
if (context.filename.endsWith(SPECIFICATION_SUFFIX$2) || roleOf(context.physicalFilename).role === "component") return {};
|
|
880
1009
|
return { CallExpression(node) {
|
|
881
1010
|
const member = specificationMember(node);
|
|
882
1011
|
if (member !== void 0) context.report({
|
|
@@ -2843,6 +2972,122 @@ const d15wStatusOnlyProbe = {
|
|
|
2843
2972
|
}
|
|
2844
2973
|
};
|
|
2845
2974
|
//#endregion
|
|
2975
|
+
//#region src/lint/rules/e5-no-simulated-dom.ts
|
|
2976
|
+
/** The pragma vitest reads to swap a test file's environment. */
|
|
2977
|
+
const PRAGMA = /@vitest-environment\s+(?<environment>[\w-]+)/u;
|
|
2978
|
+
/** The two simulated DOMs. */
|
|
2979
|
+
const SIMULATED$1 = /* @__PURE__ */ new Set(["happy-dom", "jsdom"]);
|
|
2980
|
+
/** The roles that RUN a test file — the only ones a pragma steers. */
|
|
2981
|
+
const REACHED$1 = /* @__PURE__ */ new Set([
|
|
2982
|
+
"component",
|
|
2983
|
+
"module",
|
|
2984
|
+
"specification"
|
|
2985
|
+
]);
|
|
2986
|
+
/**
|
|
2987
|
+
* CONVENTIONS E5 — no simulated DOM, stated per file.
|
|
2988
|
+
*
|
|
2989
|
+
* `@vitest-environment happy-dom` buys a document that behaves almost like a
|
|
2990
|
+
* browser's: almost is the whole problem, because what ships is judged by a
|
|
2991
|
+
* real one. The component facet renders in the Chromium the website facet
|
|
2992
|
+
* already drives, so the pragma has nothing left to buy.
|
|
2993
|
+
*/
|
|
2994
|
+
const e5NoSimulatedDom = {
|
|
2995
|
+
create(context) {
|
|
2996
|
+
if (!REACHED$1.has(roleOf(context.physicalFilename).role)) return {};
|
|
2997
|
+
return { Program(node) {
|
|
2998
|
+
for (const comment of context.sourceCode.getAllComments()) {
|
|
2999
|
+
const environment = PRAGMA.exec(comment.value)?.groups?.environment;
|
|
3000
|
+
if (environment !== void 0 && SIMULATED$1.has(environment)) context.report({
|
|
3001
|
+
data: { environment },
|
|
3002
|
+
messageId: "pragma",
|
|
3003
|
+
node
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
} };
|
|
3007
|
+
},
|
|
3008
|
+
meta: {
|
|
3009
|
+
docs: RULE_DOCS["e5-no-simulated-dom"],
|
|
3010
|
+
messages: { pragma: "`@vitest-environment {{environment}}` simulates a browser this framework can open for real — a rendered thing is a `.test.tsx` beside its component, collected by the `component()` project (E5 — docs/13-linting.md#e5-no-simulated-dom)." },
|
|
3011
|
+
type: "problem"
|
|
3012
|
+
}
|
|
3013
|
+
};
|
|
3014
|
+
//#endregion
|
|
3015
|
+
//#region src/lint/rules/e5b-no-simulated-dom-config.ts
|
|
3016
|
+
/** The two simulated DOMs. */
|
|
3017
|
+
const SIMULATED = /* @__PURE__ */ new Set(["happy-dom", "jsdom"]);
|
|
3018
|
+
/**
|
|
3019
|
+
* CONVENTIONS E5b — the same ban, where a project states it for a whole tree.
|
|
3020
|
+
*
|
|
3021
|
+
* The pragma (E5) is one file's; `environment: 'happy-dom'` in a config is
|
|
3022
|
+
* every file the project collects, which is how a repository ends up with a
|
|
3023
|
+
* simulated DOM nobody ever chose per test. `'node'` and `'edge-runtime'` are
|
|
3024
|
+
* out of reach: they name a real runtime, not a drawing of one.
|
|
3025
|
+
*/
|
|
3026
|
+
const e5bNoSimulatedDomConfig = {
|
|
3027
|
+
create(context) {
|
|
3028
|
+
if (roleOf(context.physicalFilename).role !== "config") return {};
|
|
3029
|
+
return { Program(node) {
|
|
3030
|
+
walk(node, (candidate) => {
|
|
3031
|
+
if (candidate.type !== "Property" || propertyKeyName(candidate) !== "environment") return;
|
|
3032
|
+
const environment = stringValue(child(candidate, "value"));
|
|
3033
|
+
if (environment !== void 0 && SIMULATED.has(environment)) context.report({
|
|
3034
|
+
data: { environment },
|
|
3035
|
+
messageId: "configured",
|
|
3036
|
+
node: candidate
|
|
3037
|
+
});
|
|
3038
|
+
});
|
|
3039
|
+
} };
|
|
3040
|
+
},
|
|
3041
|
+
meta: {
|
|
3042
|
+
docs: RULE_DOCS["e5b-no-simulated-dom-config"],
|
|
3043
|
+
messages: { configured: "`environment: '{{environment}}'` gives every file of this project a drawing of a browser — a rendered thing is a `.test.tsx` beside its component, collected by `component()` (E5b — docs/13-linting.md#e5b-no-simulated-dom-config)." },
|
|
3044
|
+
type: "problem"
|
|
3045
|
+
}
|
|
3046
|
+
};
|
|
3047
|
+
//#endregion
|
|
3048
|
+
//#region src/lint/rules/e6-component-project-helper.ts
|
|
3049
|
+
/** Is this property the RUNNER's browser block, rather than a key that shares its name? */
|
|
3050
|
+
function isRunnerBrowserBlock(node) {
|
|
3051
|
+
for (let current = child(node, "parent"); current !== void 0; current = child(current, "parent")) if (current.type === "Property" && propertyKeyName(current) === "test") return true;
|
|
3052
|
+
return false;
|
|
3053
|
+
}
|
|
3054
|
+
/** Is this node inside a call to `component(...)`? */
|
|
3055
|
+
function insideComponentCall(node) {
|
|
3056
|
+
for (let current = child(node, "parent"); current !== void 0; current = child(current, "parent")) if (current.type === "CallExpression" && identifierName(child(current, "callee")) === "component") return true;
|
|
3057
|
+
return false;
|
|
3058
|
+
}
|
|
3059
|
+
/**
|
|
3060
|
+
* CONVENTIONS E6 — a browser project comes from `component()`.
|
|
3061
|
+
*
|
|
3062
|
+
* A hand-rolled `browser: { … }` block is a project that has to rediscover
|
|
3063
|
+
* everything the seam already knows: the provider pinned to the runner's exact
|
|
3064
|
+
* version, the service worker served from the framework's own install, the JSX
|
|
3065
|
+
* transform the current Vite actually uses, the dependencies a cold cache must
|
|
3066
|
+
* pre-bundle, and the artefact directories Browser Mode otherwise leaks at the
|
|
3067
|
+
* repository root. Every one of those is a run that fails on the second
|
|
3068
|
+
* machine, so the helper owns them and a config states only what is its own.
|
|
3069
|
+
*/
|
|
3070
|
+
const e6ComponentProjectHelper = {
|
|
3071
|
+
create(context) {
|
|
3072
|
+
if (roleOf(context.physicalFilename).role !== "config") return {};
|
|
3073
|
+
return { Program(node) {
|
|
3074
|
+
walk(node, (candidate) => {
|
|
3075
|
+
if (candidate.type !== "Property" || propertyKeyName(candidate) !== "browser") return;
|
|
3076
|
+
if (!isRunnerBrowserBlock(candidate)) return;
|
|
3077
|
+
if (!insideComponentCall(candidate)) context.report({
|
|
3078
|
+
messageId: "handRolled",
|
|
3079
|
+
node: candidate
|
|
3080
|
+
});
|
|
3081
|
+
});
|
|
3082
|
+
} };
|
|
3083
|
+
},
|
|
3084
|
+
meta: {
|
|
3085
|
+
docs: RULE_DOCS["e6-component-project-helper"],
|
|
3086
|
+
messages: { handRolled: "Use `component({ vite })` — the provider, the worker and the pipeline are its, and a hand-rolled `browser:` block is the run that passes here and fails on the next machine (E6 — docs/13-linting.md#e6-component-project-helper)." },
|
|
3087
|
+
type: "problem"
|
|
3088
|
+
}
|
|
3089
|
+
};
|
|
3090
|
+
//#endregion
|
|
2846
3091
|
//#region src/lint/package-exports.ts
|
|
2847
3092
|
/**
|
|
2848
3093
|
* The subpaths this package actually publishes, read from its OWN
|
|
@@ -3114,6 +3359,164 @@ const f5FixturesOnlyFromTests = {
|
|
|
3114
3359
|
}
|
|
3115
3360
|
};
|
|
3116
3361
|
//#endregion
|
|
3362
|
+
//#region src/lint/rules/f6-no-foreign-test-runtime.ts
|
|
3363
|
+
const GROUPS = [
|
|
3364
|
+
{
|
|
3365
|
+
fix: "`component.render()` and the element vocabulary render in a real browser — the queries are the same nouns, and they run against what ships",
|
|
3366
|
+
matches: (source) => source === "@testing-library" || source.startsWith("@testing-library/")
|
|
3367
|
+
},
|
|
3368
|
+
{
|
|
3369
|
+
fix: "a drawing of a browser proves what a browser does not — a rendered thing is a `.test.tsx` beside its component, collected by `component()`",
|
|
3370
|
+
matches: (source) => source === "happy-dom" || source === "jsdom"
|
|
3371
|
+
},
|
|
3372
|
+
{
|
|
3373
|
+
fix: "Browser Mode is the seam, not the surface — `component.render()` owns the locators, the visitor and the ARIA tree",
|
|
3374
|
+
matches: (source) => source === "vitest/browser" || source.startsWith("vitest-browser-") || source.startsWith("@vitest/browser")
|
|
3375
|
+
}
|
|
3376
|
+
];
|
|
3377
|
+
/**
|
|
3378
|
+
* The roles that RUN a test — never a fixture app's config or a provider module
|
|
3379
|
+
* that happens to sit under `specs/`. A fixture project's own `vitest.config.ts`
|
|
3380
|
+
* has to name the provider, and a `providers.tsx` has to import the adapter it
|
|
3381
|
+
* wraps: neither is a spec speaking a second dialect.
|
|
3382
|
+
*/
|
|
3383
|
+
const REACHED = /* @__PURE__ */ new Set([
|
|
3384
|
+
"component",
|
|
3385
|
+
"module",
|
|
3386
|
+
"specification"
|
|
3387
|
+
]);
|
|
3388
|
+
/**
|
|
3389
|
+
* CONVENTIONS F6 — a test file imports no second test runtime.
|
|
3390
|
+
*
|
|
3391
|
+
* Every seam the framework owns is one a spec must not reach around: a test
|
|
3392
|
+
* that imports the adapter speaks the adapter's dialect, and a repository ends
|
|
3393
|
+
* up with as many vocabularies as it has seams. The groups the rule carries are
|
|
3394
|
+
* the ones the component facet REPLACES.
|
|
3395
|
+
*/
|
|
3396
|
+
const f6NoForeignTestRuntime = {
|
|
3397
|
+
create(context) {
|
|
3398
|
+
if (!REACHED.has(roleOf(context.physicalFilename).role)) return {};
|
|
3399
|
+
return { ...importSourceVisitor(({ node, source }) => {
|
|
3400
|
+
const group = GROUPS.find((candidate) => candidate.matches(source));
|
|
3401
|
+
if (group !== void 0) context.report({
|
|
3402
|
+
data: {
|
|
3403
|
+
fix: group.fix,
|
|
3404
|
+
source
|
|
3405
|
+
},
|
|
3406
|
+
messageId: "foreignRuntime",
|
|
3407
|
+
node
|
|
3408
|
+
});
|
|
3409
|
+
}) };
|
|
3410
|
+
},
|
|
3411
|
+
meta: {
|
|
3412
|
+
docs: RULE_DOCS["f6-no-foreign-test-runtime"],
|
|
3413
|
+
messages: { foreignRuntime: "`{{source}}` is a second test runtime in a test file: {{fix}} (F6 — docs/13-linting.md#f6-no-foreign-test-runtime)." },
|
|
3414
|
+
type: "problem"
|
|
3415
|
+
}
|
|
3416
|
+
};
|
|
3417
|
+
//#endregion
|
|
3418
|
+
//#region src/lint/rules/g4-no-dom-in-module-test.ts
|
|
3419
|
+
/** The globals that only exist where a document does. */
|
|
3420
|
+
const DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
3421
|
+
"document",
|
|
3422
|
+
"HTMLElement",
|
|
3423
|
+
"navigator",
|
|
3424
|
+
"window"
|
|
3425
|
+
]);
|
|
3426
|
+
/** The node kinds that BIND a name, and the key each one binds it under. */
|
|
3427
|
+
const BINDINGS = {
|
|
3428
|
+
CatchClause: "param",
|
|
3429
|
+
ClassDeclaration: "id",
|
|
3430
|
+
FunctionDeclaration: "id",
|
|
3431
|
+
ImportDefaultSpecifier: "local",
|
|
3432
|
+
ImportNamespaceSpecifier: "local",
|
|
3433
|
+
ImportSpecifier: "local",
|
|
3434
|
+
VariableDeclarator: "id"
|
|
3435
|
+
};
|
|
3436
|
+
/**
|
|
3437
|
+
* Every name this file declares for itself.
|
|
3438
|
+
*
|
|
3439
|
+
* A file-wide set rather than a scope chain: the rule only needs to know that
|
|
3440
|
+
* `document` is the test's own binding somewhere, and a name shadowed in one
|
|
3441
|
+
* scope is not a global in another. It can only under-report, which is the
|
|
3442
|
+
* right direction for a guard.
|
|
3443
|
+
*/
|
|
3444
|
+
function declaredNames(root) {
|
|
3445
|
+
const names = /* @__PURE__ */ new Set();
|
|
3446
|
+
const add = (node) => {
|
|
3447
|
+
const name = identifierName(node);
|
|
3448
|
+
if (name !== void 0) names.add(name);
|
|
3449
|
+
};
|
|
3450
|
+
walk(root, (node) => {
|
|
3451
|
+
const key = BINDINGS[node.type];
|
|
3452
|
+
if (key !== void 0) add(child(node, key));
|
|
3453
|
+
const { params } = node;
|
|
3454
|
+
if (Array.isArray(params)) {
|
|
3455
|
+
for (const parameter of params) if (isNode(parameter)) add(parameter);
|
|
3456
|
+
}
|
|
3457
|
+
});
|
|
3458
|
+
return names;
|
|
3459
|
+
}
|
|
3460
|
+
/** The node kinds a name sits in when it is a TYPE, not a value the test reaches. */
|
|
3461
|
+
const TYPE_POSITIONS = /* @__PURE__ */ new Set([
|
|
3462
|
+
"TSInterfaceHeritage",
|
|
3463
|
+
"TSQualifiedName",
|
|
3464
|
+
"TSTypeQuery",
|
|
3465
|
+
"TSTypeReference"
|
|
3466
|
+
]);
|
|
3467
|
+
/** Is this identifier read as a value, rather than named as a property, a key or a type? */
|
|
3468
|
+
function isValueReference(node) {
|
|
3469
|
+
const parent = child(node, "parent");
|
|
3470
|
+
if (parent === void 0) return true;
|
|
3471
|
+
if (TYPE_POSITIONS.has(parent.type)) return false;
|
|
3472
|
+
if (parent.type === "UnaryExpression" && parent.operator === "typeof") return false;
|
|
3473
|
+
if (parent.type === "MemberExpression") return child(parent, "property") !== node || parent.computed === true;
|
|
3474
|
+
if (parent.type === "Property") return child(parent, "value") === node || parent.computed === true;
|
|
3475
|
+
return true;
|
|
3476
|
+
}
|
|
3477
|
+
/**
|
|
3478
|
+
* CONVENTIONS G4 — a module test touches no DOM.
|
|
3479
|
+
*
|
|
3480
|
+
* A module test runs under node, where `document` does not exist: a test that
|
|
3481
|
+
* reaches for one is not testing a module, it is rendering something, and the
|
|
3482
|
+
* place for that is a `.test.tsx` beside the component.
|
|
3483
|
+
*
|
|
3484
|
+
* Reach is the `module` role OUTSIDE `specs/`: a `.test.tsx` is the rendered
|
|
3485
|
+
* kind and lives in a page, where those globals are what it is there to use;
|
|
3486
|
+
* and under `specs/` an api or cli spec is a `.test.ts` too until the `spec`
|
|
3487
|
+
* role exists, so the guard stops at the tree it can judge.
|
|
3488
|
+
*
|
|
3489
|
+
* A name in a TYPE position (`x as HTMLElement`) and a `typeof window` guard
|
|
3490
|
+
* name no document: neither reaches one, and a module that must run in both
|
|
3491
|
+
* runtimes is tested by exactly that guard.
|
|
3492
|
+
*/
|
|
3493
|
+
const g4NoDomInModuleTest = {
|
|
3494
|
+
create(context) {
|
|
3495
|
+
const identity = roleOf(context.physicalFilename);
|
|
3496
|
+
if (identity.role !== "module" || identity.inSpecs) return {};
|
|
3497
|
+
let declared = /* @__PURE__ */ new Set();
|
|
3498
|
+
return {
|
|
3499
|
+
Identifier(node) {
|
|
3500
|
+
const name = identifierName(node);
|
|
3501
|
+
if (name === void 0 || !DOM_GLOBALS.has(name) || declared.has(name) || !isValueReference(node)) return;
|
|
3502
|
+
context.report({
|
|
3503
|
+
data: { name },
|
|
3504
|
+
messageId: "domGlobal",
|
|
3505
|
+
node
|
|
3506
|
+
});
|
|
3507
|
+
},
|
|
3508
|
+
Program(node) {
|
|
3509
|
+
declared = declaredNames(node);
|
|
3510
|
+
}
|
|
3511
|
+
};
|
|
3512
|
+
},
|
|
3513
|
+
meta: {
|
|
3514
|
+
docs: RULE_DOCS["g4-no-dom-in-module-test"],
|
|
3515
|
+
messages: { domGlobal: "`{{name}}` does not exist where a module test runs — a rendered thing is a `.test.tsx` beside its component, collected by the `component()` project (G4 — docs/13-linting.md#g4-no-dom-in-module-test)." },
|
|
3516
|
+
type: "problem"
|
|
3517
|
+
}
|
|
3518
|
+
};
|
|
3519
|
+
//#endregion
|
|
3117
3520
|
//#region src/lint/rules/i1-layer-boundaries.ts
|
|
3118
3521
|
const TEST_OR_FIXTURES = /\.(?:test|fixtures)\.[cm]?[jt]sx?$/u;
|
|
3119
3522
|
function matchesPackage(source, packages) {
|
|
@@ -3246,21 +3649,25 @@ const i1LayerBoundaries = {
|
|
|
3246
3649
|
//#region src/lint/rules/i2-sibling-test-naming.ts
|
|
3247
3650
|
const TEST_FILE$1 = /\.test\.[cm]?[jt]sx?$/u;
|
|
3248
3651
|
/**
|
|
3249
|
-
* CONVENTIONS I2 —
|
|
3250
|
-
* `<file>.test.ts` next to it (Go's `foo_test.go` parity).
|
|
3251
|
-
*
|
|
3652
|
+
* CONVENTIONS I2 — a unit's test is its NEIGHBOUR: the test of `<file>.ts` is
|
|
3653
|
+
* `<file>.test.ts` next to it (Go's `foo_test.go` parity). A rendered unit
|
|
3654
|
+
* answers to the same law wherever it lives: a `.test.tsx` sits beside the
|
|
3655
|
+
* `.tsx` it renders, or the `.ts` of the hook or DOM function it hosts. Flags,
|
|
3656
|
+
* on visited files:
|
|
3252
3657
|
*
|
|
3253
3658
|
* - a `src/**` test whose neighbour module `<file>.ts` does not exist;
|
|
3659
|
+
* - a `component`-role test (`*.test.tsx`) with no neighbour of any tree;
|
|
3254
3660
|
* - any file living in a `__tests__/` directory under `src/`;
|
|
3255
3661
|
* - any file under a root-level `tests/` directory (the only test roots are
|
|
3256
|
-
* sibling
|
|
3662
|
+
* sibling tests under `src/` and product specifications in `specs/`).
|
|
3257
3663
|
*/
|
|
3258
3664
|
const i2SiblingTestNaming = {
|
|
3259
3665
|
create(context) {
|
|
3260
3666
|
const file = context.physicalFilename;
|
|
3261
3667
|
const parts = segments(file);
|
|
3262
3668
|
return { Program(node) {
|
|
3263
|
-
|
|
3669
|
+
const rendered = roleOf(file).role === "component";
|
|
3670
|
+
if (parts.includes("src") || rendered) {
|
|
3264
3671
|
if (parts.includes("__tests__")) context.report({
|
|
3265
3672
|
messageId: "testsDir",
|
|
3266
3673
|
node
|
|
@@ -3272,8 +3679,8 @@ const i2SiblingTestNaming = {
|
|
|
3272
3679
|
".js"
|
|
3273
3680
|
].map((extension) => file.replace(TEST_FILE$1, extension));
|
|
3274
3681
|
if (!neighbours.some(isFile)) context.report({
|
|
3275
|
-
data: { expected: neighbours[0]?.split(/[/\\]/u).at(-1) ?? "" },
|
|
3276
|
-
messageId: "orphanTest",
|
|
3682
|
+
data: { expected: neighbours[rendered ? 1 : 0]?.split(/[/\\]/u).at(-1) ?? "" },
|
|
3683
|
+
messageId: rendered ? "orphanComponent" : "orphanTest",
|
|
3277
3684
|
node
|
|
3278
3685
|
});
|
|
3279
3686
|
}
|
|
@@ -3290,6 +3697,7 @@ const i2SiblingTestNaming = {
|
|
|
3290
3697
|
meta: {
|
|
3291
3698
|
docs: RULE_DOCS["i2-sibling-test-naming"],
|
|
3292
3699
|
messages: {
|
|
3700
|
+
orphanComponent: "A component test must sit NEXT to what it renders — no neighbour \"{{expected}}\" found (I2 — see docs/13-linting.md). A hook or a DOM function is the `.ts` of the same basename, with its Host in the test file.",
|
|
3293
3701
|
orphanTest: "A src/ module test must sit NEXT to the module it tests — no neighbour \"{{expected}}\" found (I2 — see docs/13-linting.md). A test needing more than its module is a specification: move it to specs/.",
|
|
3294
3702
|
rootTests: "A root-level tests/ directory is banned — module tests are siblings under src/, product specifications live in specs/ (I2 — see docs/13-linting.md).",
|
|
3295
3703
|
testsDir: "__tests__/ directories are banned under src/ — the test of <file>.ts is its neighbour <file>.test.ts (I2 — see docs/13-linting.md)."
|
|
@@ -3532,11 +3940,16 @@ const plugin = {
|
|
|
3532
3940
|
"d12w-response-body-probe": d12wResponseBodyProbe,
|
|
3533
3941
|
"d13w-unfrozen-negative-fixture": d13wUnfrozenNegativeFixture,
|
|
3534
3942
|
"d15w-status-only-probe": d15wStatusOnlyProbe,
|
|
3943
|
+
"e5-no-simulated-dom": e5NoSimulatedDom,
|
|
3944
|
+
"e5b-no-simulated-dom-config": e5bNoSimulatedDomConfig,
|
|
3945
|
+
"e6-component-project-helper": e6ComponentProjectHelper,
|
|
3535
3946
|
"f1-no-subpath-import": f1NoSubpathImport,
|
|
3536
3947
|
"f2-no-test-imports-in-prod": f2NoTestImportsInProd,
|
|
3537
3948
|
"f3-specs-public-entry": f3SpecsPublicEntry,
|
|
3538
3949
|
"f4-no-test-to-test-import": f4NoTestToTestImport,
|
|
3539
3950
|
"f5-fixtures-only-from-tests": f5FixturesOnlyFromTests,
|
|
3951
|
+
"f6-no-foreign-test-runtime": f6NoForeignTestRuntime,
|
|
3952
|
+
"g4-no-dom-in-module-test": g4NoDomInModuleTest,
|
|
3540
3953
|
"i1-layer-boundaries": i1LayerBoundaries,
|
|
3541
3954
|
"i2-sibling-test-naming": i2SiblingTestNaming,
|
|
3542
3955
|
"i4-no-vi-mock-in-src": i4NoViMockInSrc,
|
package/dist/oxlint.d.cts
CHANGED
|
@@ -7119,17 +7119,29 @@ type RuleDoc = {
|
|
|
7119
7119
|
channel: 'checker' | 'process' | 'runtime' | 'statique';
|
|
7120
7120
|
/** The French normative sentence (the constitution's per-rule text, moved here). */
|
|
7121
7121
|
convention: string;
|
|
7122
|
+
/**
|
|
7123
|
+
* One imperative line: what to DO about it. A ban with no destination is an
|
|
7124
|
+
* argument rather than a rule, so the catalogue and the message carry the
|
|
7125
|
+
* same fix. A row that states none renders `—`.
|
|
7126
|
+
*/
|
|
7127
|
+
fix?: string;
|
|
7122
7128
|
/**
|
|
7123
7129
|
* The specification facet the rule guards — segments the catalogue like
|
|
7124
7130
|
* the constructors segment the API. `'shared'` for cross-facet rules.
|
|
7125
7131
|
*/
|
|
7126
|
-
facet?: 'api' | 'cli' | 'jobs' | 'mobile' | 'shared' | 'website';
|
|
7132
|
+
facet?: 'api' | 'cli' | 'component' | 'jobs' | 'mobile' | 'shared' | 'website';
|
|
7127
7133
|
/** Convention family letter, e.g. `'A'`. */
|
|
7128
7134
|
family: string;
|
|
7129
7135
|
/** Convention code, e.g. `'A1'`. */
|
|
7130
7136
|
id: string;
|
|
7131
7137
|
/** One line: why the rule exists. */
|
|
7132
7138
|
rationale: string;
|
|
7139
|
+
/**
|
|
7140
|
+
* Which files the rule looks at — the vocabulary of `roleOf` plus the two
|
|
7141
|
+
* shapes that are not a role (`tests`, everything the conventions bind, and
|
|
7142
|
+
* `all`). A row that states none renders `—`.
|
|
7143
|
+
*/
|
|
7144
|
+
reach?: 'all' | 'component' | 'config' | 'document' | 'ground' | 'module' | 'specification' | 'specs' | 'tests';
|
|
7133
7145
|
};
|
|
7134
7146
|
/** Rule metadata (the subset we set). */
|
|
7135
7147
|
type RuleMeta = {
|
package/dist/oxlint.d.ts
CHANGED
|
@@ -7119,17 +7119,29 @@ type RuleDoc = {
|
|
|
7119
7119
|
channel: 'checker' | 'process' | 'runtime' | 'statique';
|
|
7120
7120
|
/** The French normative sentence (the constitution's per-rule text, moved here). */
|
|
7121
7121
|
convention: string;
|
|
7122
|
+
/**
|
|
7123
|
+
* One imperative line: what to DO about it. A ban with no destination is an
|
|
7124
|
+
* argument rather than a rule, so the catalogue and the message carry the
|
|
7125
|
+
* same fix. A row that states none renders `—`.
|
|
7126
|
+
*/
|
|
7127
|
+
fix?: string;
|
|
7122
7128
|
/**
|
|
7123
7129
|
* The specification facet the rule guards — segments the catalogue like
|
|
7124
7130
|
* the constructors segment the API. `'shared'` for cross-facet rules.
|
|
7125
7131
|
*/
|
|
7126
|
-
facet?: 'api' | 'cli' | 'jobs' | 'mobile' | 'shared' | 'website';
|
|
7132
|
+
facet?: 'api' | 'cli' | 'component' | 'jobs' | 'mobile' | 'shared' | 'website';
|
|
7127
7133
|
/** Convention family letter, e.g. `'A'`. */
|
|
7128
7134
|
family: string;
|
|
7129
7135
|
/** Convention code, e.g. `'A1'`. */
|
|
7130
7136
|
id: string;
|
|
7131
7137
|
/** One line: why the rule exists. */
|
|
7132
7138
|
rationale: string;
|
|
7139
|
+
/**
|
|
7140
|
+
* Which files the rule looks at — the vocabulary of `roleOf` plus the two
|
|
7141
|
+
* shapes that are not a role (`tests`, everything the conventions bind, and
|
|
7142
|
+
* `all`). A row that states none renders `—`.
|
|
7143
|
+
*/
|
|
7144
|
+
reach?: 'all' | 'component' | 'config' | 'document' | 'ground' | 'module' | 'specification' | 'specs' | 'tests';
|
|
7133
7145
|
};
|
|
7134
7146
|
/** Rule metadata (the subset we set). */
|
|
7135
7147
|
type RuleMeta = {
|