@1o1w1/confusing-browser-globals 中文文档教程
confusing-browser-globals
浏览器全局变量的精选列表,这些变量通常会引起混淆,不建议在没有显式 window.
限定符的情况下使用。
Motivation
浏览器中的一些全局变量很可能被人们无意中用作全局变量,例如status
、name
、event
、等等
例如:
handleClick() { // missing `event` argument
this.setState({
text: event.target.value // uses the `event` global: oops!
});
}
这个包导出了一个经常被错误使用的全局列表。 您可以将此列表提供给 ESLint 等静态分析工具,以防止在没有显式 window.
限定符的情况下使用它们。
Installation
npm install --save confusing-browser-globals
Usage
如果您使用 Create React App,则无需配置任何内容,因为此规则已包含在默认的 eslint-config-react-app
预设中。
如果你维护自己的 ESLint 配置,你可以这样做:
var restrictedGlobals = require('confusing-browser-globals');
module.exports = {
rules: {
'no-restricted-globals': ['error'].concat(restrictedGlobals),
},
};
License
MIT
confusing-browser-globals
A curated list of browser globals that commonly cause confusion and are not recommended to use without an explicit window.
qualifier.
Motivation
Some global variables in browser are likely to be used by people without the intent of using them as globals, such as status
, name
, event
, etc.
For example:
handleClick() { // missing `event` argument
this.setState({
text: event.target.value // uses the `event` global: oops!
});
}
This package exports a list of globals that are often used by mistake. You can feed this list to a static analysis tool like ESLint to prevent their usage without an explicit window.
qualifier.
Installation
npm install --save confusing-browser-globals
Usage
If you use Create React App, you don't need to configure anything, as this rule is already included in the default eslint-config-react-app
preset.
If you maintain your own ESLint configuration, you can do this:
var restrictedGlobals = require('confusing-browser-globals');
module.exports = {
rules: {
'no-restricted-globals': ['error'].concat(restrictedGlobals),
},
};
License
MIT