Index

检测到循环修复……

症状

🌐 Symptoms

在使用 --fix 选项运行 ESLint 时,你可能会看到以下警告:

🌐 When running ESLint with the --fix option, you may see the following warning:

ESLintCircularFixesWarning: Circular fixes detected while fixing path/to/file. It is likely that you have conflicting rules in your configuration.

原因

🌐 Cause

你的配置中存在相互冲突的可修复规则。ESLint 会对代码进行多轮自动修复,这意味着某一轮的修复可能会在后续轮次中被撤销。例如,在第一轮中,一个规则移除了末尾的逗号,而在接下来的轮次中,另一个规则又在同一位置添加了末尾逗号,实际上将代码改回了之前的版本。当 ESLint 检测到这样的循环时,会发出警告。

🌐 You have conflicting fixable rules in your configuration. ESLint autofixes code in multiple passes, meaning it’s possible that a fix in one pass is undone in a subsequent pass. For example, in the first pass a rule removes a trailing comma and in the following pass a different rule adds a trailing comma in the same place, effectively changing the code back to the previous version. ESLint emits a warning when it detects cycles like this.

解析

🌐 Resolution

此问题的常见解决方案包括:

🌐 Common resolutions for this issue include:

  • 删除或重新配置配置文件中的冲突规则之一。

如何查找冲突的规则:

🌐 How to find the conflicting rules:

  1. 在支持应用单独修复的编辑器(例如 VS Code)中打开警告中指定的文件。
  2. 在 lint 问题列表中,找到一个可修复的规则。那就是其中一个冲突的规则。
  3. 应用修复(在 VS Code 中使用“修复此(规则名称)问题”操作)。
  4. 检查列表中出现了什么新的 lint 问题。那就是另一个冲突的规则。

资源

🌐 Resources

有关更多信息,请参阅:

🌐 For more information, see: