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

chore: upgrade @typescript-eslint #852

Conversation

lesha1201
Copy link
Contributor

@lesha1201 lesha1201 commented Dec 6, 2023

eslint-plugin-testing-library has an outdated dependency - @typescript-eslint/utils and because of it, in modern setups, it might result in duplicate @typescript-eslint/parser packages.

This PR upgrades all @typescript-eslint dependencies as well as TypeScript.

Because @typescript-eslint@6 uses package.json exports, we had to upgrade some dependencies which didn't support exports (see typescript-eslint/typescript-eslint#7284). Affected dependencies:

  • jest

I also dropped support for Node.js versions lower than 16 because they're not maintained anymore (v16 also not maintained but decided to leave it for now).

image

@typescript-eslint@6

Upgrading @typescript-eslint brought new rules. The rules I fixed:

`eslint-config-kentcdodds` uses some outdated packages which block
us from upgrading TypeScript dependencies.
Because `@typescript-eslint` uses package.json `exports`, we had to
upgrade some dependencies which didn't support `exports` (see
typescript-eslint/typescript-eslint#7284).

Affected dependencies:
- `jest`
extends: [
'kentcdodds',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

eslint-config-kentcdodds uses some outdated packages which block us from upgrading TypeScript dependencies properly. It didn't bring many rules so decided just use eslint:recommended, plugin:import/recommended and configure some rules manually.

Copy link
Member

Choose a reason for hiding this comment

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

I like this change! We should apply it anyway.

@@ -53,7 +53,7 @@ jobs:
fail-fast: false
matrix:
# The .x indicates "the most recent one"
node: [19.x, 18.x, 17.x, 16.x, 14.x, 14.17.0, 12.x, 12.22.0]
Copy link
Contributor Author

@lesha1201 lesha1201 Dec 6, 2023

Choose a reason for hiding this comment

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

Dropped support for Node.js versions lower than 16. They're not maintained for a long time and don't support package.json exports which is used at least in @typescript-eslint.

Comment on lines +1 to +6
# Files
package-lock.json

# Folders
node_modules/
dist/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add .prettierignore to ignore dist folder.

@@ -44,8 +55,8 @@ module.exports = {
project: ['./tsconfig.eslint.json'],
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict-type-checked',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can also add plugin:@typescript-eslint/stylistic-type-checked which brings some useful rules but I wasn't sure what rules should be used in the project.

@@ -54,6 +65,25 @@ module.exports = {
{ argsIgnorePattern: '^_' },
],
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-unnecessary-condition': '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.

Disabled that rule because we have a lot of errors from it in the project and fixing it might cause some issues. If we want to enable this rule, we need to fix it carefully.

Comment on lines +79 to 80
// @ts-expect-error -- TODO: fix me
property.init.value > 0
Copy link
Contributor Author

@lesha1201 lesha1201 Dec 6, 2023

Choose a reason for hiding this comment

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

Previously, we had suppressImplicitAnyIndexErrors: true in tsconfig.json which allowed such code. But in TypeScript v5, it complains about this configuration so I removed it.

I think we should fix such places but it's better to do it in a separate PR.

Comment on lines +5 to +6
"module": "Node16",
"moduleResolution": "Node16",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need this to support exports from package.json (typescript-eslint/typescript-eslint#7284).

"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"noImplicitAny": true,
"outDir": "./dist",
"removeComments": true,
"skipLibCheck": true,
"sourceMap": false,
"suppressImplicitAnyIndexErrors": true
"sourceMap": false
},
"include": ["./lib/**/*.ts"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should include all TS files by default so IDE can process all TS files and have a separate TS config for building the package. Decided to not do this in this PR.

@Belco90 Belco90 self-requested a review December 11, 2023 10:06
@Belco90
Copy link
Member

Belco90 commented Dec 11, 2023

Hi @lesha1201. Thanks for your contribution, but I'm afraid I have to reject this PR until ESLint v9 is released, and we bump the plugin to the next major:

  • We don't want to drop support for Node.js lower than v18 yet. We are aware they are not officially supported, but we want to support the same supported version as ESLint. They'll drop support for Node prior to v18.18 in ESLint v9, so we will do it once ESLint v9 is released.
  • For the previous reason, we are keeping @typescript-eslint/utils in v5. We will upgrade it in the next major together with dropping non-supported Node.js versions.
  • Upgrading TS to v5 should be addressed in a separate PR, it's too much for mixing it with other stuff. Same for other dependencies like jest.

@Belco90 Belco90 closed this Dec 11, 2023
@lesha1201
Copy link
Contributor Author

@Belco90

We don't want to drop support for Node.js lower than v18 yet. We are aware they are not officially supported, but we want to support the same supported version as ESLint. They'll drop support for Node prior to v18.18 in ESLint v9, so we will do it once ESLint v9 is released.

We only dropped support for Node.js lower than v16 in this PR. And it might work fine in v12 and v14 because they also support package.json exports but I didn't test it (https://nodejs.org/api/packages.html#exports) since typescript-eslint dropped official support for v12 and v14.

The main issue that motivated me to open this PR is that a lot of popular ESLint plugins uses typescript-eslint@6 and the most of TS projects use it as well which results in duplicated @typescript-eslint/parser when using it with eslint-plugin-testing-library.

ESLint v9 won't be released soon. We can create a major release now that upgrades TS related packages and then create another major release that upgrades ESLint v9 and something else. Users who rely on old Node.js versions can use the current version of eslint-plugin-testing-library and if they report some issue that can be patched, we can create a patch release for them. Another option is to create alpha release so the users can start using it eliminating the issue with duplicated @typescript-eslint/parser.


Should I open separate PRs for some changes? If so can you please write a list of changes that you would like to see in separate PRs? Also do you have other tasks I can work on? For example, we can upgrade Prettier.

@Belco90
Copy link
Member

Belco90 commented Dec 12, 2023

We only dropped support for Node.js lower than v16 in this PR

That's already a breaking change, but also it's not in the same page as versions supported by ESLint v8.

ESLint v9 won't be released soon. We can create a major release now that upgrades TS related packages and then create another major release that upgrades ESLint v9 and something else.

We could indeed. No idea when ESLint will be released, but I want to avoid releasing a major just for the sake of upgrading typescript-eslint.

I get the motivation for all the updates you did (I was planning to start working on it during Christmas break, so any help is appreciated). However, we can't perform them all at once, and some will have to wait a bit. In order to keep discussing it, I'll open a new issue.

@Belco90 Belco90 mentioned this pull request Dec 12, 2023
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants