|
| 1 | +import path from 'node:path'; |
| 2 | +import { fileURLToPath } from 'node:url'; |
| 3 | +import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'; |
| 4 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 5 | +import pluginJavaScript from '@eslint/js'; |
| 6 | +import pluginTypeScript from '@typescript-eslint/eslint-plugin'; |
| 7 | +import pluginTypeScriptParser from '@typescript-eslint/parser'; |
| 8 | +import pluginImport from 'eslint-plugin-import'; |
| 9 | +import pluginPrettier from 'eslint-plugin-prettier'; |
| 10 | +import pluginReact from 'eslint-plugin-react'; |
| 11 | +import pluginReactHooks from 'eslint-plugin-react-hooks'; |
| 12 | +import pluginRxjs from 'eslint-plugin-rxjs'; |
| 13 | +import pluginUnusedImports from 'eslint-plugin-unused-imports'; |
| 14 | +import globals from 'globals'; |
| 15 | + |
| 16 | +const __filename = fileURLToPath(import.meta.url); |
| 17 | +const __dirname = path.dirname(__filename); |
| 18 | + |
| 19 | +const compat = new FlatCompat({ |
| 20 | + baseDirectory: __dirname, |
| 21 | + recommendedConfig: pluginJavaScript.configs.recommended, |
| 22 | + allConfig: pluginJavaScript.configs.all, |
| 23 | +}); |
| 24 | + |
| 25 | +export default [ |
| 26 | + { |
| 27 | + ignores: [ |
| 28 | + 'eslint.config.js', // ignore self |
| 29 | + '.yarn/*', |
| 30 | + 'node_modules', |
| 31 | + 'coverage', |
| 32 | + 'electron/build', |
| 33 | + 'electron/renderer/.next', |
| 34 | + 'electron/renderer/public', |
| 35 | + 'build', |
| 36 | + 'dist', |
| 37 | + '**/.DS_Store', |
| 38 | + '**/*.pem', |
| 39 | + '**/npm-debug.log*', |
| 40 | + '**/yarn-debug.log*', |
| 41 | + '**/yarn-error.log*', |
| 42 | + '**/.env*.local', |
| 43 | + '**/*.tsbuildinfo', |
| 44 | + '**/*.d.ts', |
| 45 | + ], |
| 46 | + }, |
| 47 | + ...fixupConfigRules( |
| 48 | + compat.extends( |
| 49 | + 'eslint:recommended', |
| 50 | + 'plugin:@next/next/recommended', |
| 51 | + 'plugin:import/recommended', |
| 52 | + 'plugin:prettier/recommended' |
| 53 | + ) |
| 54 | + ), |
| 55 | + { |
| 56 | + files: ['**/*.js', '**/*.ts', '**/*.tsx'], |
| 57 | + plugins: { |
| 58 | + 'import': fixupPluginRules(pluginImport), |
| 59 | + 'prettier': fixupPluginRules(pluginPrettier), |
| 60 | + 'unused-imports': fixupPluginRules(pluginUnusedImports), |
| 61 | + }, |
| 62 | + languageOptions: { |
| 63 | + globals: { |
| 64 | + ...globals.browser, |
| 65 | + ...globals.node, |
| 66 | + }, |
| 67 | + ecmaVersion: 'latest', |
| 68 | + sourceType: 'module', |
| 69 | + }, |
| 70 | + settings: { |
| 71 | + react: { |
| 72 | + version: 'detect', |
| 73 | + }, |
| 74 | + next: { |
| 75 | + rootDir: 'electron/renderer/', |
| 76 | + }, |
| 77 | + }, |
| 78 | + rules: { |
| 79 | + 'no-else-return': 'warn', |
| 80 | + 'no-plusplus': 'warn', |
| 81 | + 'curly': 'error', |
| 82 | + 'prefer-arrow-callback': 'error', |
| 83 | + 'sort-imports': [ |
| 84 | + 'error', |
| 85 | + { |
| 86 | + ignoreCase: false, |
| 87 | + ignoreDeclarationSort: true, |
| 88 | + ignoreMemberSort: false, |
| 89 | + memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'], |
| 90 | + allowSeparatedGroups: true, |
| 91 | + }, |
| 92 | + ], |
| 93 | + 'import/default': 'off', |
| 94 | + 'import/no-commonjs': 'error', |
| 95 | + 'import/no-unresolved': 'error', |
| 96 | + 'import/order': [ |
| 97 | + 'error', |
| 98 | + { |
| 99 | + 'newlines-between': 'never', |
| 100 | + |
| 101 | + 'alphabetize': { |
| 102 | + order: 'asc', |
| 103 | + caseInsensitive: true, |
| 104 | + }, |
| 105 | + }, |
| 106 | + ], |
| 107 | + 'unused-imports/no-unused-imports': 'error', |
| 108 | + }, |
| 109 | + }, |
| 110 | + ...fixupConfigRules( |
| 111 | + compat.extends( |
| 112 | + 'eslint:recommended', |
| 113 | + 'plugin:@next/next/recommended', |
| 114 | + 'plugin:@typescript-eslint/eslint-recommended', |
| 115 | + 'plugin:@typescript-eslint/recommended', |
| 116 | + 'plugin:import/recommended', |
| 117 | + 'plugin:import/electron', |
| 118 | + 'plugin:import/typescript', |
| 119 | + 'plugin:prettier/recommended', |
| 120 | + 'plugin:react/recommended', |
| 121 | + 'plugin:react/jsx-runtime', |
| 122 | + 'plugin:react-hooks/recommended', |
| 123 | + 'plugin:rxjs/recommended' |
| 124 | + ) |
| 125 | + ).map((config) => ({ |
| 126 | + ...config, |
| 127 | + files: ['electron/**/*.ts', 'electron/**/*.tsx'], |
| 128 | + })), |
| 129 | + { |
| 130 | + files: ['electron/**/*.ts', 'electron/**/*.tsx'], |
| 131 | + plugins: { |
| 132 | + '@typescript-eslint': fixupPluginRules(pluginTypeScript), |
| 133 | + 'import': fixupPluginRules(pluginImport), |
| 134 | + 'prettier': fixupPluginRules(pluginPrettier), |
| 135 | + 'react': fixupPluginRules(pluginReact), |
| 136 | + 'react-hooks': fixupPluginRules(pluginReactHooks), |
| 137 | + 'rxjs': fixupPluginRules(pluginRxjs), |
| 138 | + 'unused-imports': fixupPluginRules(pluginUnusedImports), |
| 139 | + }, |
| 140 | + languageOptions: { |
| 141 | + parser: pluginTypeScriptParser, |
| 142 | + ecmaVersion: 'latest', |
| 143 | + sourceType: 'module', |
| 144 | + parserOptions: { |
| 145 | + project: 'tsconfig.eslint.json', |
| 146 | + }, |
| 147 | + }, |
| 148 | + settings: { |
| 149 | + 'react': { |
| 150 | + version: 'detect', |
| 151 | + }, |
| 152 | + 'next': { |
| 153 | + rootDir: 'electron/renderer/', |
| 154 | + }, |
| 155 | + 'import/resolver': { |
| 156 | + typescript: { |
| 157 | + alwaysTryTypes: true, |
| 158 | + project: 'electron/*/tsconfig.json', |
| 159 | + }, |
| 160 | + }, |
| 161 | + }, |
| 162 | + rules: { |
| 163 | + '@typescript-eslint/array-type': [ |
| 164 | + 'warn', |
| 165 | + { |
| 166 | + default: 'generic', |
| 167 | + }, |
| 168 | + ], |
| 169 | + '@typescript-eslint/explicit-function-return-type': [ |
| 170 | + 'off', |
| 171 | + { |
| 172 | + allowTypedFunctionExpressions: false, |
| 173 | + }, |
| 174 | + ], |
| 175 | + '@typescript-eslint/explicit-module-boundary-types': [ |
| 176 | + 'error', |
| 177 | + { |
| 178 | + allowArgumentsExplicitlyTypedAsAny: true, |
| 179 | + }, |
| 180 | + ], |
| 181 | + '@typescript-eslint/consistent-type-imports': [ |
| 182 | + 'error', |
| 183 | + { |
| 184 | + disallowTypeAnnotations: false, |
| 185 | + }, |
| 186 | + ], |
| 187 | + '@typescript-eslint/await-thenable': 'error', |
| 188 | + '@typescript-eslint/no-misused-promises': 'error', |
| 189 | + '@typescript-eslint/no-floating-promises': 'error', |
| 190 | + '@typescript-eslint/require-await': 'off', |
| 191 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 192 | + '@typescript-eslint/no-empty-interface': 'off', |
| 193 | + '@typescript-eslint/no-explicit-any': 'off', |
| 194 | + '@typescript-eslint/no-namespace': 'off', |
| 195 | + '@typescript-eslint/no-unused-vars': [ |
| 196 | + 'warn', |
| 197 | + { |
| 198 | + vars: 'all', |
| 199 | + args: 'after-used', |
| 200 | + argsIgnorePattern: '^_', |
| 201 | + varsIgnorePattern: '^_', |
| 202 | + ignoreRestSiblings: true, |
| 203 | + }, |
| 204 | + ], |
| 205 | + 'import/default': 'off', |
| 206 | + 'import/namespace': 'off', |
| 207 | + 'react/no-unknown-property': [ |
| 208 | + 'error', |
| 209 | + { |
| 210 | + ignore: ['css'], |
| 211 | + }, |
| 212 | + ], |
| 213 | + 'react/display-name': [ |
| 214 | + 'error', |
| 215 | + { |
| 216 | + ignoreTranspilerName: false, |
| 217 | + checkContextObjects: true, |
| 218 | + }, |
| 219 | + ], |
| 220 | + 'rxjs/no-implicit-any-catch': 'off', |
| 221 | + }, |
| 222 | + }, |
| 223 | +]; |
0 commit comments