|
| 1 | +import js from '@eslint/js' |
| 2 | +import typescript from '@typescript-eslint/eslint-plugin' |
| 3 | +import typescriptParser from '@typescript-eslint/parser' |
| 4 | +import importPlugin from 'eslint-plugin-import' |
| 5 | +import prettier from 'eslint-plugin-prettier' |
| 6 | +import react from 'eslint-plugin-react' |
| 7 | +import reactHooks from 'eslint-plugin-react-hooks' |
| 8 | +import vitest from 'eslint-plugin-vitest' |
| 9 | + |
| 10 | +export default [ |
| 11 | + js.configs.recommended, |
| 12 | + { |
| 13 | + files: ['**/*.{js,jsx,ts,tsx}'], |
| 14 | + languageOptions: { |
| 15 | + parser: typescriptParser, |
| 16 | + parserOptions: { |
| 17 | + ecmaVersion: 2018, |
| 18 | + sourceType: 'module', |
| 19 | + ecmaFeatures: { |
| 20 | + jsx: true, |
| 21 | + }, |
| 22 | + }, |
| 23 | + globals: { |
| 24 | + // Browser globals |
| 25 | + window: 'readonly', |
| 26 | + document: 'readonly', |
| 27 | + console: 'readonly', |
| 28 | + fetch: 'readonly', |
| 29 | + URL: 'readonly', |
| 30 | + URLSearchParams: 'readonly', |
| 31 | + // Node.js globals |
| 32 | + process: 'readonly', |
| 33 | + Buffer: 'readonly', |
| 34 | + __dirname: 'readonly', |
| 35 | + __filename: 'readonly', |
| 36 | + global: 'readonly', |
| 37 | + // ES6 globals |
| 38 | + Promise: 'readonly', |
| 39 | + Symbol: 'readonly', |
| 40 | + Map: 'readonly', |
| 41 | + Set: 'readonly', |
| 42 | + WeakMap: 'readonly', |
| 43 | + WeakSet: 'readonly', |
| 44 | + }, |
| 45 | + }, |
| 46 | + plugins: { |
| 47 | + '@typescript-eslint': typescript, |
| 48 | + react, |
| 49 | + 'react-hooks': reactHooks, |
| 50 | + import: importPlugin, |
| 51 | + prettier, |
| 52 | + vitest, |
| 53 | + }, |
| 54 | + rules: { |
| 55 | + // ESLint recommended rules are included via js.configs.recommended |
| 56 | + |
| 57 | + // Custom rules |
| 58 | + eqeqeq: 'error', |
| 59 | + 'no-var': 'error', |
| 60 | + 'prefer-const': 'error', |
| 61 | + curly: ['warn', 'multi-line', 'consistent'], |
| 62 | + 'no-console': 'off', |
| 63 | + |
| 64 | + // Import rules |
| 65 | + 'import/no-unresolved': ['error', { commonjs: true, amd: true }], |
| 66 | + 'import/export': 'error', |
| 67 | + 'import/no-duplicates': ['error'], |
| 68 | + 'import/order': [ |
| 69 | + 'error', |
| 70 | + { |
| 71 | + alphabetize: { order: 'asc', caseInsensitive: true }, |
| 72 | + groups: [ |
| 73 | + 'builtin', |
| 74 | + 'external', |
| 75 | + 'internal', |
| 76 | + 'parent', |
| 77 | + 'sibling', |
| 78 | + 'index', |
| 79 | + 'object', |
| 80 | + ], |
| 81 | + 'newlines-between': 'never', |
| 82 | + pathGroups: [ |
| 83 | + { |
| 84 | + pattern: 'react', |
| 85 | + group: 'builtin', |
| 86 | + position: 'before', |
| 87 | + }, |
| 88 | + ], |
| 89 | + pathGroupsExcludedImportTypes: ['builtin'], |
| 90 | + }, |
| 91 | + ], |
| 92 | + |
| 93 | + // TypeScript rules |
| 94 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 95 | + '@typescript-eslint/no-unused-vars': [ |
| 96 | + 'warn', |
| 97 | + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, |
| 98 | + ], |
| 99 | + '@typescript-eslint/no-use-before-define': 'off', |
| 100 | + '@typescript-eslint/no-empty-function': 'off', |
| 101 | + '@typescript-eslint/no-explicit-any': 'off', |
| 102 | + '@typescript-eslint/no-redeclare': 'off', |
| 103 | + 'no-unused-vars': 'off', // Use TypeScript version instead |
| 104 | + 'no-redeclare': 'off', // Use TypeScript version instead |
| 105 | + |
| 106 | + // React rules |
| 107 | + 'react/jsx-uses-react': 'off', |
| 108 | + 'react/react-in-jsx-scope': 'off', |
| 109 | + |
| 110 | + // React hooks rules |
| 111 | + 'react-hooks/rules-of-hooks': 'error', |
| 112 | + 'react-hooks/exhaustive-deps': 'warn', |
| 113 | + |
| 114 | + // Vitest rules |
| 115 | + 'vitest/consistent-test-it': [ |
| 116 | + 'error', |
| 117 | + { fn: 'it', withinDescribe: 'it' }, |
| 118 | + ], |
| 119 | + |
| 120 | + // Sort imports |
| 121 | + 'sort-imports': [ |
| 122 | + 'error', |
| 123 | + { |
| 124 | + ignoreDeclarationSort: true, |
| 125 | + }, |
| 126 | + ], |
| 127 | + }, |
| 128 | + settings: { |
| 129 | + react: { |
| 130 | + version: 'detect', |
| 131 | + }, |
| 132 | + 'import/extensions': ['.js', '.jsx', '.ts', '.tsx'], |
| 133 | + 'import/parsers': { |
| 134 | + '@typescript-eslint/parser': ['.js', '.jsx', '.ts', '.tsx'], |
| 135 | + }, |
| 136 | + 'import/resolver': { |
| 137 | + node: { |
| 138 | + extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'], |
| 139 | + paths: ['src'], |
| 140 | + }, |
| 141 | + alias: { |
| 142 | + extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'], |
| 143 | + map: [['jotai-tanstack-query', './src/index.ts']], |
| 144 | + }, |
| 145 | + }, |
| 146 | + }, |
| 147 | + }, |
| 148 | + { |
| 149 | + files: ['src/**/*.{ts,tsx}'], |
| 150 | + languageOptions: { |
| 151 | + parserOptions: { |
| 152 | + project: './tsconfig.json', |
| 153 | + }, |
| 154 | + }, |
| 155 | + }, |
| 156 | + { |
| 157 | + files: ['tests/**/*.tsx', '__tests__/**/*'], |
| 158 | + languageOptions: { |
| 159 | + globals: { |
| 160 | + describe: 'readonly', |
| 161 | + it: 'readonly', |
| 162 | + test: 'readonly', |
| 163 | + expect: 'readonly', |
| 164 | + beforeEach: 'readonly', |
| 165 | + afterEach: 'readonly', |
| 166 | + beforeAll: 'readonly', |
| 167 | + afterAll: 'readonly', |
| 168 | + vi: 'readonly', |
| 169 | + }, |
| 170 | + }, |
| 171 | + }, |
| 172 | + { |
| 173 | + files: ['./*.js'], |
| 174 | + rules: { |
| 175 | + '@typescript-eslint/no-var-requires': 'off', |
| 176 | + }, |
| 177 | + }, |
| 178 | + { |
| 179 | + files: ['examples/**/*.{ts,tsx}'], |
| 180 | + rules: { |
| 181 | + 'import/no-unresolved': 'off', |
| 182 | + }, |
| 183 | + }, |
| 184 | + { |
| 185 | + ignores: ['dist/**', 'src/vendor/**', 'node_modules/**'], |
| 186 | + }, |
| 187 | +] |
0 commit comments