检测到循环修复……

症状

¥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:

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

    ¥Remove or reconfigure one of the conflicting rules in your configuration file.

如何查找冲突的规则:

¥How to find the conflicting rules:

  1. 在支持应用单独修复的编辑器(例如 VS Code)中打开警告中指定的文件。

    ¥Open the file specified in the warning in an editor that supports applying individual fixes (for example, VS Code).

  2. 在 lint 问题列表中,找到可修复的规则。这是冲突规则之一。

    ¥In the list of lint problems, find a fixable rule. That is one of the conflicting rules.

  3. 应用修复(VS Code 中的 “修复此 (规则名称) 问题” 操作)。

    ¥Apply the fix (“Fix this (rule-name) problem” action in VS Code).

  4. 检查列表中出现了哪些新的 lint 问题。这是另一条冲突规则。

    ¥Check what new lint problem has appeared in the list. That is the other conflicting rule.

资源

¥Resources

有关更多信息,请参阅:

¥For more information, see: