feat(core-eslint): add entity-must-have-test and no-relative-parent-import rules
Two CLAUDE.md conventions had no mechanical gate, so both drifted: entity models shipped without sibling tests, and feature test files imported src modules via `../` instead of the `@/` alias. - `entity-must-have-test` — every entities/models/<x>.ts needs a sibling <x>.test.ts (errors and barrels excluded). - `no-relative-parent-import-in-tests` — feature test files must import src via `@/`, not `../`. Scoped to feature packages; core packages are governed by their own generator templates. Both register at warn level, bringing the conformance rule count to 15.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import { describe, it } from "vitest";
|
||||
import { RuleTester } from "eslint";
|
||||
import rule from "./no-relative-parent-import-in-tests.js";
|
||||
|
||||
const tester = new RuleTester({
|
||||
languageOptions: { ecmaVersion: "latest", sourceType: "module" },
|
||||
});
|
||||
|
||||
const featureTest = "/repo/packages/auth/src/di/container.test.ts";
|
||||
const featureSrc = "/repo/packages/auth/src/di/container.ts";
|
||||
const coreTest = "/repo/packages/core-audit/src/di/bind-audit.test.ts";
|
||||
|
||||
describe("no-relative-parent-import-in-tests", () => {
|
||||
it("passes when a feature test uses the @/ alias", () => {
|
||||
tester.run("no-relative-parent-import-in-tests", rule, {
|
||||
valid: [
|
||||
{
|
||||
filename: featureTest,
|
||||
code: `import { x } from "@/infrastructure/x";`,
|
||||
},
|
||||
],
|
||||
invalid: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("passes for same-directory ./ imports", () => {
|
||||
tester.run("no-relative-parent-import-in-tests", rule, {
|
||||
valid: [
|
||||
{ filename: featureTest, code: `import { x } from "./container";` },
|
||||
],
|
||||
invalid: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("fires when a feature test imports via ../", () => {
|
||||
tester.run("no-relative-parent-import-in-tests", rule, {
|
||||
valid: [],
|
||||
invalid: [
|
||||
{
|
||||
filename: featureTest,
|
||||
code: `import { x } from "../infrastructure/x";`,
|
||||
errors: [
|
||||
{
|
||||
messageId: "relativeParentImport",
|
||||
data: { source: "../infrastructure/x" },
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores ../ imports in non-test source files", () => {
|
||||
tester.run("no-relative-parent-import-in-tests", rule, {
|
||||
valid: [
|
||||
{
|
||||
filename: featureSrc,
|
||||
code: `import { x } from "../infrastructure/x";`,
|
||||
},
|
||||
],
|
||||
invalid: [],
|
||||
});
|
||||
});
|
||||
|
||||
it("ignores core-package test files (governed by their own templates)", () => {
|
||||
tester.run("no-relative-parent-import-in-tests", rule, {
|
||||
valid: [
|
||||
{ filename: coreTest, code: `import { x } from "../noop-audit-log";` },
|
||||
],
|
||||
invalid: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user