| 1 | import tsParser from "@typescript-eslint/parser"; |
| 2 | import tsPlugin from "@typescript-eslint/eslint-plugin"; |
| 3 | import importPlugin from "eslint-plugin-import"; |
| 4 | import unusedImports from "eslint-plugin-unused-imports"; |
| 5 | |
| 6 | export default [ |
| 7 | { |
| 8 | files: ["**/*.ts", "**/*.tsx"], |
| 9 | plugins: { |
| 10 | "@typescript-eslint": tsPlugin, |
| 11 | import: importPlugin, |
| 12 | "unused-imports": unusedImports, |
| 13 | }, |
| 14 | languageOptions: { |
| 15 | parser: tsParser, |
| 16 | parserOptions: { |
| 17 | project: "./tsconfig.json", |
| 18 | ecmaVersion: "latest", |
| 19 | sourceType: "module", |
| 20 | }, |
| 21 | }, |
| 22 | rules: { |
| 23 | // Core rules - all as errors |
| 24 | "max-classes-per-file": ["error", 1], |
| 25 | "prefer-const": "error", |
| 26 | // "class-methods-use-this": [ |
| 27 | // "error", |
| 28 | // { |
| 29 | // exceptMethods: [ |
| 30 | // "render", |
| 31 | // "shouldComponentUpdate", |
| 32 | // "componentDidMount", |
| 33 | // "componentDidUpdate", |
| 34 | // "componentWillUnmount", |
| 35 | // ], |
| 36 | // }, |
| 37 | // ], |
| 38 | "no-negated-condition": "error", |
| 39 | "max-lines": [ |
| 40 | "error", |
| 41 | { max: 500, skipBlankLines: true, skipComments: true }, |
| 42 | ], |
| 43 | complexity: ["error", { max: 20 }], |
| 44 | // "max-lines-per-function": [ |
| 45 | // "error", |
| 46 | // { max: 150, skipBlankLines: true, skipComments: true }, |
| 47 | // ], |
| 48 | "max-statements": ["error", { max: 50 }], |
| 49 | "max-depth": ["error", { max: 4 }], |
| 50 | "max-nested-callbacks": ["error", { max: 3 }], |
| 51 | "max-params": ["error", { max: 5 }], |
| 52 | eqeqeq: "error", |
| 53 | |
| 54 | // TypeScript specific rules |
| 55 | // "@typescript-eslint/no-floating-promises": "error", |
| 56 | "@typescript-eslint/no-explicit-any": "error", |
| 57 | // "@typescript-eslint/member-ordering": [ |
| 58 | // "error", |
| 59 | // { |
| 60 | // default: [ |
| 61 | // // Static fields |
| 62 | // "public-static-field", |
| 63 | // "protected-static-field", |
| 64 | // "private-static-field", |
| 65 | |
| 66 | // // Instance fields |
| 67 | // "public-instance-field", |
| 68 | // "protected-instance-field", |
| 69 | // "private-instance-field", |
| 70 | |
| 71 | // // Constructors |
| 72 | // "constructor", |
| 73 | |
| 74 | // // Static methods |
| 75 | // "public-static-method", |
| 76 | // "protected-static-method", |
| 77 | // "private-static-method", |
| 78 | |
| 79 | // // Instance methods |
| 80 | // "public-instance-method", |
| 81 | // "protected-instance-method", |
| 82 | // "private-instance-method", |
| 83 | // ], |
| 84 | // }, |
| 85 | // ], |
| 86 | |
| 87 | // Import rules |
| 88 | "import/order": [ |
| 89 | "error", |
| 90 | { |
| 91 | groups: [ |
| 92 | "builtin", |
| 93 | "external", |
| 94 | "internal", |
| 95 | "parent", |
| 96 | "sibling", |
| 97 | "index", |
| 98 | ], |
| 99 | "newlines-between": "always", |
| 100 | alphabetize: { |
| 101 | order: "asc", |
| 102 | caseInsensitive: true, |
| 103 | }, |
| 104 | }, |
| 105 | ], |
| 106 | "import/no-default-export": "error", |
| 107 | |
| 108 | // Unused code detection |
| 109 | "no-unused-vars": "off", |
| 110 | "@typescript-eslint/no-unused-vars": "off", |
| 111 | "unused-imports/no-unused-imports": "error", |
| 112 | "unused-imports/no-unused-vars": [ |
| 113 | "error", |
| 114 | { |
| 115 | vars: "all", |
| 116 | varsIgnorePattern: "^_", |
| 117 | args: "after-used", |
| 118 | argsIgnorePattern: "^_", |
| 119 | }, |
| 120 | ], |
| 121 | |
| 122 | // Turn off rules that might be too strict for CLI |
| 123 | "@typescript-eslint/no-explicit-any": "off", |
| 124 | "@typescript-eslint/explicit-function-return-type": "off", |
| 125 | "@typescript-eslint/explicit-module-boundary-types": "off", |
| 126 | "@typescript-eslint/no-non-null-assertion": "off", |
| 127 | |
| 128 | // Allow console for CLI tool |
| 129 | "no-console": "off", |
| 130 | }, |
| 131 | settings: { |
| 132 | "import/resolver": { |
| 133 | typescript: { |
| 134 | project: "./tsconfig.json", |
| 135 | }, |
| 136 | node: true, |
| 137 | }, |
| 138 | }, |
| 139 | }, |
| 140 | { |
| 141 | // Allow default exports in specific files |
| 142 | files: ["src/index.ts", "*.config.js", "*.config.ts"], |
| 143 | rules: { |
| 144 | "import/no-default-export": "off", |
| 145 | }, |
| 146 | }, |
| 147 | { |
| 148 | // Test files can have different rules |
| 149 | files: [ |
| 150 | "**/*.test.ts", |
| 151 | "**/*.test.tsx", |
| 152 | "**/*.spec.ts", |
| 153 | "**/*.spec.tsx", |
| 154 | "**/test-helpers/**/*.ts", |
| 155 | "**/test-helpers/**/*.tsx", |
| 156 | "**/__tests__/**/*.ts", |
| 157 | "**/__tests__/**/*.tsx", |
| 158 | "**/__mocks__/**/*.ts", |
| 159 | "**/__mocks__/**/*.tsx", |
| 160 | ], |
| 161 | rules: { |
| 162 | "@typescript-eslint/no-explicit-any": "off", |
| 163 | "@typescript-eslint/no-floating-promises": "off", |
| 164 | "unused-imports/no-unused-vars": "off", |
| 165 | "max-classes-per-file": "off", |
| 166 | "max-lines": "off", |
| 167 | "max-lines-per-function": "off", |
| 168 | "max-statements": "off", |
| 169 | complexity: "off", |
| 170 | "class-methods-use-this": "off", |
| 171 | "max-nested-callbacks": "off", |
| 172 | }, |
| 173 | }, |
| 174 | { |
| 175 | ignores: [ |
| 176 | "dist/**", |
| 177 | "node_modules/**", |
| 178 | "coverage/**", |
| 179 | "*.d.ts", |
| 180 | "src/__mocks__/**", |
| 181 | "vitest.config.ts", |
| 182 | "*.config.js", |
| 183 | "*.config.ts", |
| 184 | ], |
| 185 | }, |
| 186 | ]; |