|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | + |
| 8 | +/** |
| 9 | + * Base ESLint config initially generated by `eslint-config-airbnb-extended` (v2.3.2) |
| 10 | + * using the React + Prettier + TypeScript template, then manually adapted for GridStudy. |
| 11 | + * Source template: |
| 12 | + * https://eslint-airbnb-extended.nishargshah.dev/cli/guide |
| 13 | + * https://github.com/NishargShah/eslint-config-airbnb-extended/blob/v2.3.2/packages/create-airbnb-x-config/templates/react/prettier/ts/default/eslint.config.mjs |
| 14 | + */ |
| 15 | + |
| 16 | +import { configs, plugins } from 'eslint-config-airbnb-extended'; |
| 17 | +import { rules as prettierConfigRules } from 'eslint-config-prettier'; |
| 18 | +import prettierPlugin from 'eslint-plugin-prettier'; |
| 19 | +import reactRefreshPlugin from 'eslint-plugin-react-refresh'; |
| 20 | +import js from '@eslint/js'; |
| 21 | + |
| 22 | +const jsConfig = [ |
| 23 | + // ESLint Recommended Rules |
| 24 | + { |
| 25 | + name: 'js/config', |
| 26 | + ...js.configs.recommended, |
| 27 | + }, |
| 28 | + // Stylistic Plugin |
| 29 | + plugins.stylistic, |
| 30 | + // Import X Plugin |
| 31 | + plugins.importX, |
| 32 | + // Airbnb Base Recommended Config |
| 33 | + ...configs.base.recommended, |
| 34 | +]; |
| 35 | + |
| 36 | +const reactConfig = [ |
| 37 | + // React Plugin |
| 38 | + plugins.react, |
| 39 | + // React Hooks Plugin |
| 40 | + plugins.reactHooks, |
| 41 | + // React JSX A11y Plugin |
| 42 | + plugins.reactA11y, |
| 43 | + // Airbnb React Recommended Config |
| 44 | + ...configs.react.recommended, |
| 45 | +]; |
| 46 | + |
| 47 | +const typescriptConfig = [ |
| 48 | + // TypeScript ESLint Plugin |
| 49 | + plugins.typescriptEslint, |
| 50 | + // Airbnb Base TypeScript Config |
| 51 | + ...configs.base.typescript, |
| 52 | + // Airbnb React TypeScript Config |
| 53 | + ...configs.react.typescript, |
| 54 | +]; |
| 55 | + |
| 56 | +const prettierConfig = [ |
| 57 | + // Prettier Plugin |
| 58 | + { |
| 59 | + name: 'prettier/plugin/config', |
| 60 | + plugins: { |
| 61 | + prettier: prettierPlugin, |
| 62 | + }, |
| 63 | + }, |
| 64 | + // Prettier Config (disable conflicting rules) |
| 65 | + { |
| 66 | + name: 'prettier/config', |
| 67 | + rules: { |
| 68 | + ...prettierConfigRules, |
| 69 | + 'prettier/prettier': 'warn', |
| 70 | + }, |
| 71 | + }, |
| 72 | +]; |
| 73 | + |
| 74 | +const projectConfig = [ |
| 75 | + { |
| 76 | + name: 'project/ignores', |
| 77 | + ignores: ['dist', 'build', 'coverage'], |
| 78 | + }, |
| 79 | + { |
| 80 | + name: 'project/settings', |
| 81 | + settings: { |
| 82 | + react: { |
| 83 | + version: 'detect', |
| 84 | + }, |
| 85 | + // TypeScript import resolver settings |
| 86 | + 'import-x/parsers': { |
| 87 | + '@typescript-eslint/parser': ['.ts', '.tsx'], |
| 88 | + }, |
| 89 | + 'import-x/resolver': { |
| 90 | + typescript: { |
| 91 | + alwaysTryTypes: true, |
| 92 | + project: './tsconfig.json', |
| 93 | + }, |
| 94 | + }, |
| 95 | + }, |
| 96 | + }, |
| 97 | + // React Refresh Plugin |
| 98 | + { |
| 99 | + name: 'project/react-refresh', |
| 100 | + files: ['**/*.{jsx,tsx}'], |
| 101 | + plugins: { |
| 102 | + 'react-refresh': reactRefreshPlugin, |
| 103 | + }, |
| 104 | + rules: { |
| 105 | + 'react-refresh/only-export-components': ['error', { allowConstantExport: true }], |
| 106 | + }, |
| 107 | + }, |
| 108 | + // React JSX Runtime (prevents "React must be in scope" errors) |
| 109 | + { |
| 110 | + name: 'project/react-jsx-runtime', |
| 111 | + files: ['**/*.{jsx,tsx}'], |
| 112 | + rules: { |
| 113 | + 'react/react-in-jsx-scope': 'off', |
| 114 | + 'react/jsx-uses-react': 'off', |
| 115 | + }, |
| 116 | + }, |
| 117 | + // Custom rules |
| 118 | + { |
| 119 | + name: 'project/rules', |
| 120 | + rules: { |
| 121 | + // Code style |
| 122 | + curly: 'error', |
| 123 | + 'no-console': 'off', |
| 124 | + 'no-plusplus': 'off', |
| 125 | + |
| 126 | + // React rules |
| 127 | + 'react/jsx-props-no-spreading': 'off', |
| 128 | + 'react/require-default-props': 'off', |
| 129 | + |
| 130 | + // Import rules |
| 131 | + 'import-x/prefer-default-export': 'off', |
| 132 | + 'import-x/extensions': 'off', |
| 133 | + 'import-x/no-unresolved': 'off', |
| 134 | + 'import-x/no-useless-path-segments': 'off', |
| 135 | + 'import-x/no-cycle': [ |
| 136 | + 'off', // TODO: Re-enable and fix circular dependencies in the codebase |
| 137 | + { |
| 138 | + maxDepth: Infinity, |
| 139 | + ignoreExternal: true, |
| 140 | + }, |
| 141 | + ], |
| 142 | + 'import-x/no-self-import': 'error', |
| 143 | + 'import-x/no-extraneous-dependencies': [ |
| 144 | + 'off', // Disabled to allow devDependencies in all files, TO FIX later (use type-only imports for typescript types) |
| 145 | + { |
| 146 | + devDependencies: true, |
| 147 | + optionalDependencies: false, |
| 148 | + }, |
| 149 | + ], |
| 150 | + |
| 151 | + // MUI deep imports - disabled |
| 152 | + 'no-restricted-imports': 'off', |
| 153 | + |
| 154 | + // ============================================ |
| 155 | + // Rules disabled to match old .eslintrc.json behavior |
| 156 | + // ============================================ |
| 157 | + |
| 158 | + // Stylistic rules |
| 159 | + '@stylistic/lines-between-class-members': 'off', |
| 160 | + '@stylistic/spaced-comment': 'off', |
| 161 | + 'arrow-body-style': 'off', |
| 162 | + 'dot-notation': 'off', |
| 163 | + 'func-names': 'off', // Disabled - was causing ~20 warnings |
| 164 | + 'object-shorthand': 'off', |
| 165 | + 'operator-assignment': 'off', |
| 166 | + 'prefer-arrow-callback': 'off', |
| 167 | + 'prefer-const': 'off', |
| 168 | + 'prefer-destructuring': 'off', |
| 169 | + 'prefer-exponentiation-operator': 'off', |
| 170 | + 'prefer-template': 'off', |
| 171 | + radix: 'off', |
| 172 | + yoda: 'off', |
| 173 | + |
| 174 | + // Code quality rules |
| 175 | + camelcase: 'off', |
| 176 | + 'class-methods-use-this': 'off', |
| 177 | + 'consistent-return': 'off', |
| 178 | + 'default-case': 'off', |
| 179 | + 'no-await-in-loop': 'off', |
| 180 | + 'no-case-declarations': 'off', |
| 181 | + 'no-cond-assign': 'off', |
| 182 | + 'no-continue': 'off', |
| 183 | + 'no-else-return': 'off', |
| 184 | + 'no-extra-boolean-cast': 'off', |
| 185 | + 'no-lonely-if': 'off', |
| 186 | + 'no-nested-ternary': 'off', |
| 187 | + 'no-param-reassign': 'off', |
| 188 | + 'no-prototype-builtins': 'off', |
| 189 | + 'no-restricted-exports': 'off', |
| 190 | + 'no-restricted-globals': 'off', |
| 191 | + 'no-restricted-properties': 'off', |
| 192 | + 'no-restricted-syntax': 'off', |
| 193 | + 'no-return-assign': 'off', |
| 194 | + 'no-shadow': 'off', |
| 195 | + 'no-undef-init': 'off', |
| 196 | + 'no-unneeded-ternary': 'off', |
| 197 | + 'no-unsafe-optional-chaining': 'off', |
| 198 | + 'no-unused-expressions': 'off', |
| 199 | + 'no-unused-vars': 'off', |
| 200 | + 'no-use-before-define': 'off', |
| 201 | + 'no-useless-return': 'off', |
| 202 | + |
| 203 | + // Import rules |
| 204 | + 'import-x/newline-after-import': 'off', |
| 205 | + 'import-x/no-duplicates': 'off', |
| 206 | + 'import-x/no-named-as-default': 'off', |
| 207 | + 'import-x/order': 'off', |
| 208 | + |
| 209 | + // React rules |
| 210 | + 'react/destructuring-assignment': 'off', |
| 211 | + 'react/forbid-prop-types': 'off', |
| 212 | + 'react/function-component-definition': 'off', |
| 213 | + 'react/jsx-boolean-value': 'off', |
| 214 | + 'react/jsx-curly-brace-presence': 'off', |
| 215 | + 'react/jsx-no-bind': 'off', |
| 216 | + 'react/jsx-no-constructed-context-values': 'off', |
| 217 | + 'react/jsx-no-duplicate-props': 'off', |
| 218 | + 'react/jsx-no-useless-fragment': 'off', |
| 219 | + 'react/no-array-index-key': 'off', |
| 220 | + 'react/no-children-prop': 'off', |
| 221 | + 'react/no-unstable-nested-components': 'off', |
| 222 | + 'react/no-unused-prop-types': 'off', |
| 223 | + 'react/prop-types': 'off', |
| 224 | + 'react/self-closing-comp': 'off', |
| 225 | + |
| 226 | + // TypeScript rules |
| 227 | + '@typescript-eslint/consistent-indexed-object-style': 'off', |
| 228 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 229 | + '@typescript-eslint/default-param-last': 'off', |
| 230 | + '@typescript-eslint/dot-notation': 'off', |
| 231 | + '@typescript-eslint/naming-convention': 'off', |
| 232 | + '@typescript-eslint/no-empty-object-type': 'off', |
| 233 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 234 | + '@typescript-eslint/no-shadow': 'off', |
| 235 | + '@typescript-eslint/no-unnecessary-template-expression': 'off', |
| 236 | + '@typescript-eslint/no-unnecessary-type-arguments': 'off', |
| 237 | + '@typescript-eslint/no-unnecessary-type-assertion': 'off', |
| 238 | + '@typescript-eslint/no-unsafe-enum-comparison': 'off', |
| 239 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 240 | + '@typescript-eslint/no-unused-vars': 'off', |
| 241 | + '@typescript-eslint/no-use-before-define': 'off', |
| 242 | + '@typescript-eslint/no-wrapper-object-types': 'off', |
| 243 | + '@typescript-eslint/prefer-destructuring': 'off', |
| 244 | + '@typescript-eslint/prefer-function-type': 'off', |
| 245 | + '@typescript-eslint/return-await': 'off', |
| 246 | + }, |
| 247 | + }, |
| 248 | +]; |
| 249 | + |
| 250 | +export default [...jsConfig, ...reactConfig, ...typescriptConfig, ...prettierConfig, ...projectConfig]; |
0 commit comments