-
Notifications
You must be signed in to change notification settings - Fork 22
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
markVariableAsUsed
for the customElement
decorator
#195
Comments
markVariableAsUsed
for the customElement
decorator
you're probably right that we should just mark CEs as used when passed through the customElement decorator since it is lit-specific knowledge/side-effects, it seems to make sense we tackle it i'll take a look unless you want to have a stab at it |
Unfortunately, I won't have time to handle this at the moment. I've temporarily shifted away from the project where I'm using Lit. However, I don't like the fact that I'm currently using the |
i had a think about this, its a bit of an awkward one for us to solve basically, multiple rules work against lit classes conditionally (i.e. it doesn't seem to belong anywhere sensible. maybe we just need to look at some examples elsewhere in the wild 🤔 im guessing other plugins just published their own version of no-unused-vars that overrides the original or something |
I have one example. This is a no-undefined-types rule in the eslint-plugin-jsdoc package. Here is the source code for this rule https://github.com/gajus/eslint-plugin-jsdoc/blob/main/src/rules/noUndefinedTypes.js |
that makes sense in their case as they have a rule for detecting those types we don't really have a rule whose purpose is to detect registered custom elements, so there doesn't seem to be anywhere sensible to mark these variables 🤔 in the jsdoc plugin it works because they explicitly have a rule detecting those types. we don't explicitly have a rule for detecting element definitions |
It seems that eslint-plugin-lit should have a similar rule to mark classes to which the |
the only reason the jsdoc plugin has a sensible place for it is because they have a rule specifically for detecting type references in JSDoc comments. they then mark them as used, makes sense. meanwhile, in lit, we don't have a rule for detecting custom element references. so we don't have anywhere sensible to mark them as used in the plugin right now there is no sensible place to do this logic. if we had a rule which detected element definitions, what would it be detecting them for? see what i mean? we'd be making a no-op rule for the sole purpose of marking these classes as used (but it actually wouldn't lint anything) hope im making sense, this isn't easy to explain |
Hey @43081j I understand you, and it seems that indeed, if we add a new rule, it will simply mark classes as used, and nothing more. The authors of typescript-eslint themselves suggest creating this rule in this comment. But I also agree with you. It's just not entirely clear how to solve this problem then. |
Ah interesting, you can see the react plugin went exactly that route: a no-op rule that exists solely to mark some vars as used I'll have a think about it this week, we may be able to do similar. A new rule like "custom-elements-uses-vars" |
Has there been any progress on this issue? So far I have disabled the no unused vars rule in our eslint config, but this is not ideal |
none yet as I have had an extremely busy month of travelling i'd be happy to help guide someone to contribute this though |
Hello! Thank you for such a cool plugin!
There is currently an issue where if you use a custom component declaration through the
customElement
decorator on a class, ESLint with theno-unused-vars
rule will complain that the class is not used, even though it is actually being used. This can be circumvented by declaring the custom component through thecustomElements.define
function, but this is a workaround. Of course, it is preferable to use decorators.In the typescript-eslint repository, you can find the following comment:
It seems reasonable to agree with it that frameworks should handle this themselves.
Another example is when I had to work with the ESLint plugin eslint-plugin-jsdoc, which exhibits similar behavior. By default, ESLint complains if you only use a type in comments, as it does not mark such values as
markVariableAsUsed
. To fix this, the eslint-plugin-jsdoc team created their own rule called no-undefined-types, which marks all values as used that are only used in comments viamarkVariableAsUsed
.I feel like something similar should emerge in eslint-plugin-lit. Or maybe I haven't found a better way to fix it. I'd be glad to hear any of your thoughts.
The text was updated successfully, but these errors were encountered: