Skip to content

Commit 965d31a

Browse files
committed
Upgrade to ESLint 9 with flat config to fix release build
The release build failed with: [eslint] Couldn't find FlatESLint, you might need to set eslintPath to 'eslint/use-at-your-own-risk' eslint-webpack-plugin v5 defaults to ESLint's flat config system, which requires ESLint 9. The project was still on ESLint 8 and had no ESLint configuration file at all, so linting never effectively ran. Following the same approach already used in Stepup-Gateway: - Upgrade eslint to ^9 and add @eslint/js and typescript-eslint - Drop eslint-config-airbnb and eslint-plugin-import (unused: ESLint 8 config files never existed, and airbnb does not support flat config) - Add eslint.config.mjs with recommended + type-checked TS rules - Scope the webpack ESLint plugin to assets/typescript and fail the production build on lint errors - Fix the two lint findings this surfaced in app.ts and registration-print.ts
1 parent c7be898 commit 965d31a

6 files changed

Lines changed: 371 additions & 1187 deletions

File tree

assets/typescript/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import jQuery from 'jquery';
2-
(window as any).jQuery = jQuery;
2+
(window as unknown as { jQuery: typeof jQuery }).jQuery = jQuery;
33
import 'bootstrap';

assets/typescript/registration-print.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import jQuery from 'jquery';
1515
* limitations under the License.
1616
*/
1717

18-
document.addEventListener('DOMContentLoaded', (_) => {
18+
document.addEventListener('DOMContentLoaded', () => {
1919
jQuery('a.registration-print').on('click', (e) => {
2020
e.preventDefault();
2121

eslint.config.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import js from '@eslint/js';
2+
import typescriptEslint from 'typescript-eslint';
3+
4+
export default [
5+
{
6+
ignores: [
7+
'vendor/**',
8+
'node_modules/**',
9+
'var/**',
10+
'public/build/**',
11+
'build/**',
12+
'dist/**',
13+
],
14+
},
15+
js.configs.recommended,
16+
...typescriptEslint.configs.recommendedTypeChecked,
17+
{
18+
files: ['**/*.ts', '**/*.tsx'],
19+
languageOptions: {
20+
parserOptions: {
21+
project: './tsconfig.json',
22+
tsconfigRootDir: import.meta.dirname,
23+
},
24+
},
25+
rules: {
26+
'@typescript-eslint/no-explicit-any': 'warn',
27+
'@typescript-eslint/no-unused-vars': 'warn',
28+
},
29+
},
30+
{
31+
// Disable type-checking rules for JS files
32+
files: ['**/*.js', '**/*.jsx'],
33+
...typescriptEslint.configs.disableTypeChecked,
34+
},
35+
];

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
"devDependencies": {
44
"@babel/core": "^7.29.7",
55
"@babel/preset-env": "^7.29.7",
6+
"@eslint/js": "^9.39.4",
67
"@symfony/webpack-encore": "^5.0.0",
78
"@types/jest": "^30",
89
"@types/jquery": "^3.5.32",
910
"@types/node": "^20",
1011
"compass-mixins": "^0.12.10",
1112
"css-loader": "^7.1.4",
12-
"eslint": "^8.57.0",
13-
"eslint-config-airbnb": "^19.0",
14-
"eslint-plugin-import": "^2.31.0",
13+
"eslint": "^9.39.4",
1514
"eslint-webpack-plugin": "^5.0.3",
15+
"typescript-eslint": "^8.59.3",
1616
"file-loader": "^6.0.0",
1717
"jest": "^30",
1818
"less": "^4.6.4",

webpack.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ Encore
3737
})
3838
.addLoader({test: /\.scss$/, loader: 'webpack-import-glob-loader', enforce: 'pre'})
3939
.addPlugin(new ESLintPlugin({
40-
extensions: ['js', 'jsx', 'ts', 'tsx', 'vue'],
40+
extensions: ['ts', 'js'],
41+
files: 'assets/typescript',
42+
emitWarning: true,
43+
failOnError: Encore.isProduction(),
4144
}))
4245
.enableSingleRuntimeChunk()
4346
.enableSourceMaps(!Encore.isProduction())

0 commit comments

Comments
 (0)