简体   繁体   English

Eslint不允许内置的全局函数?

[英]Eslint disallow a built-in global function?

Is there a rule to disable specific built-in JS functions? 是否有禁用特定内置JS功能的规则? Eg I want to disable parseFloat because there's almost never cases where parseFloat is better than unary + . 例如,我想禁用parseFloat因为几乎在任何情况下parseFloat都不比一元+

You can use no-restricted-globals : 您可以使用no-restricted-globals

Disallowing usage of specific global variables can be useful if you want to allow a set of global variables by enabling an environment, but still want to disallow some of those. 如果要通过启用环境来允许一组全局变量,但仍然要禁止其中的某些全局变量,则禁止使用特定的全局变量可能很有用。

This rule allows you to specify global variable names that you don't want to use in your application. 该规则允许您指定不想在应用程序中使用的全局变量名称。

Example: 例:

{
  "rules": {
    "no-restricted-globals": ["parseFloat"]
  }
}

Or, for a more descriptive warning: 或者,对于更具描述性的警告:

{
  "rules": {
    "no-restricted-globals": [
      "error",
      {
        "name": "parseFloat",
        "message": "Use + instead."
      }
    ]
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM