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。
解決方案
此問題的常見解決方案包括
- 將外掛升級到最新版本
- 使用相容性工具在您的設定檔中修補外掛
資源
如需更多資訊,請參閱