-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Bug: Created rules using RuleCreator
are not portable
#5032
Comments
As an aside - one thing I would suggest is disabling type def generation for your plugin. Nobody is going to be importing your plugin directly so giving it type defs is a waste of package size! |
Hmm, I don't reproduce this when I make a new scratch repo. But when I clone that emotion PR and run
I'm not very familiar with rollup. What's the
Good question. When we create an override rule such as
...except, looking through the codebase, none of the
...so, maybe we can get rid of the |
Probably can get rid of it. I doubt anyone does actually use it though! So probably safe to remove. It is technically a breaking change to remove it from the API, sadly. |
That doesn't have to be true - I can imagine people creating presets in a programmatic way and that would "require" type defs to be shipped with the plugin (or at least, it would be better if there would be a type def for a plugin). That being said - I don't have an easy way to opt-out from
It's hard to tell what's the exact
I'm in no rush here so that's fine - I just wanted to raise this as an issue. Do you think it's worth raising a PR for this now that would wait for your next major release? Or would you say that this is going to be problematic (merge-wise) and that it's better to wait with such a PR until you actually start working on the new major? |
Unless I'm misunderstanding - every reference to an ESLint plugin should be done via raw, untyped strings. The only case I know of where one might want to directly import a plugin is if you're "extending" a rule (like we do for the base ESLint rules) - in which case that's an advanced edge case I wouldn't ever ship types for!
😢 that sucks! In our repo we have one tsconfig per package, so we can (and have) disabled typedef generation for the plugin typescript-eslint/packages/eslint-plugin/tsconfig.build.json Lines 4 to 6 in 1f60fae
More than happy to take a PR now! The code in question rarely changes so it shouldn't be a problem! |
Then that is me not knowing how one actually creates presets in ESLint :P
Here you go :) |
Before You File a Bug Report Please Confirm You Have Done The Following...
Relevant Package
utils
Playground Link
No response
Repro Code
ESLint Config
No response
tsconfig
No response
Expected Result
A definition file for a library utilizing this util should be generated just fine.
Actual Result
We get an error like this one:
I've diagnosed this and the problem is that the final
RuleModule
contains a reference toTRuleListener
and its type contains references to types from another packages:typescript-eslint/packages/utils/src/eslint-utils/RuleCreator.ts
Line 95 in ed7b5f6
I've also figured out a workaround - we need to provide generic params explicitly, to disable the inference for the third generic param (
TRuleListener
) and just use its default. The workaround in practice can be checked out here: https://github.com/emotion-js/emotion/pull/2761/files/79848d3a5ff7fa5338d31a27fb94951ea15071faI wonder though... why the
TRuleListener
is a generic? Does it have to be referenced inRuleModule
? I would have assumed that a rule should be rather opaque to the consumer 🤔 (at least in relation to what kind of AST types does it process and stuff like that)cc @JoshuaKGoldberg, funny enough that I've stumbled upon this issue just after this recent conversation on Twitter: https://twitter.com/JoshuaKGoldberg/status/1526969335717191692 😅
Additional Info
No response
Versions
@typescript-eslint/utils
5.25.0
TypeScript
4.5.5
ESLint
^7.10.0
The text was updated successfully, but these errors were encountered: