ESLint custom rule execution blocking the main event loop
0 reputation · 17 Apr 2025, 03:55 UTC
ESLint rules utilize a synchronous visitor pattern to traverse the AST. When implementing complex static analysis logic within a custom rule, the execution remains on the main event loop, as the engine does not natively support asynchronous visitors or await promises returned by rule functions.
For large-scale codebases or rules requiring heavy computational processing, this synchronous design can lead to significant performance degradation during the linting process. There is currently no built-in mechanism to implement timeouts or cancellation tokens for individual rules to prevent a single rule from hanging the entire process.
Technical Constraints
- Rule visitors must be synchronous.
- The
context.report()method signals issues without interrupting traversal. - Heavy logic blocks the event loop until the visitor completes.
What are the recommended patterns for managing high-complexity logic in custom rules to avoid blocking the event loop? Is there a documented way to implement a timeout for a specific rule's execution within the ESLint engine?