-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [consistent-type-imports] ignore files with decorators, experimentalDecorators, and emitDecoratorMetadata #8335
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
Conversation
Thanks for the PR, @bradzacher! 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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
…rators, experimentalDecorators, and emitDecoratorMetadata
f3525d4
to
1c1f9f4
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8335 +/- ##
==========================================
+ Coverage 87.38% 87.98% +0.59%
==========================================
Files 254 404 +150
Lines 12489 14045 +1556
Branches 3919 4110 +191
==========================================
+ Hits 10914 12358 +1444
- Misses 1304 1382 +78
- Partials 271 305 +34
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice solution, +1 from me on the direction!
Requesting changes mainly on extracting the deeper explanations out of the rule file and into a blog post. Also for at least resolving the breaking change discussion.
But the rule's new implementation looks great to me (thanks for the whitespace suggestion!). ✨
@bradzacher Thanks for building this solution! I'm eagerly awaiting it being merged so I can use it in my project where I've been forced to just turn this rule off entirely for the moment. Also hi @JoshuaKGoldberg! Always fun to see your name pop up. Thanks for fighting the good fight and keeping high-quality open source software available! 😄 |
Haha hey @ZackMFleischman, great to see you pop up too! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! I'm super happy with the implementation, and think I understand this much better now thanks to the docs & comments. Thanks!
Left some proofreading thoughts on the blog post. That's the only real blocker from me - and there's nothing I likely can't be convinced otherwise on.
🔥
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Outdated
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Outdated
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Outdated
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Outdated
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Outdated
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Outdated
Show resolved
Hide resolved
packages/website/blog/2024-03-25-changes-to-consistent-type-imports-with-decorators.md
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoop, this is great - useful userland fixing and really solid explanations @bradzacher! 👏
|
||
<!-- prettier-ignore --> | ||
```ts | ||
var _a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this isn't used later.
var _a; |
If TypeScript is producing an _a
despite never using it, then that's a bug we can ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nah it was there cos the code has no types so this is an extra case I (purposely) didn't mention. In this case when TS can't determine the type but it can see its a value-import - instead TS emits [typeof _a = (typeof Foo !== "undefined" && Foo) === "function" ? _a : Object]
. Which is some funky code-golf heh.
Can remove it though yeah as it's not necessary for the examples I'm mentioning.
…rators, experimentalDecorators, and emitDecoratorMetadata (typescript-eslint#8335)
…rators, experimentalDecorators, and emitDecoratorMetadata (typescript-eslint#8335)
PR Checklist
Overview
Note: I've labelled this as a
feat
on purpose to mark it for a minor bump. It's technically a "bug fix" but it's also a change in behaviour. One might classify it as a breaking change because a specific usecase will require a config change - but given that usecases is also already broken, I didn't think that it truly qualified as breaking.This PR implements a sledge-hammer approach to fixing the problem in #5468 - I have opted to just completely ignore a file if it passes all three of the following conditions:
experimentalDecorators: true
emitDecoratorMetadata: true
Originally in #5468 I suggested going with the the approach of specifically ignoring imports that are used in locations that might be passed to decorator metadata. However I ultimately chose not to go down this path because:
experimentalDecorators
is considered legacyverbatimModuleSyntax
exists for the above usecaseexperimentalDecorators
This PR:
scope-manager
experimentalDecorators
parser option that is auto-populated from type info if availableexperimentalDecorators
andemitDecoratorMetadata
on the parser servicesconsistent-type-imports
:NOTE:: I strongly suggest turning on the no-whitespace diff when reviewing this PR.