UNPKG

@flizpay-de/eslint

Version:

Shared ESLint flat-config for FlizPay projects

104 lines (90 loc) 3.41 kB
import { FlatCompat } from "@eslint/eslintrc"; import { dirname } from "node:path"; import { fileURLToPath } from "node:url"; import tsPlugin from "@typescript-eslint/eslint-plugin"; import tsParser from "@typescript-eslint/parser"; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); const compat = new FlatCompat({ baseDirectory: __dirname }); // Base config and rules export default [ { ignores: [ "/*", // ignore every top-level entry "!/src/**", // …except anything that lives in /src ], }, ...compat.config({ plugins: ["sonarjs", "import", "promise", "security"], rules: { /* ------------- Core JS ------------- */ // Disallow use of console.* except console.error "no-console": ["error", { allow: ["error"] }], /* ------------- API design rules ------------- */ // Limit a function to at most 2 positional parameters "max-params": ["error", 2], /* ------------- Maintainability thresholds ------------- */ // Discourage legacy enums in favor of union types "no-restricted-syntax": [ "error", { selector: "TSEnumDeclaration", message: "Prefer union types over enums", }, ], /* ------------- SonarJS / Security / Promise ------------- */ // Reduce copy‑paste by warning on duplicate string literals "sonarjs/no-duplicate-string": "warn", // Ensure promises either return a value or explicitly void "promise/always-return": "error", /* ------------- Import hygiene & sorting ------------- */ // Prevent missing, extraneous or duplicate dependencies "import/no-extraneous-dependencies": ["error", { devDependencies: true }], }, }), { /* ------------- Core TS rules ------------- */ files: ["**/*.ts", "**/*.tsx"], languageOptions: { parser: tsParser, parserOptions: { sourceType: "module", ecmaVersion: "latest", // project: ['./tsconfig.json'], // ← uncomment if you need it }, }, plugins: { "@typescript-eslint": tsPlugin, // ← register the object exactly once }, rules: { // Flag unused variables / args unless they start with "_" "@typescript-eslint/no-unused-vars": [ "error", { vars: "all", args: "all", ignoreRestSiblings: true, varsIgnorePattern: "^_", argsIgnorePattern: "^_", caughtErrors: "all", caughtErrorsIgnorePattern: "^_", destructuredArrayIgnorePattern: "^_", }, ], // Enforce named interface for destructured parameter types "@typescript-eslint/consistent-type-definitions": ["error", "interface"], // Defer unused‑var detection to the TypeScript‑aware version "no-unused-vars": "off", // 🚫 forbid const fn = ({x}: {x: string}) => {} // ✅ allow const fn = ({x}: MyProps) => {} "no-restricted-syntax": [ "error", { selector: "ObjectPattern > TSTypeAnnotation > TSTypeLiteral", message: "Inline object type literals are not allowed in parameters – use a named interface or type alias instead.", }, ], }, }, ];