Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Update @typescript-eslint/* packages and remove deprecated eslint-config-airbnb-typescript package #45245

Merged
merged 10 commits into from
Feb 11, 2025
32 changes: 15 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = /** @type {Config} */ ({
'plugin:eslint-plugin-import/recommended',
'plugin:eslint-plugin-import/typescript',
'eslint-config-airbnb',
'eslint-config-airbnb-typescript',
'./eslint/config-airbnb-typescript.js',
'eslint-config-prettier',
],
parser: '@typescript-eslint/parser',
Expand All @@ -74,7 +74,7 @@ module.exports = /** @type {Config} */ ({
plugins: [
'eslint-plugin-material-ui',
'eslint-plugin-react-hooks',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint',
'eslint-plugin-filenames',
...(ENABLE_REACT_COMPILER_PLUGIN ? ['eslint-plugin-react-compiler'] : []),
],
Expand All @@ -92,6 +92,7 @@ module.exports = /** @type {Config} */ ({
rules: {
'consistent-this': ['error', 'self'],
curly: ['error', 'all'],
'dot-notation': 'error',
// Just as bad as "max components per file"
'max-classes-per-file': 'off',
// Too interruptive
Expand All @@ -112,14 +113,18 @@ module.exports = /** @type {Config} */ ({
],
'no-continue': 'off',
'no-constant-condition': 'error',
'no-implied-eval': 'error',
'no-throw-literal': 'error',
// Use the proptype inheritance chain
'no-prototype-builtins': 'off',
'no-return-await': 'error',
'no-underscore-dangle': 'error',
'nonblock-statement-body-position': 'error',
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
// Destructuring harm grep potential.
'prefer-destructuring': 'off',

'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [
'error',
{
Expand All @@ -128,24 +133,17 @@ module.exports = /** @type {Config} */ ({
variables: true,
},
],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ vars: 'all', args: 'after-used', ignoreRestSiblings: true, argsIgnorePattern: '^_' },
{
vars: 'all',
args: 'after-used',
ignoreRestSiblings: true,
argsIgnorePattern: '^_',
caughtErrors: 'none',
Copy link
Member Author

@ZeeshanTamboli ZeeshanTamboli Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Override caughtErrors to none here to avoid an unused error parameter eslint error in the catch block. It's a breaking change in v8—the default is changed to all. See https://typescript-eslint.io/blog/announcing-typescript-eslint-v8/#rule-breaking-changes. So I had to override it.

},
],
'no-use-before-define': 'off',

// disabled type-aware linting due to performance considerations
'@typescript-eslint/dot-notation': 'off',
'dot-notation': 'error',
// disabled type-aware linting due to performance considerations
'@typescript-eslint/no-implied-eval': 'off',
'no-implied-eval': 'error',
// disabled type-aware linting due to performance considerations
'@typescript-eslint/no-throw-literal': 'off',
'no-throw-literal': 'error',
// disabled type-aware linting due to performance considerations
'@typescript-eslint/return-await': 'off',
'no-return-await': 'error',

// Not sure why it doesn't work
'import/named': 'off',
Expand Down
111 changes: 111 additions & 0 deletions eslint/config-airbnb-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const { rules: baseBestPracticesRules } = require('eslint-config-airbnb-base/rules/best-practices');
const { rules: baseES6Rules } = require('eslint-config-airbnb-base/rules/es6');
const { rules: baseImportsRules } = require('eslint-config-airbnb-base/rules/imports');
const { rules: baseStyleRules } = require('eslint-config-airbnb-base/rules/style');
const { rules: baseVariablesRules } = require('eslint-config-airbnb-base/rules/variables');

module.exports = {
settings: {
// Apply special parsing for TypeScript files
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
},
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx', '.d.ts'],
},
},
// Append 'ts' extensions to Airbnb 'import/extensions' setting
// Original: ['.js', '.mjs', '.jsx']
'import/extensions': ['.js', '.mjs', '.jsx', '.ts', '.tsx', '.d.ts'],
// Resolve type definition packages
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
},
rules: {
camelcase: 'off',
// The `@typescript-eslint/naming-convention` rule allows `leadingUnderscore` and `trailingUnderscore` settings. However, the existing `no-underscore-dangle` rule already takes care of this.
'@typescript-eslint/naming-convention': [
'error',
// Allow camelCase variables (23.2), PascalCase variables (23.8), and UPPER_CASE variables (23.10)
{
selector: 'variable',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
},
// Allow camelCase functions (23.2), and PascalCase functions (23.8)
{
selector: 'function',
format: ['camelCase', 'PascalCase'],
},
// 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
{
selector: 'typeLike',
format: ['PascalCase'],
},
],
'default-param-last': 'off',
'@typescript-eslint/default-param-last': baseBestPracticesRules['default-param-last'],
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': baseStyleRules['no-array-constructor'],
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': baseBestPracticesRules['no-empty-function'],
'no-loss-of-precision': 'error',
'no-loop-func': 'off',
'@typescript-eslint/no-loop-func': baseBestPracticesRules['no-loop-func'],
'no-magic-numbers': 'off',
'@typescript-eslint/no-magic-numbers': baseBestPracticesRules['no-magic-numbers'],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': baseVariablesRules['no-shadow'],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': baseBestPracticesRules['no-unused-expressions'],
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': baseES6Rules['no-useless-constructor'],
'require-await': 'off',
'@typescript-eslint/require-await': baseBestPracticesRules['require-await'],

// Append 'ts' and 'tsx' to Airbnb 'import/extensions' rule
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
'import/extensions': [
baseImportsRules['import/extensions'][0],
baseImportsRules['import/extensions'][1],
typeof baseImportsRules['import/extensions'][2] === 'object'
? {
...baseImportsRules['import/extensions'][2],
ts: 'never',
tsx: 'never',
}
: { ts: 'never', tsx: 'never' },
],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
// The following rules are enabled in Airbnb config, but are already checked (more thoroughly) by the TypeScript compiler
// Some of the rules also fail in TypeScript files, for example: https://github.com/typescript-eslint/typescript-eslint/issues/662#issuecomment-507081586
// Rules are inspired by: https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
'constructor-super': 'off',
'getter-return': 'off',
'no-const-assign': 'off',
'no-dupe-args': 'off',
'no-dupe-class-members': 'off',
'no-dupe-keys': 'off',
'no-func-assign': 'off',
'no-import-assign': 'off',
'no-new-symbol': 'off',
'no-obj-calls': 'off',
'no-redeclare': 'off',
'no-setter-return': 'off',
'no-this-before-super': 'off',
'no-undef': 'off',
'no-unreachable': 'off',
'no-unsafe-negation': 'off',
'valid-typeof': 'off',
// The following rules are enabled in Airbnb config, but are recommended to be disabled within TypeScript projects
// See: https://github.com/typescript-eslint/typescript-eslint/blob/13583e65f5973da2a7ae8384493c5e00014db51b/docs/linting/TROUBLESHOOTING.md#eslint-plugin-import
'import/named': 'off',
'import/no-named-as-default-member': 'off',
'import/no-unresolved': 'off',
},
},
],
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
"@types/node": "^20.17.17",
"@types/react": "^19.0.8",
"@types/yargs": "^17.0.33",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/eslint-plugin": "^8.23.0",
"@typescript-eslint/parser": "^8.23.0",
"@vitest/browser": "^3.0.5",
"@vitest/coverage-v8": "^3.0.5",
"babel-loader": "^9.2.1",
Expand All @@ -155,7 +155,7 @@
"danger": "^12.3.3",
"eslint": "^8.57.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^18.0.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^10.0.1",
"eslint-import-resolver-webpack": "^0.13.10",
"eslint-plugin-babel": "^5.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"devDependencies": {
"@types/eslint": "^8.56.12",
"@typescript-eslint/parser": "^7.18.0",
"@typescript-eslint/parser": "^8.23.0",
"eslint": "^8.57.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { StylesProviderProps } from '../StylesProvider';

declare class ServerStyleSheets {
constructor(options?: object);

collect(children: React.ReactNode, options?: object): React.ReactElement<StylesProviderProps>;

toString(): string;

getStyleElement(props?: object): React.ReactElement<any>;
}

Expand Down
Loading