$ show antfu/eslint-plugin-format
This is an ESLint plugin that provides three formatting rules (`format/prettier`, `format/dprint`, `format/oxfmt`) to format code using Prettier, dprint, and oxfmt respectively. It is designed to be used with ESLint's flat config and treats formatters as side-effects-free tools, giving users full control over which formatter to apply to which file types. The plugin uses `synckit` to run formatters synchronously in worker threads, and `eslint-formatting-reporter` to generate fix suggestions. The architecture is clean: each rule is a standard ESLint rule that lazily loads a synchronous wrapper around the actual formatter library. The codebase is well-structured, with comprehensive tests and CI. It is actively maintained and uses modern JavaScript/TypeScript practices.
The LLM identified 2 files worth highlighting for reuse:
Implements the `format/dprint` ESLint rule. It lazily initializes a synchronous function via `synckit` that calls the dprint formatter worker. The rule uses `eslint-formatting-reporter` to compare original and formatted code and report differences as lint errors with auto-fix. It handles errors gracefully and supports both simple language-based and plugin-based dprint configurations. This pattern is reusable for any ESLint rule that needs to invoke an external formatter synchronously.
A worker script that runs dprint formatting in a separate thread via `synckit`. It implements caching of loaded WASM buffers for dprint plugins and a context cache for plugin combinations. It handles loading from npm packages, file paths, data URIs, and URLs. This demonstrates a robust pattern for running WASM-based formatters in a worker with caching, which could be adapted for other WASM tools.