禁止隐式访问 window 属性

Disallow implicit accessing of window properties

我正在寻找一个 ESLint 规则,它不允许像 location 这样的用法,只允许 window.location。规则我都梳理过了,没找到,有谁知道吗?

no-restricted-globals 规则将帮助您解决这个问题。

将此添加到您的 .eslintrc 文件

"no-restricted-globals" : [
    "error",
    "location",
    "history",
]

因此在上面的示例中,如果您使用 window.locationwindow.history,eslint 不会抛出错误。您可以向列表中添加更多 window 个属性。