fix(linter/plugins): ensure after hook is always called in ESLint compat mode#20721
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
0061f54 to
20abf3c
Compare
There was a problem hiding this comment.
Pull request overview
Improves ESLint compatibility for Oxlint createOnce plugins by ensuring after hooks are executed reliably (including after visitor/CFG errors) and only after all rules in the plugin finish traversing a file. Adds fixture-based coverage in both Oxlint and ESLint snapshot modes for multiple error scenarios and ordering guarantees.
Changes:
- Add plugin-wide
AfterHooksStatecoordination ineslintCompatPluginto run all pendingafterhooks after traversal and still clean up on errors. - Expand
eslintCompatfixture to verifyafterhooks run after all CFG events across multiple rules. - Add new fixtures validating
afterhook execution/order when errors occur inbefore, visitor functions, CFG handlers, andafter.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxlint/src-js/package/compat.ts | Implement plugin-wide after hook scheduling/reset logic for ESLint compat mode. |
| apps/oxlint/test/fixtures/eslintCompat/plugin.ts | Extend CFG-order fixture to include two CFG rules and assert cross-rule ordering. |
| apps/oxlint/test/fixtures/eslintCompat/output.snap.md | Update Oxlint snapshot output for added CFG rule. |
| apps/oxlint/test/fixtures/eslintCompat/eslint.snap.md | Update ESLint snapshot output for added CFG rule. |
| apps/oxlint/test/fixtures/eslintCompat/eslint.config.js | Enable new CFG rule in ESLint config. |
| apps/oxlint/test/fixtures/eslintCompat/.oxlintrc.json | Enable new CFG rule in Oxlint config. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/plugin.ts | New fixture plugin: throws in an AST visitor and logs hook order. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/output.snap.md | Oxlint snapshot for visitor-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/options.json | Fixture options enabling ESLint compat mode. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/files/1.js | Fixture input file. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/eslint.snap.md | ESLint snapshot for visitor-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/eslint.config.js | ESLint config for visitor-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_visit/.oxlintrc.json | Oxlint config for visitor-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/plugin.ts | New fixture plugin: throws in onCodePathEnd and logs hook order. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/output.snap.md | Oxlint snapshot for CFG handler-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/options.json | Fixture options enabling ESLint compat mode. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/files/1.js | Fixture input file. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/eslint.snap.md | ESLint snapshot for CFG handler-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/eslint.config.js | ESLint config for CFG handler-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_onCodePathEnd/.oxlintrc.json | Oxlint config for CFG handler-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/plugin.ts | New fixture plugin: throws in before and validates which after hooks run. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/output.snap.md | Oxlint snapshot for before-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/options.json | Fixture options enabling ESLint compat mode. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/files/1.js | Fixture input file. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/eslint.snap.md | ESLint snapshot for before-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/eslint.config.js | ESLint config for before-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_before/.oxlintrc.json | Oxlint config for before-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/plugin.ts | New fixture plugin: throws in after and ensures other after hooks still run. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/output.snap.md | Oxlint snapshot for after-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/options.json | Fixture options enabling ESLint compat mode. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/files/1.js | Fixture input file. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/eslint.snap.md | ESLint snapshot for after-throw scenario. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/eslint.config.js | ESLint config for after-throw fixture. |
| apps/oxlint/test/fixtures/eslintCompat_error_in_after/.oxlintrc.json | Oxlint config for after-throw fixture. |
20abf3c to
4d271fe
Compare
Merge activity
|
…ompat mode (#20721) In Oxlint, when using `createOnce` API, we ensure that `after` hooks are always called for all rules even in the event of a rule throwing an error during AST traversal. Uphold the same guarantee when a plugin using `createOnce` API runs in ESLint via `eslintCompatPlugin`, including in language server environments where the process lives on after an error is thrown. We now make sure that: 1. `after` hooks are always run even if an error occurs during AST visitation. 2. `after` hooks for all rules are always run after *all* the plugin's rules complete AST visitation (not just after each individual rule finishes AST visitation). These guarantees allow creating a reliable per-file cache shared between rules with a pattern like this: ```ts let cache: Data | null = null; let numRunningRules = 0; function setupCache(context) { if (cache === null) cache = new Data(context); numRunningRules++; } function teardownCache() { numRunningRules--; if (numRunningRules === 0) cache = null; } const rule1 = { createOnce(context) { return { before() { setupCache(context); }, Identifier(node) { // Use `cache` }, after() { teardownCache(); }, }; }, }; const rule2 = { // Same as above }; const rule3 = { // Same as above }; ``` We can build on this to create a dedicated API for the shared cache use case, and have it work reliably in ESLint as well as Oxlint. Related: #20700.
694fdb1 to
31145a9
Compare
4d271fe to
0aa1ff0
Compare
# Oxlint ### 💥 BREAKING CHANGES - c0ebbce linter: [**BREAKING**] Report error on unknown builtin rule (#20464) (camc314) ### 🚀 Features - 04f85e5 linter/no-unused-vars: Add safe-fix option for import fixes (#20839) (Marcell Toth) - 32a3706 linter/eslint-vitest-plugin: Implements `require-test-timeout` rule (#20806) (Said Atrahouch) - ae03653 linter: Implement suggestion for `eslint/no-useless-computed-key` rule (#20805) (Mikhail Baev) - 6624513 linter/prefer-string-starts-ends-with: Move rule from nursery to style (#20797) (camc314) - 58941f8 linter/prefer-readonly: Move rule from nursery to style (#20796) (camc314) - 8837ffd linter/prefer-regexp-exec: Move rule from nursery to style (#20795) (camc314) - 7e88871 linter/prefer-find: Move rule out of nursery (#20794) (camc314) - ca6e5bc linter/vitest: Implement prefer-called-exactly-once-with (#17562) (Said Atrahouch) - e80c0bf linter/eslint-plugin-vitest: Implement `require-mock-type-parameters` (#20785) (Said Atrahouch) - cec8b8f linter/vitest: Implement require-awaited-expect-poll rule (#20702) (Said Atrahouch) - d8e9d01 linter/eslint-plugin-vitest: Set `prefer-to-have-been-called-times` compatible with jest (#20703) (Said Atrahouch) - caf8231 linter: Enhance import plugin diagnostics with help messages (#20766) (离谱) - f44adfa linter: Improve the oxlint config generated by `--init`. (#20632) (connorshea) - 43f4827 linter: Add help text to jest and promise diagnostics (#20640) (kszongic) - 16516de linter: Enhance types for `DummyRule` (#20751) (camc314) - 27374e8 linter: Add hint about node version when ts config fail to import (#20570) (camc314) - 8e34150 linter/eslint-plugin-vitest: Sync rule with JS implementation (#20679) (Said Atrahouch) ### 🐛 Bug Fixes - df057d5 linter/no-noninteractive-tabindex: Add missing composite widget … (#20860) (bab) - bb34073 linter: Mark vitest/valid-title as a compatible jest rules (#20463) (Nicolas Le Cam) - bd2c76b linter: Handle shadowed locals in no-restricted-globals (#20811) (Ulrich Stark) - 62e39be linter: Sort nested object keys in fix of `eslint/sort-keys` in one pass (#20838) (Ulrich Stark) - 3ef37da oxlint/lsp: Error on unknown command (#20841) (Sysix) - ab1070d oxlint/cli: Skip parsing base config again for nested config search (#20809) (Sysix) - 2be3728 oxlint/lsp: Skip parsing base config again for nested config search (#20808) (Sysix) - 6171217 oxlint: Respect `NO_COLOR` env for `format=stylish` (#20804) (Sysix) - d89ae8f linter/plugins: Patch `WeakMap` to emulate `WeakMap`s keyed by `sourceCode` (#20799) (overlookmotel) - c610666 linter/no-shadow: Respect env settings when builtinGlobals is enabled (#20429) (vvnikita74) - 6bb502f linter/no-invalid-void-type: Allow void generic args in heritage clauses (#20780) (camc314) - 365bb7d linter: Skip typed nested literals in explicit-module-boundary-types (#20776) (camc314) - 0aa1ff0 linter/plugins: Ensure `after` hook is always called in ESLint compat mode (#20721) (overlookmotel) - 31145a9 linter/plugins: Fire `after` hook after CFG events in ESLint compat (#20720) (overlookmotel) - c09a5ab diagnostics: Skip minified fallback for single-line reporters (#20716) (camc314) - e4dc9a1 linter: Isolate `--init` config writes from parallel tests (#20717) (camc314) - 7e394ec linter: Clarify empty replacement fixer help text (#20698) (camc314) - d15a99c linter/jsx-curly-brace-presence: Flag empty string literals (#20690) (camc314) ### 📚 Documentation - c722495 linter: Update JS Plugins + LS references (#20843) (camc314) - e1f9748 linter/jsdoc/require-property: Fix typo (#20792) (Benjaming61001) - be3dcc1 linter: Add note about node version + custom TS plugin (#19381) (camc314) # Oxfmt ### 🚀 Features - 6ef440a oxfmt: Support bool for object style options (#20853) (leaysgur) - 23050fa oxfmt: Support markdown-in-js substitution (#20683) (leaysgur) - 4087295 oxfmt: Support angular-in-js substitution (#20676) (leaysgur)

In Oxlint, when using
createOnceAPI, we ensure thatafterhooks are always called for all rules even in the event of a rule throwing an error during AST traversal.Uphold the same guarantee when a plugin using
createOnceAPI runs in ESLint viaeslintCompatPlugin, including in language server environments where the process lives on after an error is thrown.We now make sure that:
afterhooks are always run even if an error occurs during AST visitation.afterhooks for all rules are always run after all the plugin's rules complete AST visitation (not just after each individual rule finishes AST visitation).These guarantees allow creating a reliable per-file cache shared between rules with a pattern like this:
We can build on this to create a dedicated API for the shared cache use case, and have it work reliably in ESLint as well as Oxlint. Related: #20700.