|
| 1 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 2 | +import js from "@eslint/js"; |
| 3 | +import typescriptEslint from "@typescript-eslint/eslint-plugin"; |
| 4 | +import tsParser from "@typescript-eslint/parser"; |
| 5 | +import { defineConfig } from "eslint/config"; |
| 6 | +import globals from "globals"; |
| 7 | +import path from "node:path"; |
| 8 | +import { fileURLToPath } from "node:url"; |
| 9 | + |
| 10 | +const __filename = fileURLToPath(import.meta.url); |
| 11 | +const __dirname = path.dirname(__filename); |
| 12 | +const compat = new FlatCompat({ |
| 13 | + baseDirectory: __dirname, |
| 14 | + recommendedConfig: js.configs.recommended, |
| 15 | + allConfig: js.configs.all |
| 16 | +}); |
| 17 | + |
| 18 | +export default defineConfig([ |
| 19 | + { |
| 20 | + ignores: ["**/node_modules/*", "**/dist/*"], |
| 21 | + |
| 22 | + files: ["**/*.ts", "**/*.js", "**.*.js"], |
| 23 | + |
| 24 | + extends: compat.extends( |
| 25 | + "eslint:recommended", |
| 26 | + "plugin:@typescript-eslint/eslint-recommended", |
| 27 | + "plugin:@typescript-eslint/recommended" |
| 28 | + ), |
| 29 | + |
| 30 | + plugins: { |
| 31 | + "@typescript-eslint": typescriptEslint |
| 32 | + }, |
| 33 | + |
| 34 | + languageOptions: { |
| 35 | + globals: { |
| 36 | + ...globals.browser |
| 37 | + }, |
| 38 | + |
| 39 | + parser: tsParser, |
| 40 | + ecmaVersion: "latest", |
| 41 | + sourceType: "module" |
| 42 | + }, |
| 43 | + |
| 44 | + rules: { |
| 45 | + // - - - - - - - - - - - - |
| 46 | + // ESLint |
| 47 | + // - - - - - - - - - - - - |
| 48 | + camelcase: "warn", // Enforce camelcase naming convention |
| 49 | + curly: "error", // Enforce consistent brace style for all control statements |
| 50 | + eqeqeq: ["warn", "always", { null: "ignore" }], // Require the use of === and !== "ignore" -------> Do not apply this rule to null |
| 51 | + "logical-assignment-operators": [ |
| 52 | + "warn", |
| 53 | + "always", |
| 54 | + { enforceForIfStatements: true } |
| 55 | + ], // This rule checks for expressions that can be shortened using logical assignment operator |
| 56 | + "dot-notation": "warn", // This rule is aimed at maintaining code consistency and improving code readability by encouraging use of the dot notation style whenever possible. As such, it will warn when it encounters an unnecessary use of square-bracket notation. |
| 57 | + "max-depth": ["warn", 3], // Enforce a maximum depth that blocks can be nested. Many developers consider code difficult to read if blocks are nested beyond a certain depth |
| 58 | + "no-alert": "error", // Disallow the use of alert, confirm, and prompt |
| 59 | + "no-console": "warn", // Warning when using console.log, console.warn or console.error |
| 60 | + "no-else-return": ["warn", { allowElseIf: false }], // Disallow else blocks after return statements in if statements |
| 61 | + "no-extra-boolean-cast": "error", // Disallow unnecessary boolean casts |
| 62 | + "no-debugger": "error", // Error when using debugger; |
| 63 | + "no-duplicate-case": "error", // This rule disallows duplicate test expressions in case clauses of switch statements |
| 64 | + "no-empty": "error", // Disallow empty block statements |
| 65 | + "no-lonely-if": "error", // Disallow if statements as the only statement in else blocks |
| 66 | + "no-multi-assign": "error", // Disallow use of chained assignment expressions |
| 67 | + "no-nested-ternary": "error", // Errors when using nested ternary expressions |
| 68 | + "no-sequences": "error", // Disallow comma operators |
| 69 | + "no-undef": "off", // Allows defining undefined variables |
| 70 | + "no-unneeded-ternary": "error", // Disallow ternary operators when simpler alternatives exist |
| 71 | + "no-useless-return": "error", // Disallow redundant return statements |
| 72 | + "prefer-const": "error", |
| 73 | + "spaced-comment": ["error", "always", { exceptions: ["-", "+", "/"] }], // Enforce consistent spacing after the // or /* in a comment |
| 74 | + |
| 75 | + "no-prototype-builtins": "off", |
| 76 | + |
| 77 | + // - - - - - - - - - - - - |
| 78 | + // TypeScript |
| 79 | + // - - - - - - - - - - - - |
| 80 | + "@typescript-eslint/ban-types": "off", |
| 81 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 82 | + "@typescript-eslint/explicit-module-boundary-types": "off", |
| 83 | + "@typescript-eslint/no-explicit-any": "error", |
| 84 | + "@typescript-eslint/no-empty-function": "off", |
| 85 | + "@typescript-eslint/no-non-null-assertion": "off" |
| 86 | + |
| 87 | + // "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }] |
| 88 | + } |
| 89 | + } |
| 90 | +]); |
| 91 | + |
0 commit comments