javascript - 禁止隐式访问窗口属性

标签 javascript eslint

我正在寻找一个 ESLint 规则,该规则不允许使用 location 等用法,而只允许 window.location。我查遍了规则,但没有找到,有人知道吗?

最佳答案

no-restricted-globals规则将帮助您。

将其添加到您的 .eslintrc 文件

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

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

关于javascript - 禁止隐式访问窗口属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65388965/

相关文章:

javascript - 在编辑对话框表单中禁用 JQGrid 下拉列表

javascript - 类型错误 : Cannot read property 'map' of undefined in my app

javascript - 如何在 mvc View 中将 Razor 值传递给 jquery 函数

javascript - react.js 中的 Eslint arrow-body-style 错误

javascript - 编写 ESLint 规则,如何通过标识符查找导出类?

javascript - 以异步方式发送网格邮件

vue.js - 带有 Eslint 的 Vite.js 上的 Vue 3 — 无法解析模块 eslint 的路径(import/no-unresolved)

Javascript Lint 错误

javascript - react native 和 Webpack : Confusing when ESLint detects errors

javascript - 将变量值从 if 语句传递到 if/else 之外