Skip to content

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

Merged
merged 25 commits into from
Jul 17, 2025

Conversation

DMartens
Copy link
Contributor

@DMartens DMartens commented Jun 6, 2025

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 for let/const)
  • no-unused-vars: counts the variables as used as their Symbol.dispose is implicitly called at the end of its scope
  • prefer-destructuring: allows not destructuring as this would be a parse error
  • require-await + no-await-in-loop: counts await using as an await

Notes:

  • Did not update func-* or no-magic-numbers as they would be runtime errors (have no Symbol.dispose)
  • Added no tests if there were non for especially 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 case
  • no-case-declarations: does not need to be updated as it is a syntax error

Is there anything you'd like reviewers to focus on?

  • There were open questions in the original issue, e.g. for the behavior of no-loop-func
  • How should updates to the types be handled (some reference @types/estree)
  • Should options be added for the frozen one-var as it normalizes the options only to the prior known var/let/const (in other words using and await using are just ignored)
  • no-unassigned-vars + init-declarations: Have a special condition for const even though it is a parse error to omit the initial value. Should using and await using be included?
  • require-await + no-await-in-loop: Should the rule documentation explicitly mention await using?

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 6, 2025
Copy link

netlify bot commented Jun 6, 2025

Deploy Preview for docs-eslint canceled.

Name Link
🔨 Latest commit 49bbb85
🔍 Latest deploy log https://app.netlify.com/projects/docs-eslint/deploys/6876c7ca34944a0008e3911a

@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Jun 6, 2025
@github-actions github-actions bot added the rule Relates to ESLint's core rules label Jun 6, 2025
@mdjermanovic
Copy link
Member

  • Should options be added for the frozen one-var as it normalizes the options only to the prior known var/let/const (in other words using and await using are just ignored)

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.

@nzakas nzakas moved this from Needs Triage to Implementing in Triage Jun 10, 2025
@DMartens DMartens force-pushed the support-explicit-resource-management branch from 989b7c3 to 6913dd3 Compare June 13, 2025 08:08
@DMartens DMartens marked this pull request as ready for review June 13, 2025 08:08
@DMartens DMartens requested a review from a team as a code owner June 13, 2025 08:08
@DMartens
Copy link
Contributor Author

Rebased on main to use the updated espree parser. So this is ready to be reviewed.

@lumirlumir lumirlumir added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 17, 2025
@mdjermanovic
Copy link
Member

  • require-await + no-await-in-loop: Should the rule documentation explicitly mention await using?

I think we should at least add examples with await using.

@aladdin-add aladdin-add self-requested a review June 30, 2025 07:39

return (
definition?.type === "Variable" &&
definition.parent.type === "VariableDeclaration" &&
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Contributor Author

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}

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@DMartens
Copy link
Contributor Author

DMartens commented Jul 1, 2025

Regarding the check of declaration.kind === "const" in no-unassigned-vars:
I checked the git blame and this check was part of the original rule introduction in #19618.
I also think this check is unnecessary, should the removal be part of this PR?

mdjermanovic
mdjermanovic previously approved these changes Jul 15, 2025
Copy link
Member

@mdjermanovic mdjermanovic 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! Leaving open for others to verify their review suggestions.

snitin315
snitin315 previously approved these changes Jul 15, 2025
Copy link
Contributor

@snitin315 snitin315 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! Amazing job!

@DMartens DMartens dismissed stale reviews from snitin315 and mdjermanovic via 49bbb85 July 15, 2025 21:27
Copy link
Contributor

@snitin315 snitin315 left a 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 ❤️

@snitin315 snitin315 merged commit 1245000 into eslint:main Jul 17, 2025
31 checks passed
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion contributor pool feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

5 participants