|
| 1 | +import tsPlugin from "@typescript-eslint/eslint-plugin"; |
| 2 | +import tsParser from "@typescript-eslint/parser"; |
| 3 | +import prettierPlugin from "eslint-plugin-prettier"; |
| 4 | + |
| 5 | +/** |
| 6 | + * ESLint flat config for the project. |
| 7 | + * - TypeScript parser + plugin for typed linting |
| 8 | + * - Prettier plugin to keep formatting enforced by ESLint |
| 9 | + * - Basic overrides for test files and generated or output folders |
| 10 | + */ |
| 11 | +export default [ |
| 12 | + // ignore common build/artifact folders |
| 13 | + { |
| 14 | + ignores: ["dist/**", "build/**", "node_modules/**"], |
| 15 | + }, |
| 16 | + |
| 17 | + // General JS/TS settings |
| 18 | + { |
| 19 | + files: ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.cjs", "**/*.mjs"], |
| 20 | + languageOptions: { |
| 21 | + parser: tsParser, |
| 22 | + parserOptions: { |
| 23 | + project: ["./tsconfig.json"], |
| 24 | + tsconfigRootDir: new URL(".", import.meta.url).pathname, |
| 25 | + ecmaVersion: "latest", |
| 26 | + sourceType: "module", |
| 27 | + }, |
| 28 | + globals: { |
| 29 | + // Bun testing / runtime globals (Bun provides `Bun` as global runtime) |
| 30 | + Bun: "readonly", |
| 31 | + }, |
| 32 | + }, |
| 33 | + // Plugins are loaded by name in the flat config as objects |
| 34 | + plugins: { |
| 35 | + "@typescript-eslint": tsPlugin, |
| 36 | + prettier: prettierPlugin, |
| 37 | + }, |
| 38 | + rules: { |
| 39 | + // Prettier enforces formatting — run prettier as part of linting |
| 40 | + "prettier/prettier": "error", |
| 41 | + |
| 42 | + // Replace core ESLint `no-unused-vars` with TypeScript-aware rule |
| 43 | + "no-unused-vars": "off", |
| 44 | + "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], |
| 45 | + |
| 46 | + // Type-only import enforcement for consistency |
| 47 | + "@typescript-eslint/consistent-type-imports": "error", |
| 48 | + |
| 49 | + // Allow some pragmatic leniency for lib code (disable if you want stricter checks) |
| 50 | + "@typescript-eslint/explicit-module-boundary-types": "off", |
| 51 | + "@typescript-eslint/no-explicit-any": "off", |
| 52 | + }, |
| 53 | + }, |
| 54 | + |
| 55 | + // Test files — bun.test uses describe/it/expect (similar to Jest), mark them as known |
| 56 | + { |
| 57 | + files: ["**/*.test.ts", "**/*.spec.ts"], |
| 58 | + languageOptions: { |
| 59 | + globals: { |
| 60 | + describe: "readonly", |
| 61 | + it: "readonly", |
| 62 | + test: "readonly", |
| 63 | + expect: "readonly", |
| 64 | + beforeAll: "readonly", |
| 65 | + afterAll: "readonly", |
| 66 | + }, |
| 67 | + }, |
| 68 | + rules: { |
| 69 | + // Tests often include non-null assertions and other patterns that are okay |
| 70 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 71 | + "@typescript-eslint/no-explicit-any": "off", |
| 72 | + }, |
| 73 | + }, |
| 74 | +]; |
0 commit comments