Skip to content

Commit 20d606b

Browse files
committed
chore(eslint)!: upgrade eslint package to version 9
Upgrade shared eslint package to latest eslint - removed relative PF impoers rule, imports are transformed at build time by TSC plugin - migration documented at packages/eslint-config/docs/eslint-9-migration.md
1 parent d5b435e commit 20d606b

File tree

4 files changed

+72
-219
lines changed

4 files changed

+72
-219
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Eslint 9 migration guide
2+
3+
Official Eslint migration guide: https://eslint.org/docs/latest/use/migrate-to-9.0.0
4+
5+
## HCC UI module migration
6+
7+
### Upgrade eslint packages
8+
9+
Upgrade the `@redhat-cloud-services/eslint-config-redhat-cloud-services` package to v `^3.0.0`.
10+
11+
Upgrade any locally installed eslint-related packages in your repository to version compatible with eslint@9.
12+
13+
### Update your eslint config
14+
15+
Eslint 9 changes its configuration schema quite significantly. Composite configurations can now be composed, instead of referenced by a string. To use the FEC configuration you can compose it:
16+
17+
```js
18+
import { defineConfig } from "eslint/config";
19+
import fecPlugin from '@redhat-cloud-services/eslint-config-redhat-cloud-services'
20+
21+
export default defineConfig(
22+
fecConfig,
23+
{
24+
// custom configuration
25+
}
26+
)
27+
```

packages/eslint-config/index.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,55 @@
1+
const globals = require('globals');
2+
const { defineConfig } = require('eslint/config');
3+
const reactPlugin = require('eslint-plugin-react');
14
const rulesDirPlugin = require('eslint-plugin-rulesdir');
5+
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
6+
const babelParser = require('@babel/eslint-parser');
27
const path = require('path');
38
rulesDirPlugin.RULES_DIR = path.resolve(__dirname, './lib/rules');
49

5-
module.exports = {
6-
parser: '@babel/eslint-parser',
7-
env: {
8-
browser: true,
9-
node: true,
10-
es6: true,
11-
jasmine: true,
12-
jest: true,
10+
// fix bad global names
11+
const patchedBrowserGlobals = {
12+
...globals.browser,
13+
};
14+
// Fixes issues with version mismatch between eslint-plugin-react and eslint
15+
// https://github.com/sindresorhus/globals/pull/184
16+
delete patchedBrowserGlobals['AudioWorkletGlobalScope '];
17+
patchedBrowserGlobals['AudioWorkletGlobalScope'] = 'readonly';
18+
19+
module.exports = defineConfig(eslintPluginPrettierRecommended, reactPlugin.configs.flat.recommended, {
20+
plugins: {
21+
rulesdir: rulesDirPlugin,
1322
},
1423
settings: {
1524
react: {
1625
version: 'detect',
1726
},
1827
},
19-
plugins: ['prettier', 'rulesdir'],
20-
extends: ['eslint:recommended', 'prettier', 'plugin:prettier/recommended', 'plugin:react/recommended'],
2128
rules: {
2229
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
2330
'prettier/prettier': ['error', { singleQuote: true }],
2431
'rulesdir/disallow-fec-relative-imports': 2,
2532
'rulesdir/deprecated-packages': 1,
2633
'rulesdir/no-chrome-api-call-from-window': 2,
27-
'rulesdir/forbid-pf-relative-imports': 1,
2834
'rulesdir/disallow-pf-migrated-components': 1,
2935
},
30-
globals: {
31-
CRC_APP_NAME: 'readonly',
32-
},
33-
parserOptions: {
34-
ecmaVersion: 7,
35-
sourceType: 'module',
36+
languageOptions: {
37+
globals: {
38+
...patchedBrowserGlobals,
39+
...globals.node,
40+
...globals.jasmine,
41+
...globals.jest,
42+
...globals.es6,
43+
CRC_APP_NAME: 'readonly',
44+
},
45+
parser: babelParser,
46+
parserOptions: {
47+
requireConfigFile: false,
48+
ecmaVersion: 7,
49+
sourceType: 'module',
50+
babelOptions: {
51+
presets: ['@babel/preset-react'],
52+
},
53+
},
3654
},
37-
};
55+
});

packages/eslint-config/lib/rules/forbid-pf-relative-imports.js

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

packages/eslint-config/package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
],
1010
"scripts": {},
1111
"dependencies": {
12-
"@babel/eslint-parser": "^7.19.1",
13-
"eslint-config-prettier": "^8.5.0",
14-
"eslint-plugin-prettier": "^3.4.1",
15-
"eslint-plugin-react": "^7.31.8",
16-
"eslint-plugin-rulesdir": "^0.2.1",
17-
"prettier": "^2.7.1"
12+
"@babel/eslint-parser": "^7.27.0",
13+
"@babel/preset-react": "^7.26.3",
14+
"eslint-config-prettier": "^10.1.2",
15+
"eslint-plugin-prettier": "^5.2.6",
16+
"eslint-plugin-react": "^7.37.5",
17+
"eslint-plugin-rulesdir": "^0.2.2",
18+
"globals": "^16.0.0",
19+
"prettier": "^3.5.3"
1820
},
1921
"peerDependencies": {
2022
"@babel/core": "^7.14.0",
21-
"eslint": "^8.9.0"
23+
"eslint": "^9.24.0"
2224
},
2325
"license": "Apache",
2426
"publishConfig": {

0 commit comments

Comments
 (0)