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

build: use typescript-eslint@v6 internally #3541

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 42 additions & 26 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
module.exports = {
extends: ['react-app', 'prettier'],
extends: [
'eslint:recommended',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding 'eslint:recommended' is IME generally a good idea for all JS/TS codebases because it has a lot of good built-in rules. Was it intentional not to have it previously?

'prettier',
'react-app',
'plugin:node/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

project: true is already in typescript-eslint@v5. It's just a nice way to enable parserOptions.project 😄

tsconfigRootDir: __dirname,
},
rules: {
'jsx-a11y/href-no-hash': 'off',
'react/react-in-jsx-scope': 'off',

// Taken care of by TypeScript's `noUnusedLocals` / `noUnusedParameters`
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
// Silence some bizarre "rule not found" TSLint error
'@typescript-eslint/no-angle-bracket-type-assertion': 'off',
'no-redeclare': 'off',
// Silence some bizarre "rule not found" TSLint error
'@typescript-eslint/no-redeclare': 'off',
'no-use-before-define': 'off',

// These off/not-configured-the-way-we-want lint rules we like & opt into
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/consistent-type-imports': [
'error',
Expand All @@ -24,27 +32,35 @@ module.exports = {
additionalHooks: '(usePossiblyImmediateEffect)',
},
],

// Todo: investigate whether we'd like these on
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-function-type': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/sort-type-constituents': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/dot-notation': 'off',
'no-empty': 'off',
'prefer-const': 'off',
'prefer-rest-params': 'off',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each of these had at least a few existing warnings, so I didn't want to overreach and solve for them without asking. Are any of these rules ones you feel particularly strongly about?

If not, I can go ahead and fix for all their complaints.

},
overrides: [
// {
// // only add after https://github.com/typescript-eslint/typescript-eslint/pull/3463 is merged
// files: ['src/**/*.ts'],
// excludedFiles: [
// '**/tests/*.ts',
// '**/tests/**/*.ts',
// '**/tests/*.tsx',
// '**/tests/**/*.tsx',
// ],
// parserOptions: {
// project: './tsconfig.json',
// },
// rules: {
// '@typescript-eslint/prefer-readonly-parameter-types': [
// 'warn',
// { arraysAndTuplesOnly: true },
// ],
// },
// },
{
files: [
'packages/toolkit/src/tests/*.ts',
Expand Down
2 changes: 1 addition & 1 deletion examples/action-listener/counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"react-dom": "^18.1.0",
"react-redux": "^8.0.2",
"react-scripts": "5.0.1",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

typescript-eslint@v6 increases the minimum TS range to 4.3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, it looks like the Codesandbox environment is running on a version of Node too old for nullish coalescing assignment (??=)

+ node -v (in /tmp/4c6c9715)
v14.21.1
/tmp/4c6c9715/node_modules/@typescript-eslint/eslint-plugin/dist/util/getStringLength.js:16
    splitter ??= new grapheme_splitter_1.default();
             ^^^

SyntaxError: Unexpected token '??='
    at new Script (vm.js:102:7)

Per http://kangax.github.io/compat-table/es2016plus/ > 2021 features > Logical Assignment > ??= basic support, Node 16 up is needed.

},
"scripts": {
"start": "react-scripts start",
Expand Down
22 changes: 16 additions & 6 deletions examples/publish-ci/next/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
module.exports = {
extends: ['react-app', 'prettier'],
extends: [
'eslint:recommended',
'prettier',
'react-app',
'plugin:node/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
],
parser: '@typescript-eslint/parser',
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
rules: {
'jsx-a11y/href-no-hash': 'off',
'react/react-in-jsx-scope': 'off',
// Taken care of by TypeScript's `noUnusedLocals` / `noUnusedParameters`
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off',
// Silence some bizarre "rule not found" TSLint error
'@typescript-eslint/no-angle-bracket-type-assertion': 'off',
'no-redeclare': 'off',
// Silence some bizarre "rule not found" TSLint error
'@typescript-eslint/no-redeclare': 'off',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/consistent-type-imports': ['off'],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', disallowTypeAnnotations: false },
],
'react-hooks/exhaustive-deps': [
'warn',
{
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/advanced/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"eslintConfig": {
"extends": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"msw": "^0.40.2",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/conditional-fetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/deduping-queries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"eslintConfig": {
"extends": [
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/graphql-codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"typescript": "4.1.3"
},
"resolutions": {
"@typescript-eslint/parser": "4.4.1"
"@typescript-eslint/parser": "6.0.0-alpha.158"
},
"scripts": {
"develop": "cross-env CHOKIDAR_USEPOLLING=true yarn start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/faker": "^5.5.5",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/node": "^14.14.6",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4",
"typescript": "~4.3.4",
"whatwg-fetch": "^3.4.1"
},
"eslintConfig": {
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/mutations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/optimistic-update/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4",
"typescript": "~4.3.4",
"whatwg-fetch": "^3.4.1"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/pagination/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/faker": "^5.5.5",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/polling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"eslintConfig": {
"extends": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/faker": "^5.5.5",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/prefetching-automatic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/faker": "^5.5.5",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/prefetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/faker": "^5.5.5",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion examples/query/react/with-apiprovider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"devDependencies": {
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
"typescript": "~4.3.4"
},
"eslintConfig": {
"extends": [
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"examples/action-listener/*"
],
"devDependencies": {
"@typescript-eslint/eslint-plugin": "6.0.0-alpha.158",
"@typescript-eslint/parser": "6.0.0-alpha.158",
"eslint": "^7.25.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-react-app": "^7.0.1",
Expand All @@ -44,6 +46,8 @@
"@babel/helper-compilation-targets": "7.19.3",
"@babel/traverse": "7.19.3",
"@babel/types": "7.19.3",
"@typescript-eslint/eslint-plugin": "6.0.0-alpha.158",
"@typescript-eslint/parser": "6.0.0-alpha.158",
"console-testing-library": "patch:console-testing-library@npm:0.3.1#.yarn/patches/console-testing-library__npm_0.3.1.patch",
"msw": "patch:msw@npm:0.40.2#.yarn/patches/msw-npm-0.40.2-2107d48752",
"jscodeshift": "0.13.1",
Expand Down
10 changes: 9 additions & 1 deletion packages/rtk-codemods/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
module.exports = {
parserOptions: {
ecmaVersion: 2018,
project: true,
tsconfigRootDir: __dirname,
},

plugins: ['prettier', 'node'],
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:node/recommended'],
extends: [
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:node/recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
],
env: {
node: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import {
ExpressionStatement,
JSCodeshift,
ObjectExpression,
ObjectMethod,
ObjectProperty,
Transform,
} from 'jscodeshift';

type ObjectKey = ObjectMethod['key'] & ObjectProperty['key'];

function wrapInAddCaseExpression(
j: JSCodeshift,
addCaseArgs: (ExpressionKind | SpreadElementKind)[]
Expand Down
18 changes: 3 additions & 15 deletions packages/rtk-codemods/transforms/createSliceBuilder/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import { ExpressionKind, SpreadElementKind } from 'ast-types/gen/kinds';
import {
ExpressionStatement,
JSCodeshift,
ObjectExpression,
ObjectMethod,
ObjectProperty,
Transform,
} from 'jscodeshift';

type ObjectKey = ObjectMethod['key'] & ObjectProperty['key'];
import { ExpressionStatement, JSCodeshift, ObjectExpression, Transform } from 'jscodeshift';

function wrapInAddCaseExpression(
j: JSCodeshift,
Expand All @@ -32,7 +23,7 @@ export function reducerPropsToBuilderExpression(j: JSCodeshift, defNode: ObjectE
}
break;
}
case 'ObjectProperty': {
case 'ObjectProperty': {
const { key } = property;

switch (property.value.type) {
Expand Down Expand Up @@ -96,10 +87,7 @@ const transform: Transform = (file, api) => {
p.key.name === 'extraReducers' &&
p.value.type === 'ObjectExpression'
) {
const expressionStatement = reducerPropsToBuilderExpression(
j,
p.value as ObjectExpression
);
const expressionStatement = reducerPropsToBuilderExpression(j, p.value);
return j.objectProperty(p.key, expressionStatement);
}
return p;
Expand Down
2 changes: 1 addition & 1 deletion packages/rtk-query-codegen-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"prettier": "^2.2.1",
"semver": "^7.3.5",
"swagger2openapi": "^7.0.4",
"typescript": ">=4.1 <=4.5"
"typescript": ">=4.3 <=4.5"
},
"husky": {
"hooks": {
Expand Down
Loading