File size: 2,271 Bytes
170b9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0de93d
170b9b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// @ts-check
import tseslint from "typescript-eslint";

/**
 * Hexagonal dependency boundary (CLAUDE.md #1): packages/domain + packages/ports
 * are PURE — no framework/SDK, no adapters, no db. They may import only
 * packages/ports and packages/contracts.
 *
 * Uses glob `patterns` (not `paths`) so subpath imports like
 * "drizzle-orm/node-postgres" or "@nestjs/common" are also caught.
 */
const FORBIDDEN_PATTERNS = [
  { group: ["@nestjs/*"], message: "domain/ports must not import NestJS." },
  { group: ["next", "next/*"], message: "domain/ports must not import Next.js." },
  { group: ["react", "react/*", "react-dom", "react-dom/*"], message: "domain/ports must not import React." },
  { group: ["ai", "ai/*", "openai", "openai/*", "@ai-sdk/*"], message: "domain/ports must not import AI SDKs (use LlmPort)." },
  { group: ["drizzle-orm", "drizzle-orm/*", "pg", "pg/*"], message: "domain/ports must not import the DB layer (use a port)." },
  { group: ["resend", "grammy", "grammy/*"], message: "domain/ports must not import channel/email SDKs (use ports)." },
  { group: ["playwright", "playwright/*"], message: "domain/ports must not import playwright." },
  { group: ["@supabase/*"], message: "domain/ports must not import supabase." },
  { group: ["inngest", "inngest/*"], message: "domain/ports must not import inngest (use WorkflowPort)." },
  { group: ["@aws-sdk/*"], message: "domain/ports must not import the AWS SDK (use a port)." },
  {
    group: ["@courtmitra/adapters", "@courtmitra/adapters/*", "@courtmitra/db", "@courtmitra/db/*"],
    message: "domain/ports must not import adapters or the db package.",
  },
];

export default tseslint.config(
  {
    ignores: ["**/dist/**", "**/.next/**", "**/node_modules/**", "**/.turbo/**", "**/*.config.*", "**/next-env.d.ts", "**/evaluate/**"],
  },
  ...tseslint.configs.recommended,
  {
    rules: {
      "@typescript-eslint/no-explicit-any": "warn",
      "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_", varsIgnorePattern: "^_" }],
    },
  },
  {
    files: ["packages/domain/**/*.ts", "packages/ports/**/*.ts"],
    rules: {
      "@typescript-eslint/no-explicit-any": "error",
      "no-restricted-imports": ["error", { patterns: FORBIDDEN_PATTERNS }],
    },
  },
);