TypeError:context.getScope 不是一个函数

症状

¥Symptoms

当将 ESLint v9.0.0 或更高版本与插件一起使用时,你可能会看到以下错误之一:

¥When using ESLint v9.0.0 or later with a plugin, you may see one of the following errors:

TypeError: context.getScope is not a function
TypeError: context.getAncestors is not a function
TypeError: context.markVariableAsUsed is not a function
TypeError: context.getDeclaredVariables is not a function

原因

¥Cause

ESLint v9.0.0 引入了插件规则使用的 规则 API 的更改,其中包括将一些方法从 context 对象移动到 sourceCode 对象。如果你看到这些错误之一,则意味着该插件尚未更新为使用新规则 API。

¥ESLint v9.0.0 introduces changes to the rules API that plugin rules use, which included moving some methods from the context object to the sourceCode object. If you’re seeing one of these errors, that means the plugin has not yet been updated to use the new rules API.

解析

¥Resolution

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

¥Common resolutions for this issue include:

资源

¥Resources

有关更多信息,请参阅:

¥For more information, see:

ESLint 中文网
粤ICP备13048890号