|
| 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 Commons-ui. |
| 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 js from '@eslint/js'; |
| 20 | + |
| 21 | +const jsConfig = [ |
| 22 | + // ESLint Recommended Rules |
| 23 | + { |
| 24 | + name: 'js/config', |
| 25 | + ...js.configs.recommended, |
| 26 | + }, |
| 27 | + // Stylistic Plugin |
| 28 | + plugins.stylistic, |
| 29 | + // Import X Plugin |
| 30 | + plugins.importX, |
| 31 | + // Airbnb Base Recommended Config |
| 32 | + ...configs.base.recommended, |
| 33 | +]; |
| 34 | + |
| 35 | +const reactConfig = [ |
| 36 | + // React Plugin |
| 37 | + plugins.react, |
| 38 | + // React Hooks Plugin |
| 39 | + plugins.reactHooks, |
| 40 | + // React JSX A11y Plugin |
| 41 | + plugins.reactA11y, |
| 42 | + // Airbnb React Recommended Config |
| 43 | + ...configs.react.recommended, |
| 44 | +]; |
| 45 | + |
| 46 | +const typescriptConfig = [ |
| 47 | + // TypeScript ESLint Plugin |
| 48 | + plugins.typescriptEslint, |
| 49 | + // Airbnb Base TypeScript Config |
| 50 | + ...configs.base.typescript, |
| 51 | + // Airbnb React TypeScript Config |
| 52 | + ...configs.react.typescript, |
| 53 | +]; |
| 54 | + |
| 55 | +const prettierConfig = [ |
| 56 | + // Prettier Plugin |
| 57 | + { |
| 58 | + name: 'prettier/plugin/config', |
| 59 | + plugins: { |
| 60 | + prettier: prettierPlugin, |
| 61 | + }, |
| 62 | + }, |
| 63 | + // Prettier Config (disable conflicting rules) |
| 64 | + { |
| 65 | + name: 'prettier/config', |
| 66 | + rules: { |
| 67 | + ...prettierConfigRules, |
| 68 | + 'prettier/prettier': 'warn', |
| 69 | + }, |
| 70 | + }, |
| 71 | +]; |
| 72 | + |
| 73 | +const projectConfig = [ |
| 74 | + { |
| 75 | + name: 'project/ignores', |
| 76 | + ignores: ['dist', 'coverage'], |
| 77 | + }, |
| 78 | + // Settings |
| 79 | + { |
| 80 | + name: 'project/settings', |
| 81 | + settings: { |
| 82 | + react: { |
| 83 | + version: 'detect', |
| 84 | + }, |
| 85 | + }, |
| 86 | + }, |
| 87 | + // React JSX Runtime (prevents "React must be in scope" errors) |
| 88 | + { |
| 89 | + name: 'project/react-jsx-runtime', |
| 90 | + files: ['**/*.{jsx,tsx}'], |
| 91 | + rules: { |
| 92 | + 'react/react-in-jsx-scope': 'off', |
| 93 | + 'react/jsx-uses-react': 'off', |
| 94 | + }, |
| 95 | + }, |
| 96 | + // Custom rules |
| 97 | + { |
| 98 | + name: 'project/rules', |
| 99 | + rules: { |
| 100 | + // Code style |
| 101 | + curly: 'error', |
| 102 | + 'no-console': 'off', |
| 103 | + 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }], |
| 104 | + |
| 105 | + // React rules |
| 106 | + 'react/jsx-props-no-spreading': 'off', |
| 107 | + 'react/require-default-props': 'off', |
| 108 | + |
| 109 | + // Import rules |
| 110 | + 'import-x/prefer-default-export': 'off', |
| 111 | + 'import-x/extensions': 'off', |
| 112 | + 'import-x/no-unresolved': 'off', |
| 113 | + 'import-x/no-useless-path-segments': 'off', |
| 114 | + 'import-x/no-extraneous-dependencies': [ |
| 115 | + 'error', |
| 116 | + { |
| 117 | + devDependencies: [ |
| 118 | + 'test/**', |
| 119 | + 'tests/**', |
| 120 | + 'spec/**', |
| 121 | + '**/__tests__/**', |
| 122 | + '**/__mocks__/**', |
| 123 | + 'test.{js,jsx,ts,tsx}', |
| 124 | + 'test-*.{js,jsx,ts,tsx}', |
| 125 | + '**/*{.,_}{test,spec}.{js,jsx,ts,tsx}', |
| 126 | + '**/jest.config.ts', |
| 127 | + '**/jest.setup.ts', |
| 128 | + '**/prettier.config.js', |
| 129 | + '**/vite.config.ts', |
| 130 | + '**/eslint.config.js', |
| 131 | + ], |
| 132 | + optionalDependencies: false, |
| 133 | + }, |
| 134 | + ], |
| 135 | + |
| 136 | + // MUI deep imports restriction |
| 137 | + 'no-restricted-imports': [ |
| 138 | + 'warn', |
| 139 | + { |
| 140 | + patterns: [ |
| 141 | + { |
| 142 | + group: [ |
| 143 | + '@mui/*/*', |
| 144 | + '!@mui/material/colors', |
| 145 | + '!@mui/material/locale', |
| 146 | + '!@mui/icons-material/*', |
| 147 | + ], |
| 148 | + message: |
| 149 | + 'Deep imports from MUI libraries are forbidden. Import only from the library root.', |
| 150 | + }, |
| 151 | + ], |
| 152 | + }, |
| 153 | + ], |
| 154 | + |
| 155 | + // Disable strict type-aware rules that weren't in old config |
| 156 | + '@typescript-eslint/no-unsafe-enum-comparison': 'off', |
| 157 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 158 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 159 | + '@typescript-eslint/consistent-indexed-object-style': 'off', |
| 160 | + '@typescript-eslint/no-empty-object-type': 'off', |
| 161 | + '@typescript-eslint/no-unnecessary-template-expression': 'off', |
| 162 | + '@typescript-eslint/no-duplicate-enum-values': 'off', |
| 163 | + '@typescript-eslint/no-wrapper-object-types': 'off', |
| 164 | + '@typescript-eslint/array-type': 'off', |
| 165 | + '@typescript-eslint/no-unnecessary-type-arguments': 'off', |
| 166 | + 'arrow-body-style': 'off', |
| 167 | + 'no-shadow': 'off', |
| 168 | + 'no-unused-expressions': ['error', { allowShortCircuit: true }], |
| 169 | + 'prefer-arrow-callback': 'off', |
| 170 | + 'no-unused-vars': ['off', { argsIgnorePattern: '^_' }], |
| 171 | + '@typescript-eslint/no-unnecessary-type-assertion': 'off', |
| 172 | + 'prefer-object-has-own': 'off', |
| 173 | + }, |
| 174 | + }, |
| 175 | +]; |
| 176 | + |
| 177 | +export default [...jsConfig, ...reactConfig, ...typescriptConfig, ...prettierConfig, ...projectConfig]; |
0 commit comments