Files
kandev/apps/web/eslint.config.mjs
T
2026-08-13 22:50:13 +01:00

103 lines
3.9 KiB
JavaScript

import { defineConfig, globalIgnores } from "eslint/config";
import js from "@eslint/js";
import reactHooks from "eslint-plugin-react-hooks";
import sonarjs from "eslint-plugin-sonarjs";
import unusedImports from "eslint-plugin-unused-imports";
import i18next from "eslint-plugin-i18next";
import tseslint from "typescript-eslint";
import { i18nGuardFiles, noLiteralStringOptions } from "./eslint.i18n.options.mjs";
import {
e2eSleepGuardFiles,
e2eSleepPlugin,
SLEEP_EXEMPT_FILES,
} from "./eslint-rules/no-unsanctioned-sleep.mjs";
const eslintConfig = defineConfig([
{
linterOptions: {
reportUnusedDisableDirectives: "off",
},
},
js.configs.recommended,
...tseslint.configs.recommended,
globalIgnores([
".next/**",
"out/**",
"build/**",
"dist/**",
// Test artifacts (Playwright):
"**/test-results/**",
"**/playwright-report/**",
]),
{
plugins: {
"react-hooks": reactHooks,
sonarjs,
"unused-imports": unusedImports,
},
rules: {
"no-control-regex": "off",
"no-empty": "off",
"no-undef": "off",
"no-unsafe-finally": "off",
"max-lines": ["warn", { max: 600, skipBlankLines: true, skipComments: true }],
"max-lines-per-function": ["warn", { max: 100, skipBlankLines: true, skipComments: true }],
complexity: ["warn", 15],
"max-depth": ["warn", 4],
"max-params": ["warn", 5],
"no-nested-ternary": "warn",
"sonarjs/cognitive-complexity": ["warn", 20],
"sonarjs/no-duplicate-string": ["warn", { threshold: 4 }],
"sonarjs/no-identical-functions": "warn",
"unused-imports/no-unused-imports": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{ varsIgnorePattern: "^_", argsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_" },
],
},
},
// Hardcoded user-facing strings. An ERROR, but only on the allowlist in
// eslint.i18n.options.mjs — the paths that render user-facing copy, which is
// where a regression is real. A repo-wide error would break every unrelated PR
// that lands a literal; a warning would let listed paths drift back. A PR
// appends to `i18nGuardFiles` when it adds such a path or externalizes one
// still off the list — `lib/sidebar` is one the screen sweep did not cover.
{
files: i18nGuardFiles,
// Test files build fixtures out of literal strings on purpose; guarding them
// would force every `label="Tasks"` in a test through the catalog.
ignores: ["**/*.test.ts", "**/*.test.tsx", "e2e/**"],
plugins: { i18next },
rules: { "i18next/no-literal-string": ["error", noLiteralStringOptions] },
},
// E2E tests (Playwright): disable React hooks rules since Playwright's `use()` and
// `test.extend()` patterns are falsely flagged, and relax test-specific limits.
{
files: ["e2e/**/*.ts"],
rules: {
"react-hooks/rules-of-hooks": "off",
"react-hooks/exhaustive-deps": "off",
"max-lines-per-function": "off",
"max-lines": "off",
"sonarjs/no-duplicate-string": "off",
},
},
// Unconditional wall-clock sleeps in E2E specs. An ERROR, but only on
// `e2eSleepGuardFiles` — the directories the causal-waits conversion has
// already driven to zero. `pnpm lint` is `eslint --max-warnings 0`, so a
// repo-wide registration at ANY severity (warning included) would fail the
// build on the ~126 sleeps that predate the rule. Everything not listed is
// covered by `scripts/check-new-e2e-sleeps.mjs`, which judges only the lines a
// change added, so new sleeps are caught everywhere without a treadmill.
// Append a directory here when it reaches zero; see the list's own comment.
{
files: e2eSleepGuardFiles,
// `causal-waits.ts` implements both banned forms — see SLEEP_EXEMPT_FILES.
ignores: SLEEP_EXEMPT_FILES,
plugins: { "e2e-sleeps": e2eSleepPlugin },
rules: { "e2e-sleeps/no-unsanctioned-sleep": "error" },
},
]);
export default eslintConfig;