How can I configure ESLint to retry fixes without causing duplicate writes?
0 reputation · 14 Jan 2021, 16:58 UTC
When using ESLint to automatically apply fixes, a custom rule that transforms source code may be invoked multiple times during a retry loop. Each invocation writes the same transformed content back to the file, resulting in duplicate write operations that clutter the version‑control history and can cause unnecessary rebuilds. The desired outcome is for the fix process to be idempotent: after the first successful transformation, subsequent runs should detect that no further changes are needed and skip writing to disk. The rule must remain compatible with ESLint’s built‑in fix mechanism and should not depend on external caching tools. It is unclear whether ESLint already compares the original and fixed output before writing, or if the rule itself must perform that comparison.
Specific questions:
- Does ESLint’s fix mechanism automatically avoid writing when the fixed output matches the original?
- If not, what is the recommended pattern for a rule to compare the original and transformed code before issuing a write?
- Are there any existing configuration options that influence this write‑skip behavior?