|
1 | 1 | import js from '@eslint/js'; |
2 | | -import typescriptEslint from '@typescript-eslint/eslint-plugin'; |
3 | | -import typescriptParser from '@typescript-eslint/parser'; |
4 | | -import importPlugin from 'eslint-plugin-import'; |
5 | | -import preferArrowPlugin from 'eslint-plugin-prefer-arrow'; |
6 | | -import prettierPlugin from 'eslint-plugin-prettier'; |
7 | | -import unusedImportsPlugin from 'eslint-plugin-unused-imports'; |
| 2 | +import tseslint from 'typescript-eslint'; |
8 | 3 |
|
9 | 4 | export default [ |
10 | | - // Base JS rules |
| 5 | + // Base JS recommended rules |
11 | 6 | js.configs.recommended, |
12 | 7 |
|
13 | | - // Global ignores |
14 | | - { |
15 | | - ignores: ['**/node_modules/**', '**/dist/**', '**/coverage/**'], |
16 | | - }, |
| 8 | + // TypeScript recommended rules |
| 9 | + ...tseslint.configs.recommended, |
17 | 10 |
|
18 | | - // Base config for TS/JS files |
19 | 11 | { |
20 | | - files: ['**/*.{js,jsx,ts,tsx}'], |
| 12 | + files: ['**/*.ts', '**/*.tsx'], |
21 | 13 | languageOptions: { |
22 | | - ecmaVersion: 'latest', |
23 | | - sourceType: 'module', |
24 | | - }, |
25 | | - plugins: { |
26 | | - prettier: prettierPlugin, |
27 | | - import: importPlugin, |
28 | | - 'prefer-arrow': preferArrowPlugin, |
29 | | - 'unused-imports': unusedImportsPlugin, |
30 | | - }, |
31 | | - rules: { |
32 | | - // General rules (aligned with main project) |
33 | | - 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], |
34 | | - 'no-console': [ |
35 | | - 'warn', |
36 | | - { allow: ['group', 'groupCollapsed', 'groupEnd'] }, |
37 | | - ], |
38 | | - 'no-control-regex': 0, |
39 | | - 'no-debugger': 'error', |
40 | | - 'no-duplicate-imports': 'error', |
41 | | - 'no-undef': 'off', |
42 | | - 'no-unused-vars': 'off', |
43 | | - |
44 | | - // Import rules |
45 | | - 'import/no-relative-packages': 'error', |
46 | | - 'import/no-useless-path-segments': 'error', |
47 | | - 'import/no-duplicates': ['error', { considerQueryString: true }], |
48 | | - |
49 | | - // Prefer arrow functions |
50 | | - 'prefer-arrow/prefer-arrow-functions': [ |
51 | | - 'error', |
52 | | - { |
53 | | - disallowPrototype: true, |
54 | | - singleReturnOnly: false, |
55 | | - classPropertiesAllowed: false, |
56 | | - }, |
57 | | - ], |
58 | | - |
59 | | - // Unused imports |
60 | | - 'unused-imports/no-unused-imports': 'warn', |
61 | | - 'unused-imports/no-unused-vars': [ |
62 | | - 'warn', |
63 | | - { |
64 | | - vars: 'all', |
65 | | - varsIgnorePattern: '^_', |
66 | | - args: 'after-used', |
67 | | - argsIgnorePattern: '^_', |
68 | | - }, |
69 | | - ], |
70 | | - |
71 | | - // Prettier (formatting as lint errors if you want) |
72 | | - 'prettier/prettier': 'error', |
73 | | - }, |
74 | | - }, |
75 | | - |
76 | | - // TypeScript-specific configuration |
77 | | - { |
78 | | - files: ['**/*.{ts,tsx}'], |
79 | | - languageOptions: { |
80 | | - parser: typescriptParser, |
81 | 14 | parserOptions: { |
82 | | - ecmaFeatures: { |
83 | | - jsx: true, |
84 | | - }, |
| 15 | + project: true, |
| 16 | + tsconfigRootDir: import.meta.dirname, |
85 | 17 | }, |
86 | 18 | }, |
87 | | - plugins: { |
88 | | - '@typescript-eslint': typescriptEslint, |
89 | | - }, |
90 | 19 | rules: { |
91 | | - // Turn off base rule and use TS-aware versions |
92 | | - 'no-redeclare': 'off', |
93 | | - '@typescript-eslint/no-redeclare': 'error', |
94 | | - |
95 | | - '@typescript-eslint/ban-ts-comment': 'error', |
96 | | - '@typescript-eslint/consistent-type-imports': [ |
97 | | - 'error', |
98 | | - { |
99 | | - prefer: 'type-imports', |
100 | | - fixStyle: 'inline-type-imports', |
101 | | - }, |
102 | | - ], |
103 | | - '@typescript-eslint/explicit-function-return-type': 'off', |
104 | | - '@typescript-eslint/explicit-module-boundary-types': 'off', |
105 | | - '@typescript-eslint/interface-name-prefix': 'off', |
106 | | - '@typescript-eslint/no-empty-interface': [ |
107 | | - 'error', |
108 | | - { |
109 | | - allowSingleExtends: true, |
110 | | - }, |
| 20 | + // Common TypeScript-friendly tweaks |
| 21 | + '@typescript-eslint/no-unused-vars': [ |
| 22 | + 'warn', |
| 23 | + { argsIgnorePattern: '^_' }, |
111 | 24 | ], |
112 | 25 | '@typescript-eslint/no-explicit-any': 'off', |
113 | | - '@typescript-eslint/no-empty-function': 'off', |
114 | | - '@typescript-eslint/no-unused-vars': 'off', |
115 | | - }, |
116 | | - }, |
117 | | - |
118 | | - // Test files (Jest) |
119 | | - { |
120 | | - files: ['**/*.spec.@(ts|tsx|js|jsx)', '**/*.test.@(ts|tsx|js|jsx)'], |
121 | | - languageOptions: { |
122 | | - globals: { |
123 | | - jest: true, |
124 | | - describe: true, |
125 | | - it: true, |
126 | | - expect: true, |
127 | | - beforeEach: true, |
128 | | - afterEach: true, |
129 | | - beforeAll: true, |
130 | | - afterAll: true, |
131 | | - }, |
132 | | - }, |
133 | | - rules: { |
134 | | - '@typescript-eslint/no-non-null-assertion': 'off', |
| 26 | + 'no-unused-vars': 'off', // handled by TS rule |
135 | 27 | }, |
136 | 28 | }, |
137 | 29 | ]; |
0 commit comments