-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
feat: support explicit resource management in core rules #19828
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
feat: support explicit resource management in core rules #19828
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
I think yes, but we don't need to update/fix all rules in one PR. For manageability reasons, it might be good to limit the scope of this PR to the rules already included in it, and discuss the rest on the original issue. |
989b7c3
to
6913dd3
Compare
Rebased on main to use the updated espree parser. So this is ready to be reviewed. |
I think we should at least add examples with |
lib/rules/no-unused-vars.js
Outdated
|
||
return ( | ||
definition?.type === "Variable" && | ||
definition.parent.type === "VariableDeclaration" && |
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.
definition.parent.type === "VariableDeclaration" && |
I think this is redundant since the parent has to be VariableDeclaration
when the definition is of Variable
type.
https://eslint.org/docs/latest/extend/scope-manager-interface#parent
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.
Unfortunately svelte-eslint-parser also creates a variable of type Variable
but with a node.parent of SvelteConstTag
for
{@const value = 0}
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.
But this syntax is not for JavaScript files and out of scope for this rule. If someone is using svelte-eslint-parser they should use svelte specific rules.
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.
I think it depends on what the current behavior is. If the rule works with the Svelte parser now, it should continue to do so.
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.
In this case it is unnecessary so I removed it, as we only check the parents kind
property which would be undefined in the case of the svelte const tag.
I probably added it without proper thought as a safety as the svelte case surprised in the past.
Regarding the check of |
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.
LGTM, thanks! Leaving open for others to verify their review suggestions.
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.
LGTM, thanks! Amazing job!
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.
Looks great, thank you ❤️
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain: Support new syntax
What changes did you make? (Give an overview)
This PR adds preliminary support for the explicit resource management proposal which will likely be included in ES2026 (refs #19792).
Most of the changes are additional tests for existing rules except the following behavior changes:
curly
: allows using/await using as only statement as otherwise parser error (same as forlet/const
)no-unused-vars
: counts the variables as used as theirSymbol.dispose
is implicitly called at the end of its scopeprefer-destructuring
: allows not destructuring as this would be a parse errorrequire-await
+no-await-in-loop
: countsawait using
as an awaitNotes:
func-*
orno-magic-numbers
as they would be runtime errors (have noSymbol.dispose
)let/const
(e.g.block-scoped-var
)no-undef-init
: does not need to be updated as it is a parse error for initializing to undefined in this caseno-case-declarations
: does not need to be updated as it is a syntax errorIs there anything you'd like reviewers to focus on?
no-loop-func
@types/estree
)one-var
as it normalizes the options only to the prior knownvar/let/const
(in other wordsusing
andawait using
are just ignored)no-unassigned-vars
+init-declarations
: Have a special condition forconst
even though it is a parse error to omit the initial value. Shouldusing
andawait using
be included?require-await
+no-await-in-loop
: Should the rule documentation explicitly mentionawait using
?