As I mentioned in the comments, this can be achieved by using the no-shadow
rule. By default, the rule does not check the built-in types (e.g. window
, Node
or Attr
), but it can be configured to do so by setting the option builtinGlobals
to true, like this:
no-shadow: ["error", { "builtinGlobals": true }]
This now tells ESLint to check if any variables shadows any name that is available in the global scope - but you have to configure which ones are actually available, since ESLint does not know that by itself. You can do that by setting the correct environments through the env
configuration:
"env": {
"browser": true
}
I configured a small example in the ESLint Playground Demo to showcase this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…