Skip to content

Commit ffb8ed9

Browse files
[core] Update @typescript-eslint/* packages and remove deprecated eslint-config-airbnb-typescript package (#45245)
1 parent 5f53376 commit ffb8ed9

File tree

6 files changed

+229
-142
lines changed

6 files changed

+229
-142
lines changed

.eslintrc.js

+15-17
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = /** @type {Config} */ ({
6464
'plugin:eslint-plugin-import/recommended',
6565
'plugin:eslint-plugin-import/typescript',
6666
'eslint-config-airbnb',
67-
'eslint-config-airbnb-typescript',
67+
'./eslint/config-airbnb-typescript.js',
6868
'eslint-config-prettier',
6969
],
7070
parser: '@typescript-eslint/parser',
@@ -74,7 +74,7 @@ module.exports = /** @type {Config} */ ({
7474
plugins: [
7575
'eslint-plugin-material-ui',
7676
'eslint-plugin-react-hooks',
77-
'@typescript-eslint/eslint-plugin',
77+
'@typescript-eslint',
7878
'eslint-plugin-filenames',
7979
...(ENABLE_REACT_COMPILER_PLUGIN ? ['eslint-plugin-react-compiler'] : []),
8080
],
@@ -92,6 +92,7 @@ module.exports = /** @type {Config} */ ({
9292
rules: {
9393
'consistent-this': ['error', 'self'],
9494
curly: ['error', 'all'],
95+
'dot-notation': 'error',
9596
// Just as bad as "max components per file"
9697
'max-classes-per-file': 'off',
9798
// Too interruptive
@@ -112,14 +113,18 @@ module.exports = /** @type {Config} */ ({
112113
],
113114
'no-continue': 'off',
114115
'no-constant-condition': 'error',
116+
'no-implied-eval': 'error',
117+
'no-throw-literal': 'error',
115118
// Use the proptype inheritance chain
116119
'no-prototype-builtins': 'off',
120+
'no-return-await': 'error',
117121
'no-underscore-dangle': 'error',
118122
'nonblock-statement-body-position': 'error',
119123
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
120124
// Destructuring harm grep potential.
121125
'prefer-destructuring': 'off',
122126

127+
'no-use-before-define': 'off',
123128
'@typescript-eslint/no-use-before-define': [
124129
'error',
125130
{
@@ -128,24 +133,17 @@ module.exports = /** @type {Config} */ ({
128133
variables: true,
129134
},
130135
],
136+
'no-unused-vars': 'off',
131137
'@typescript-eslint/no-unused-vars': [
132138
'error',
133-
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true, argsIgnorePattern: '^_' },
139+
{
140+
vars: 'all',
141+
args: 'after-used',
142+
ignoreRestSiblings: true,
143+
argsIgnorePattern: '^_',
144+
caughtErrors: 'none',
145+
},
134146
],
135-
'no-use-before-define': 'off',
136-
137-
// disabled type-aware linting due to performance considerations
138-
'@typescript-eslint/dot-notation': 'off',
139-
'dot-notation': 'error',
140-
// disabled type-aware linting due to performance considerations
141-
'@typescript-eslint/no-implied-eval': 'off',
142-
'no-implied-eval': 'error',
143-
// disabled type-aware linting due to performance considerations
144-
'@typescript-eslint/no-throw-literal': 'off',
145-
'no-throw-literal': 'error',
146-
// disabled type-aware linting due to performance considerations
147-
'@typescript-eslint/return-await': 'off',
148-
'no-return-await': 'error',
149147

150148
// Not sure why it doesn't work
151149
'import/named': 'off',

eslint/config-airbnb-typescript.js

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
const { rules: baseBestPracticesRules } = require('eslint-config-airbnb-base/rules/best-practices');
2+
const { rules: baseES6Rules } = require('eslint-config-airbnb-base/rules/es6');
3+
const { rules: baseImportsRules } = require('eslint-config-airbnb-base/rules/imports');
4+
const { rules: baseStyleRules } = require('eslint-config-airbnb-base/rules/style');
5+
const { rules: baseVariablesRules } = require('eslint-config-airbnb-base/rules/variables');
6+
7+
module.exports = {
8+
settings: {
9+
// Apply special parsing for TypeScript files
10+
'import/parsers': {
11+
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
12+
},
13+
'import/resolver': {
14+
node: {
15+
extensions: ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx', '.d.ts'],
16+
},
17+
},
18+
// Append 'ts' extensions to Airbnb 'import/extensions' setting
19+
// Original: ['.js', '.mjs', '.jsx']
20+
'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'],
21+
// Resolve type definition packages
22+
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
23+
},
24+
rules: {
25+
camelcase: 'off',
26+
// The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings. However, the existing `no-underscore-dangle` rule already takes care of this.
27+
'@typescript-eslint/naming-convention': [
28+
'error',
29+
// Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
30+
{
31+
selector: 'variable',
32+
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
33+
},
34+
// Allow camelCase functions (23.2), and PascalCase functions (23.8)
35+
{
36+
selector: 'function',
37+
format: ['camelCase', 'PascalCase'],
38+
},
39+
// Airbnb recommends PascalCase for classes (23.3), and although Airbnb does not make TypeScript recommendations, we are assuming this rule would similarly apply to anything "type like", including interfaces, type aliases, and enums
40+
{
41+
selector: 'typeLike',
42+
format: ['PascalCase'],
43+
},
44+
],
45+
'default-param-last': 'off',
46+
'@typescript-eslint/default-param-last': baseBestPracticesRules['default-param-last'],
47+
'no-array-constructor': 'off',
48+
'@typescript-eslint/no-array-constructor': baseStyleRules['no-array-constructor'],
49+
'no-empty-function': 'off',
50+
'@typescript-eslint/no-empty-function': baseBestPracticesRules['no-empty-function'],
51+
'no-loss-of-precision': 'error',
52+
'no-loop-func': 'off',
53+
'@typescript-eslint/no-loop-func': baseBestPracticesRules['no-loop-func'],
54+
'no-magic-numbers': 'off',
55+
'@typescript-eslint/no-magic-numbers': baseBestPracticesRules['no-magic-numbers'],
56+
'no-shadow': 'off',
57+
'@typescript-eslint/no-shadow': baseVariablesRules['no-shadow'],
58+
'no-unused-expressions': 'off',
59+
'@typescript-eslint/no-unused-expressions': baseBestPracticesRules['no-unused-expressions'],
60+
'no-useless-constructor': 'off',
61+
'@typescript-eslint/no-useless-constructor': baseES6Rules['no-useless-constructor'],
62+
'require-await': 'off',
63+
'@typescript-eslint/require-await': baseBestPracticesRules['require-await'],
64+
65+
// Append 'ts' and 'tsx' to Airbnb 'import/extensions' rule
66+
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
67+
'import/extensions': [
68+
baseImportsRules['import/extensions'][0],
69+
baseImportsRules['import/extensions'][1],
70+
typeof baseImportsRules['import/extensions'][2] === 'object'
71+
? {
72+
...baseImportsRules['import/extensions'][2],
73+
ts: 'never',
74+
tsx: 'never',
75+
}
76+
: { ts: 'never', tsx: 'never' },
77+
],
78+
},
79+
overrides: [
80+
{
81+
files: ['*.ts', '*.tsx'],
82+
rules: {
83+
// The following rules are enabled in Airbnb config, but are already checked (more thoroughly) by the TypeScript compiler
84+
// Some of the rules also fail in TypeScript files, for example: https://github.com/typescript-eslint/typescript-eslint/issues/662#issuecomment-507081586
85+
// Rules are inspired by: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
86+
'constructor-super': 'off',
87+
'getter-return': 'off',
88+
'no-const-assign': 'off',
89+
'no-dupe-args': 'off',
90+
'no-dupe-class-members': 'off',
91+
'no-dupe-keys': 'off',
92+
'no-func-assign': 'off',
93+
'no-import-assign': 'off',
94+
'no-new-symbol': 'off',
95+
'no-obj-calls': 'off',
96+
'no-redeclare': 'off',
97+
'no-setter-return': 'off',
98+
'no-this-before-super': 'off',
99+
'no-undef': 'off',
100+
'no-unreachable': 'off',
101+
'no-unsafe-negation': 'off',
102+
'valid-typeof': 'off',
103+
// The following rules are enabled in Airbnb config, but are recommended to be disabled within TypeScript projects
104+
// See: https://github.com/typescript-eslint/typescript-eslint/blob/13583e65f5973da2a7ae8384493c5e00014db51b/docs/linting/TROUBLESHOOTING.md#eslint-plugin-import
105+
'import/named': 'off',
106+
'import/no-named-as-default-member': 'off',
107+
'import/no-unresolved': 'off',
108+
},
109+
},
110+
],
111+
};

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@
136136
"@types/node": "^20.17.17",
137137
"@types/react": "^19.0.8",
138138
"@types/yargs": "^17.0.33",
139-
"@typescript-eslint/eslint-plugin": "^7.18.0",
140-
"@typescript-eslint/parser": "^7.18.0",
139+
"@typescript-eslint/eslint-plugin": "^8.23.0",
140+
"@typescript-eslint/parser": "^8.23.0",
141141
"@vitest/browser": "^3.0.5",
142142
"@vitest/coverage-v8": "^3.0.5",
143143
"babel-loader": "^9.2.1",
@@ -155,7 +155,7 @@
155155
"danger": "^12.3.3",
156156
"eslint": "^8.57.1",
157157
"eslint-config-airbnb": "^19.0.4",
158-
"eslint-config-airbnb-typescript": "^18.0.0",
158+
"eslint-config-airbnb-base": "^15.0.0",
159159
"eslint-config-prettier": "^10.0.1",
160160
"eslint-import-resolver-webpack": "^0.13.10",
161161
"eslint-plugin-babel": "^5.3.1",

packages/eslint-plugin-material-ui/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"devDependencies": {
1111
"@types/eslint": "^8.56.12",
12-
"@typescript-eslint/parser": "^7.18.0",
12+
"@typescript-eslint/parser": "^8.23.0",
1313
"eslint": "^8.57.1"
1414
},
1515
"peerDependencies": {

packages/mui-styles/src/ServerStyleSheets/ServerStyleSheets.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import { StylesProviderProps } from '../StylesProvider';
33

44
declare class ServerStyleSheets {
55
constructor(options?: object);
6+
67
collect(children: React.ReactNode, options?: object): React.ReactElement<StylesProviderProps>;
8+
79
toString(): string;
10+
811
getStyleElement(props?: object): React.ReactElement<any>;
912
}
1013

0 commit comments

Comments
 (0)