How to Stop GitHub Copilot From Triggering ESLint Auto-Fix Loops
🔍 WiseChecker

How to Stop GitHub Copilot From Triggering ESLint Auto-Fix Loops

GitHub Copilot generates code suggestions that sometimes violate your ESLint rules. When you save the file, ESLint auto-fix changes the code. Copilot then suggests the original style again, creating an endless loop. This article explains why these loops occur and provides exact settings to stop them.

The root cause is a mismatch between Copilot’s suggestion style and your ESLint configuration. Copilot learns from public code, which may not follow your project’s rules. ESLint auto-fix on save reverts Copilot’s output, but Copilot does not learn from those corrections in real time.

You will learn to disable ESLint auto-fix for Copilot-generated lines, configure Copilot to respect your project’s ESLint rules, and use editor settings to break the loop permanently.

Key Takeaways: Stop Copilot-ESLint Auto-Fix Loops

  • VS Code settings.json > “editor.codeActionsOnSave”: Disable ESLint auto-fix for specific file types or scopes to stop the loop.
  • Copilot settings > “github.copilot.editor.enableAutoCompletions”: Toggle completions off temporarily while you save and fix a file.
  • ESLint configuration > .eslintrc.json > “rules”: Add a rule override for Copilot-generated code patterns to prevent the conflict.

ADVERTISEMENT

Why Copilot and ESLint Create an Auto-Fix Loop

GitHub Copilot suggests code based on patterns in public repositories. These patterns often use single quotes, two-space indentation, or trailing commas that differ from your ESLint configuration. When you save the file, your editor runs ESLint auto-fix, which reformats the code to match your rules. Copilot then sees the fixed code as context and suggests the original style again on the next line or edit.

This loop repeats every time you save. The loop is not a bug in Copilot or ESLint. It is a conflict between two tools with different reference points. Copilot references public code patterns. ESLint references your project rules. Neither tool adjusts its behavior based on the other’s output during a single editing session.

The most common triggers are formatting rules such as quotes, indent, comma-dangle, and semi. If your ESLint config enforces double quotes and Copilot suggests single quotes, the loop starts. The same happens with trailing commas or semicolons.

Steps to Break the Auto-Fix Loop

Method 1: Disable ESLint Auto-Fix on Save for Copilot-Affected Files

  1. Open VS Code settings.json
    Press Ctrl+Shift+P, type “Preferences: Open Settings (JSON)”, and press Enter.
  2. Locate the editor.codeActionsOnSave setting
    Find or add the line "editor.codeActionsOnSave": { "source.fixAll.eslint": true }.
  3. Disable ESLint auto-fix for specific file types
    Change the setting to "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" } and add a file scope. For JavaScript files only, use:
    "[javascript]": { "editor.codeActionsOnSave": { "source.fixAll.eslint": false } }
    This keeps auto-fix for other languages but stops it for JavaScript files where Copilot triggers the loop.
  4. Save settings.json
    Press Ctrl+S to save. The loop should stop immediately.

Method 2: Disable Copilot Completions Temporarily

  1. Open the Copilot status menu
    Click the Copilot icon in the VS Code status bar at the bottom right.
  2. Disable completions
    Select “Disable Completions” from the menu. Copilot will stop suggesting code while you save and fix the current file.
  3. Save and fix the file
    Press Ctrl+S to save. ESLint auto-fix runs once and stops because Copilot is not generating new suggestions.
  4. Re-enable completions
    Click the Copilot icon again and select “Enable Completions”. The loop should not resume because the file now matches ESLint rules.

Method 3: Configure Copilot to Respect ESLint Rules

  1. Add a .github/copilot-instructions.md file
    Create this file in your repository root. Write instructions such as:
    Always use double quotes.
    Never use trailing commas.
    Indent with two spaces.
    Copilot reads this file and adjusts its suggestions for your project.
  2. Restart VS Code
    Close and reopen VS Code. Copilot reloads the instructions.
  3. Test with a new line
    Type a few lines of code and accept a Copilot suggestion. Save the file. The loop should not occur because Copilot now matches your ESLint rules.

Method 4: Override ESLint Rules for Copilot-Generated Code

  1. Open your .eslintrc.json file
    This file is in your project root. If it does not exist, create it with a basic configuration.
  2. Add a rule override for the problematic rule
    For example, to allow single quotes in Copilot-generated code without triggering auto-fix, add:
    "rules": { "quotes": ["warn", "single"] }
    Changing from “error” to “warn” prevents auto-fix from running on that rule. ESLint still highlights the issue but does not change the code.
  3. Save .eslintrc.json
    Press Ctrl+S. The loop stops because ESLint no longer auto-fixes the quotes rule.

ADVERTISEMENT

If Copilot Still Triggers an Auto-Fix Loop After These Fixes

Copilot suggests code that ESLint auto-fixes to a different style on the same line

This happens when Copilot completes a line with a semicolon and your ESLint rule enforces no semicolons. ESLint removes the semicolon on save. Copilot then sees the line without a semicolon and suggests adding one again. To fix this, add a .github/copilot-instructions.md file with the instruction Never use semicolons. This tells Copilot to match your style from the start.

ESLint auto-fix runs on every keystroke, not only on save

Some editors run ESLint auto-fix in real time as you type. This can create a loop even before you save. To stop this, open VS Code settings and set "eslint.run": "onSave". This restricts ESLint to run only when you save the file, not during typing.

Copilot continues to suggest the old style after you fix the file

Copilot’s context window may still reference the unfixed lines. Close the file and reopen it. Copilot rebuilds its context from the current file content, which now matches ESLint rules. The loop should not return.

Item Disable ESLint Auto-Fix on Save Disable Copilot Completions Temporarily
Effect on loop Stops auto-fix from running, so Copilot suggestions are never reverted Stops Copilot from generating new suggestions while you fix the file
Persistence Permanent for the configured file types Temporary until you re-enable completions
Setup time 30 seconds 5 seconds
Best for Projects with strict ESLint rules and frequent Copilot use Quick fixes when the loop is blocking your work

You can now stop the auto-fix loop by disabling ESLint auto-fix on save for specific file types, disabling Copilot completions temporarily, or configuring Copilot to respect your ESLint rules. For persistent issues, add a .github/copilot-instructions.md file with your style preferences. Try combining the permanent settings change with the instruction file for the most reliable result. An advanced tip: use the "eslint.run": "onSave" setting together with "editor.codeActionsOnSave": { "source.fixAll.eslint": "explicit" } to keep auto-fix available but under your control.

ADVERTISEMENT