Skip to content

Commit bc49c63

Browse files
committed
front: migrate to ESLint flat config
ESLint v9 requires flat configs, it no longer supports the legacy config file format. Migrate our configuration file to prepare for the bump. --ext has been removed from the package.json script because ESLint rejects that CLI option when used with flat configs: file extensions are now specified in the config file directly. Signed-off-by: Simon Ser <contact@emersion.fr>
1 parent 78e7896 commit bc49c63

5 files changed

Lines changed: 213 additions & 198 deletions

File tree

front/.eslintrc

Lines changed: 0 additions & 195 deletions
This file was deleted.

front/eslint.config.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
import js from '@eslint/js';
2+
import importPlugin from 'eslint-plugin-import';
3+
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
4+
import prettierPluginRecommended from 'eslint-plugin-prettier/recommended';
5+
import reactPlugin from 'eslint-plugin-react';
6+
import reactHooksPlugin from 'eslint-plugin-react-hooks';
7+
import tseslint from 'typescript-eslint';
8+
import vitestPlugin from 'eslint-plugin-vitest';
9+
10+
export default [
11+
{
12+
files: ['**/*.ts', '**/*.tsx', '**/*.js'],
13+
ignores: [
14+
'src/common/api/generatedEditoastApi.ts',
15+
'src/common/api/osrdGatewayApi.ts',
16+
'public',
17+
'build',
18+
'playwright-report',
19+
'ui',
20+
],
21+
},
22+
...tseslint.config(js.configs.recommended, ...tseslint.configs.recommended),
23+
prettierPluginRecommended,
24+
importPlugin.flatConfigs.recommended,
25+
importPlugin.flatConfigs.typescript,
26+
reactPlugin.configs.flat.recommended,
27+
reactHooksPlugin.configs['recommended-latest'],
28+
vitestPlugin.configs.recommended,
29+
jsxA11yPlugin.flatConfigs.recommended,
30+
{
31+
languageOptions: {
32+
parserOptions: {
33+
projectService: true,
34+
tsconfigRootDir: import.meta.dirname,
35+
},
36+
},
37+
settings: {
38+
react: {
39+
version: 'detect',
40+
},
41+
'import/resolver': {
42+
typescript: true, // uses eslint-import-resolver-typescript
43+
},
44+
},
45+
rules: {
46+
'import/no-named-as-default': 'off',
47+
'import/no-named-as-default-member': 'off',
48+
'react-hooks/exhaustive-deps': 'off',
49+
'import/order': [
50+
'error',
51+
{
52+
groups: ['builtin', 'external', 'internal'],
53+
pathGroups: [
54+
{
55+
pattern: 'react',
56+
group: 'builtin',
57+
position: 'before',
58+
},
59+
],
60+
pathGroupsExcludedImportTypes: ['react'],
61+
'newlines-between': 'always',
62+
alphabetize: {
63+
order: 'asc',
64+
caseInsensitive: true,
65+
},
66+
},
67+
],
68+
'no-shadow': 'off',
69+
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
70+
'@typescript-eslint/consistent-type-imports': ['error', { fixStyle: 'inline-type-imports' }],
71+
'@typescript-eslint/no-shadow': 'error',
72+
'@typescript-eslint/no-use-before-define': 'error',
73+
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
74+
'@typescript-eslint/no-unsafe-return': 'error',
75+
'@typescript-eslint/no-unsafe-call': 'error',
76+
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
77+
78+
'@typescript-eslint/no-restricted-types': [
79+
'error',
80+
{
81+
types: {
82+
LegacyFilterSpecification: {
83+
message: 'Use ExpressionFilterSpecification instead',
84+
fixWith: 'ExpressionFilterSpecification',
85+
},
86+
'React.FC':
87+
'Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177',
88+
FC: 'Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177',
89+
'React.FunctionComponent':
90+
'Useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177',
91+
'React.FunctionalComponent':
92+
'Preact specific, useless and has some drawbacks, see https://github.com/facebook/create-react-app/pull/8177',
93+
},
94+
},
95+
],
96+
'arrow-body-style': ['error', 'as-needed'],
97+
'global-require': 'off',
98+
'import/extensions': [
99+
'error',
100+
'ignorePackages',
101+
{
102+
js: 'never',
103+
jsx: 'never',
104+
ts: 'never',
105+
tsx: 'never',
106+
},
107+
],
108+
'import/no-extraneous-dependencies': [
109+
'error',
110+
{
111+
devDependencies: [
112+
'**/*.spec.ts',
113+
'**/__tests__/**',
114+
'tests/**',
115+
'scripts/**',
116+
'playwright.config.ts',
117+
'vite.config.ts',
118+
],
119+
},
120+
],
121+
'jsx-a11y/click-events-have-key-events': 'off',
122+
'linebreak-style': ['error', 'unix'],
123+
'no-await-in-loop': 'off',
124+
'no-console': ['error', { allow: ['info', 'debug', 'warn', 'error'] }],
125+
'no-continue': 'off',
126+
'no-named-as-default': 'off',
127+
'no-param-reassign': 'off',
128+
'no-use-before-define': 'off',
129+
'no-restricted-syntax': 'off',
130+
'prettier/prettier': ['warn'],
131+
'react/forbid-prop-types': 'off',
132+
'react/jsx-filename-extension': 'off',
133+
'react/jsx-no-useless-fragment': 'error',
134+
'react/jsx-props-no-spreading': 0,
135+
'react/jsx-uses-react': 'off',
136+
'react/react-in-jsx-scope': 'off',
137+
'react/prefer-stateless-function': 'off',
138+
'react/static-property-placement': 0,
139+
// disable vitest/prefer-to-be because it does not authorize toEqual for the floats
140+
'vitest/prefer-to-be': 'off',
141+
'no-restricted-imports': [
142+
'error',
143+
{
144+
name: 'common/api/generatedEditoastApi',
145+
message: 'Please use common/api/osrdEditoastApi instead',
146+
},
147+
],
148+
149+
'@typescript-eslint/no-explicit-any': 2,
150+
'@typescript-eslint/explicit-module-boundary-types': 0,
151+
'@typescript-eslint/space-before-blocks': 0,
152+
camelcase: 0,
153+
'no-nonoctal-decimal-escape': 0,
154+
'no-param-reassign': 0,
155+
'no-unsafe-optional-chaining': 0,
156+
'object-curly-newline': 0,
157+
'react/function-component-definition': 0,
158+
'react/jsx-props-no-spreading': 0,
159+
'react/no-array-index-key': 0,
160+
'react/require-default-props': 0,
161+
162+
'@typescript-eslint/no-unused-vars': [
163+
'warn',
164+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
165+
],
166+
},
167+
},
168+
{
169+
files: ['src/common/api/generatedEditoastApi.ts', 'src/common/api/osrdGatewayApi.ts'],
170+
rules: {
171+
'@typescript-eslint/no-explicit-any': ['error', { fixToUnknown: true }],
172+
},
173+
},
174+
{
175+
files: ['tests/**/*.ts', 'tests/**/*.tsx'],
176+
rules: {
177+
'@typescript-eslint/no-floating-promises': 'error',
178+
'react-hooks/rules-of-hooks': 'off',
179+
},
180+
},
181+
];

0 commit comments

Comments
 (0)