Skip to content

fix(ast-spec): replace attributes with options property in TSImportType#10691

Merged
JoshuaKGoldberg merged 14 commits intotypescript-eslint:mainfrom
fisker:TSImportType-options
Feb 24, 2025
Merged

fix(ast-spec): replace attributes with options property in TSImportType#10691
JoshuaKGoldberg merged 14 commits intotypescript-eslint:mainfrom
fisker:TSImportType-options

Conversation

@fisker
Copy link
Copy Markdown
Contributor

@fisker fisker commented Jan 21, 2025

PR Checklist

Overview

The AST should align with ImportExpression which contains .options with Property

#10640 (comment)

@typescript-eslint
Copy link
Copy Markdown
Contributor

Thanks for the PR, @fisker!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 21, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 9d8e54f
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/679255df297b75000854be45
😎 Deploy Preview https://deploy-preview-10691--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 93 (🔴 down 5 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 21, 2025

View your CI Pipeline Execution ↗ for commit 9d8e54f.

Command Status Duration Result
nx test eslint-plugin --coverage=false ✅ Succeeded 7m 37s View ↗
nx test eslint-plugin ✅ Succeeded 5m 59s View ↗
nx test typescript-estree --coverage=false ✅ Succeeded 1m 31s View ↗
nx test utils --coverage=false ✅ Succeeded 7s View ↗
nx test visitor-keys --coverage=false ✅ Succeeded 3s View ↗
nx run types:build ✅ Succeeded <1s View ↗
nx test type-utils --coverage=false ✅ Succeeded 22s View ↗
nx run-many --target=build --exclude website --... ✅ Succeeded 1m 16s View ↗
Additional runs (24) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-01-23 15:03:50 UTC

@fisker fisker marked this pull request as draft January 21, 2025 00:56
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.

Project coverage is 87.12%. Comparing base (79af426) to head (9d8e54f).
Report is 86 commits behind head on main.

Files with missing lines Patch % Lines
packages/typescript-estree/src/convert.ts 0.00% 10 Missing ⚠️

❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10691      +/-   ##
==========================================
- Coverage   87.17%   87.12%   -0.05%     
==========================================
  Files         448      450       +2     
  Lines       15598    15633      +35     
  Branches     4555     4566      +11     
==========================================
+ Hits        13597    13621      +24     
- Misses       1645     1655      +10     
- Partials      356      357       +1     
Flag Coverage Δ
unittest 87.12% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/visitor-keys/src/visitor-keys.ts 100.00% <ø> (ø)
packages/typescript-estree/src/convert.ts 28.55% <0.00%> (-0.33%) ⬇️

... and 7 files with indirect coverage changes

@fisker fisker changed the title Use TSImportType.options instead of TSImportType.attributes fix(ast-spec): Use TSImportType.options instead of TSImportType.attributes Jan 21, 2025
@fisker fisker changed the title fix(ast-spec): Use TSImportType.options instead of TSImportType.attributes fix(ast-spec): use TSImportType.options instead of TSImportType.attributes Jan 21, 2025
@fisker fisker changed the title fix(ast-spec): use TSImportType.options instead of TSImportType.attributes fix(ast-spec): use TSImportType.options instead of .attributes Jan 21, 2025
@fisker fisker changed the title fix(ast-spec): use TSImportType.options instead of .attributes fix(ast-spec): replace attributes with options property in TSImportType Jan 21, 2025
@fisker fisker marked this pull request as ready for review January 21, 2025 04:13
@JoshuaKGoldberg
Copy link
Copy Markdown
Member

@fisker can you say more, why should it use options and not `attributes?

@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Jan 21, 2025

  1. For values, in ImportDeclaration, with is a keyword, the attributes don't need location information for it, but in import("foo", {with: {type: "json"}}) (ImportExpression, not TSImportType) it already use ObjectExpression, so it contains the location information for the second "argument"(at least it looks like one), without location information of the open brace, it will be hard for Prettier and ESLint to use.
  2. In babel, with ts plugin, it already support TSImportType with .options which is an ObjectExpression

I'm fine to accept if you have a better AST shape to suggest, but I still hope it contains the location information of {, }, and with.

@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Jan 21, 2025

Since ImportExpression and TSImportType are exactly the same code, it will be much easier if they share same AST shape, I'd suggest rename .argument to .source in future.

Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Gotcha, thanks - this makes sense. I see why you'd want to align them to the options from ImportExpression.

Since we only just released support yesterday for this relatively-uncommon AST usage I think it's fine to treat this as a non-breaking-change fix.

cc @ronami as I might have (again) missed something.

ronami
ronami previously approved these changes Jan 21, 2025
Copy link
Copy Markdown
Member

@ronami ronami left a comment

Choose a reason for hiding this comment

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

Oh, I missed this one too, I didn't consider it not having the location information on the entire second "argument" 🙈

+1 from me to treat this as non-breaking; I didn't even know this was correct TypeScript syntax until a few days ago 😁


Some thoughts:

It seems TypeScript's AST uses ts.ImportAttributes over ts.Expression for this (see here), which is also used in ts.ImportDeclaration and ts.ExportDeclaration.

To my understanding, typescript-eslint's AST coverts these to ImportAttribute[] (e.g. 1, 2), so this would be the first time a ts.ImportAttributes node is converted into something other than ImportAttribute[].

Still, I think the change is correct, as the existing AST doesn't include location information for the second "argument", making it rather hard to use 👍

bradzacher
bradzacher previously approved these changes Jan 22, 2025
Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Noting #10649: is there more work to be done here?

@fisker fisker dismissed stale reviews from bradzacher, ronami, and JoshuaKGoldberg via 9d8e54f January 23, 2025 14:44
@fisker
Copy link
Copy Markdown
Contributor Author

fisker commented Jan 23, 2025

Updated vistorKeys.

Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

One question ~

Comment thread packages/visitor-keys/src/visitor-keys.ts
Copy link
Copy Markdown
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. I don't want to keep delaying on this - it's a good change and the longer we wait the more likely an issue will pop up. Merging now to get in today's release.

@JoshuaKGoldberg JoshuaKGoldberg merged commit 476c2c0 into typescript-eslint:main Feb 24, 2025
@fisker fisker deleted the TSImportType-options branch February 24, 2025 20:27
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants