|
| 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 our project. |
| 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': ['error', { allowForLoopAfterthoughts: true }], |
| 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 | + 'error', |
| 137 | + { |
| 138 | + maxDepth: Infinity, |
| 139 | + ignoreExternal: true, |
| 140 | + }, |
| 141 | + ], |
| 142 | + 'import-x/no-self-import': 'error', |
| 143 | + 'import-x/no-extraneous-dependencies': [ |
| 144 | + 'error', |
| 145 | + { |
| 146 | + devDependencies: [ |
| 147 | + 'test/**', // tape, common npm pattern |
| 148 | + 'tests/**', // also common npm pattern |
| 149 | + 'spec/**', // mocha, rspec-like pattern |
| 150 | + '**/__tests__/**', // jest pattern |
| 151 | + '**/__mocks__/**', // jest pattern |
| 152 | + 'test.{js,jsx,ts,tsx}', // repos with a single test file |
| 153 | + 'test-*.{js,jsx,ts,tsx}', // repos with multiple top-level test files |
| 154 | + '**/*{.,_}{test,spec}.{js,jsx,ts,tsx}', // tests where the extension or filename suffix denotes that it is a test |
| 155 | + '**/jest.config.ts', // jest config |
| 156 | + '**/jest.setup.ts', // jest setup |
| 157 | + '**/prettier.config.js', |
| 158 | + '**/vite.config.ts', |
| 159 | + '**/eslint.config.js', |
| 160 | + ], |
| 161 | + optionalDependencies: false, |
| 162 | + }, |
| 163 | + ], |
| 164 | + |
| 165 | + // ============================================ |
| 166 | + // Rules disabled to match old .eslintrc.json behavior |
| 167 | + // ============================================ |
| 168 | + |
| 169 | + // EsLint core rules |
| 170 | + 'arrow-body-style': 'off', |
| 171 | + 'prefer-arrow-callback': 'off', |
| 172 | + 'object-shorthand': 'off', |
| 173 | + 'prefer-const': 'off', |
| 174 | + 'prefer-template': 'off', |
| 175 | + 'no-else-return': 'off', |
| 176 | + 'consistent-return': 'off', |
| 177 | + 'default-case': 'off', |
| 178 | + 'no-param-reassign': 'off', |
| 179 | + |
| 180 | + // TypeScript rules |
| 181 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 182 | + '@typescript-eslint/no-empty-object-type': 'off', |
| 183 | + '@typescript-eslint/no-shadow': 'off', |
| 184 | + '@typescript-eslint/no-unused-vars': 'off', |
| 185 | + '@typescript-eslint/no-use-before-define': 'off', |
| 186 | + '@typescript-eslint/no-unsafe-function-type': 'off', |
| 187 | + |
| 188 | + // Stylistic rules |
| 189 | + '@stylistic/spaced-comment': 'off', |
| 190 | + |
| 191 | + // Import rules |
| 192 | + 'import-x/order': 'off', |
| 193 | + 'import-x/no-empty-named-blocks': 'off', |
| 194 | + 'import-x/newline-after-import': 'off', |
| 195 | + 'import-x/no-named-as-default': 'off', |
| 196 | + |
| 197 | + // React rules |
| 198 | + 'react/function-component-definition': 'off', |
| 199 | + 'react/jsx-curly-brace-presence': 'off', |
| 200 | + 'react/jsx-boolean-value': 'off', |
| 201 | + 'react/destructuring-assignment': 'off', |
| 202 | + 'react/self-closing-comp': 'off', |
| 203 | + 'react/no-unstable-nested-components': 'off', |
| 204 | + 'react/jsx-no-bind': 'off', |
| 205 | + }, |
| 206 | + }, |
| 207 | +]; |
| 208 | + |
| 209 | +export default [...jsConfig, ...reactConfig, ...typescriptConfig, ...prettierConfig, ...projectConfig]; |
0 commit comments