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

[Fix] @typescript-eslint v6 use typeArguments with fallback to typeParameters #3629

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

HenryBrown0
Copy link
Contributor

@HenryBrown0 HenryBrown0 commented Sep 4, 2023

Follows the guide from @typescript-eslint to upgrade to v6, by adding a small utility function getTypeArguments which returns the typeArguments or falls back to typeParameters.

Closes #3602

…rst-prop-new-line`, `jsx-props-no-multi-spaces`, `propTypes`: use type args
@codecov
Copy link

codecov bot commented Sep 4, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.66%. Comparing base (b4b7497) to head (f5bd822).
Report is 33 commits behind head on master.

❗ Current head f5bd822 differs from pull request most recent head fa6a122. Consider uploading reports for the commit fa6a122 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3629      +/-   ##
==========================================
+ Coverage   97.65%   97.66%   +0.01%     
==========================================
  Files         132      132              
  Lines        9379     9382       +3     
  Branches     3433     3445      +12     
==========================================
+ Hits         9159     9163       +4     
+ Misses        220      219       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

Seems good, altho there's an uncovered line.

lib/util/propTypes.js Outdated Show resolved Hide resolved
lib/util/propTypes.js Outdated Show resolved Hide resolved
@henkkasoft
Copy link

Hopefully this is fixed and merged soon.

@ljharb
Copy link
Member

ljharb commented Nov 2, 2023

@HenryBrown0 any update on those smaller PRs?

@HenryBrown0
Copy link
Contributor Author

@HenryBrown0 any update on those smaller PRs?

Sorry I got side tracked, I'll try getting some tests written in the next few days

@ljharb ljharb force-pushed the fix/@typescript-eslint-v6-throws-deprecation-warnings branch from 0f45d97 to 586b162 Compare November 4, 2023 04:18
@ljharb
Copy link
Member

ljharb commented Nov 4, 2023

Can we add some tests that would have failed without these typeArguments checks? That may require adding tests that run on typescript-eslint v6.

@HenryBrown0
Copy link
Contributor Author

Can we add some tests that would have failed without these typeArguments checks? That may require adding tests that run on typescript-eslint v6.

typeParameters has been marked as @deprecated rather than removed, I'm not sure how writing tests will work here. I've added v6 to ci. Hopefully this is good to go?

Copy link

socket-security bot commented Nov 27, 2023

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@typescript-eslint/parser 5.62.0...6.15.0 None +6/-0 33.7 MB jameshenry

@ljharb
Copy link
Member

ljharb commented Nov 27, 2023

Fair, I'll take that (and rebase this) assuming tests pass :-) thanks!

@osdiab
Copy link

osdiab commented Dec 20, 2023

looking forward to this!

@ljharb ljharb force-pushed the fix/@typescript-eslint-v6-throws-deprecation-warnings branch 3 times, most recently from 2929087 to f5bd822 Compare December 20, 2023 06:52
@ljharb ljharb marked this pull request as ready for review December 20, 2023 06:52
@ljharb ljharb marked this pull request as draft December 20, 2023 07:09
@ljharb
Copy link
Member

ljharb commented Dec 20, 2023

@HenryBrown0 unfortunately a number of tests are failing. any idea why?

@HenryBrown0
Copy link
Contributor Author

@HenryBrown0 unfortunately a number of tests are failing. any idea why?

Unit tests are failing on master for me, has a dependency changed?

It appears only minor version of Node.js 6 are failing, e.g. 18.6.8 and 19.6.8. I suspect this is a red herring as the matrix build reports using different node versions;

  • 18.5.9 uses 18.19.0 and passes
  • 18.6.8 uses 18.19.0 and fails
    Not sure why this is happening

@ljharb
Copy link
Member

ljharb commented Dec 20, 2023

Thanks, in that case I'll check out master and report back.

@ljharb
Copy link
Member

ljharb commented Dec 20, 2023

@HenryBrown0 tests seem to be passing on master https://github.com/jsx-eslint/eslint-plugin-react/actions (i checked on my fork before pushing to this repo, so i expect these to pass).

@@ -37,7 +37,7 @@ const parsers = {
BABEL_ESLINT: path.join(__dirname, NODE_MODULES, 'babel-eslint'),
'@BABEL_ESLINT': path.join(__dirname, NODE_MODULES, '@babel/eslint-parser'),
TYPESCRIPT_ESLINT: path.join(__dirname, NODE_MODULES, 'typescript-eslint-parser'),
'@TYPESCRIPT_ESLINT': path.join(__dirname, NODE_MODULES, '@typescript-eslint/parser'),
'@TYPESCRIPT_ESLINT': path.join(__dirname, NODE_MODULES, '@typescript-eslint/parser/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.

@typescript-eslint/parser removed the main field in v6, which pointed to dist/index.js. Not sure how tests were passing before, as this would have been wrong for all of v6.

Copy link
Member

Choose a reason for hiding this comment

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

exports['.'] would still work in node versions that support exports, which might be the only node versions that v6 supports?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v6 supports node versions ^16.0.0 || >=18.0.0, but even if I'm running this locally with node 18 it still fails to find the export

Copy link
Member

Choose a reason for hiding this comment

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

interesting, indeed node 18 should work - line 15 in https://unpkg.com/browse/@typescript-eslint/parser@6.19.0/package.json points there.

Copy link

Choose a reason for hiding this comment

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

It works* locally when I switch it to importing the specific file:

Suggested change
'@TYPESCRIPT_ESLINT': path.join(__dirname, NODE_MODULES, '@typescript-eslint/parser/dist'),
'@TYPESCRIPT_ESLINT': path.join(__dirname, NODE_MODULES, '@typescript-eslint/parser/dist/index.js'),

*as in, other things break later 🙃 - https://github.com/jsx-eslint/eslint-plugin-react/pull/3629/files#r1580983575

@JoshuaKGoldberg
Copy link

👋 @HenryBrown0 do you still have time to work on this? We're at v7 in typescript-eslint (https://typescript-eslint.io/blog/announcing-typescript-eslint-v7) and working on v8 - which will remove the old properties altogether.

Even if there are still some cases that log for deprecated property access (https://github.com/jsx-eslint/eslint-plugin-react/pull/3629/files#r1511579466) I personally would very much like to see this PR merged. That way the v8 branch of typescript-eslint can use the impacted rules. Want any help? ❤️

@HenryBrown0
Copy link
Contributor Author

👋 @HenryBrown0 do you still have time to work on this? We're at v7 in typescript-eslint (https://typescript-eslint.io/blog/announcing-typescript-eslint-v7) and working on v8 - which will remove the old properties altogether.

Even if there are still some cases that log for deprecated property access (https://github.com/jsx-eslint/eslint-plugin-react/pull/3629/files#r1511579466) I personally would very much like to see this PR merged. That way the v8 branch of typescript-eslint can use the impacted rules. Want any help? ❤️

I'm going to look at this again this evening. #3629 (comment) was giving me issues before, maybe you have some ideas how this can be resolved?

package.json Outdated

Choose a reason for hiding this comment

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

Once https://github.com/jsx-eslint/eslint-plugin-react/pull/3629/files#r1454015312 is fixed, we get this lovely crash on any rule that uses @typescript-eslint/parser:

TypeError: import_typescript.default.isTokenKind is not a function
      at forEachToken (/Users/josh/repos/eslint-plugin-react/node_modules/ts-api-utils/lib/index.cjs:260:35)
      at Object.forEachComment (/Users/josh/repos/eslint-plugin-react/node_modules/ts-api-utils/lib/index.cjs:309:10)
      at convertComments (/Users/josh/repos/eslint-plugin-react/node_modules/@typescript-eslint/typescript-estree/dist/convert-comments.js:40:13)
      at astConverter (/Users/josh/repos/eslint-plugin-react/node_modules/@typescript-eslint/typescript-estree/dist/ast-converter.js:56:66)
      at parseAndGenerateServices (/Users/josh/repos/eslint-plugin-react/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:170:66)
      at Object.parseForESLint (/Users/josh/repos/eslint-plugin-react/node_modules/@typescript-eslint/parser/dist/parser.js:93:80)
      at Object.parseForESLint (/Users/josh/repos/eslint-plugin-react/node_modules/eslint/lib/rule-tester/rule-tester.js:314:36)
      at parse (/Users/josh/repos/eslint-plugin-react/node_modules/eslint/lib/linter/linter.js:834:22)
      at Linter._verifyWithoutProcessors (/Users/josh/repos/eslint-plugin-react/node_modules/eslint/lib/linter/linter.js:1312:33)
      at Linter.verify (/Users/josh/repos/eslint-plugin-react/node_modules/eslint/lib/linter/linter.js:1454:57)
      at runRuleForItem (/Users/josh/repos/eslint-plugin-react/node_modules/eslint/lib/rule-tester/rule-tester.js:833:35)
      ...

This is because TypeScript is on an old version that doesn't support the default export:

"typescript": "^3.9.9",

I tried updating the devDependency to ^4.0.2 and then the error becamse:

TypeError: ts.getModifierFlags is not a function
      at Object.hasStaticModifierFlag (/Users/josh/repos/eslint-plugin-react/node_modules/typescript-estree/lib/node-utils.js:403:21)
      at convert (/Users/josh/repos/eslint-plugin-react/node_modules/typescript-estree/lib/convert.js:996:29)
      at convertChild (/Users/josh/repos/eslint-plugin-react/node_modules/typescript-estree/lib/convert.js:77:12)
      ...

...from the deprecated typescript-estree package. Which, along with typescript-eslint-parser, don't support the latest TypeScript versions. So they can't be used in environments that have typescript@4 (roughly - I haven't checked the exact range support).

"typescript-eslint-parser": "^20.1.1"

When I set const tsOld = false; in parsers.js, then all tests pass with typescript@4 and @typescript-eslint/*@6.

@ljharb I can vaguely guess the right solution is to change around when the typescript-eslint-parser tests should be run, but I'm not clear on what the exact change should be. Is this something you can do?

Copy link
Member

Choose a reason for hiding this comment

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

I'll take a look - basically, we do some hijinks in our CI to install the right version combinations of things so it'll work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: @typescript-eslint v6 throws deprecation warnings
6 participants