版本

TypeError:context.getScope 不是函式

症狀

當搭配外掛程式使用 ESLint v9.0.0 或更新版本時,您可能會看到以下錯誤之一

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

原因

ESLint v9.0.0 引入了 規則 API 的變更,外掛程式規則會使用這些變更,其中包括將一些方法從 context 物件移動到 sourceCode 物件。如果您看到這些錯誤之一,表示該外掛程式尚未更新以使用新的規則 API。

解決方案

此問題的常見解決方案包括

  • 將外掛程式升級到最新版本。
  • 使用相容性工具在您的設定檔中修補外掛程式。

資源

如需更多資訊,請參閱

變更語言