chore(template): clean-slate template snapshot from bb4a0c7
Curated, product-agnostic snapshot of the post-story-04 tree: demo content deleted, auth-only reference feature, web-next shell, all gates green. Product-specific docs, ADRs 027-029, PRDs/epics/archive, editor library traces, and product naming are curated out; generic template repairs (coverage provider devDeps, root test:coverage script, live lint fixes, root-only release-please) are kept. See TEMPLATE.md for provenance, curation list, and usage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
This commit is contained in:
55
packages/core-eslint/rules/entity-must-have-test.js
Normal file
55
packages/core-eslint/rules/entity-must-have-test.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
/**
|
||||
* Entity models (`entities/models/<x>.ts`) are pure domain logic — schemas,
|
||||
* invariants, derivations. They are the cheapest layer to test and the most
|
||||
* expensive to get wrong, so every model file must carry a sibling test.
|
||||
*
|
||||
* Scope is `entities/models/` only. Error classes (`entities/errors/`) are
|
||||
* conventionally covered by a consolidated `errors.test.ts`, and barrels
|
||||
* (`index.ts`) hold no logic — both are excluded.
|
||||
*/
|
||||
function isEntityModelFile(filename) {
|
||||
const normalized = filename.replace(/\\/g, "/");
|
||||
if (!normalized.includes("/entities/models/")) return false;
|
||||
if (!normalized.endsWith(".ts")) return false;
|
||||
if (normalized.endsWith(".test.ts")) return false;
|
||||
if (normalized.endsWith(".d.ts")) return false;
|
||||
if (normalized.endsWith("/index.ts")) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @type {import("eslint").Rule.RuleModule} */
|
||||
export default {
|
||||
meta: {
|
||||
type: "problem",
|
||||
docs: {
|
||||
description:
|
||||
"Every entity model file (entities/models/<x>.ts) must have a sibling <x>.test.ts.",
|
||||
},
|
||||
schema: [],
|
||||
messages: {
|
||||
missingTest:
|
||||
"Entity model {{filename}} has no sibling test at {{expected}}. Entity models are pure domain logic — cover them with a unit test.",
|
||||
},
|
||||
},
|
||||
create(context) {
|
||||
return {
|
||||
Program(node) {
|
||||
const filename = context.filename;
|
||||
if (!isEntityModelFile(filename)) return;
|
||||
const expected = filename.replace(/\.ts$/, ".test.ts");
|
||||
if (fs.existsSync(expected)) return;
|
||||
context.report({
|
||||
node,
|
||||
messageId: "missingTest",
|
||||
data: {
|
||||
filename: path.basename(filename),
|
||||
expected: path.basename(expected),
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user