美文网首页
ESLint-plugin-React 中文

ESLint-plugin-React 中文

作者: Maco_wang | 来源:发表于2019-04-09 17:52 被阅读0次

React specific linting rules for ESLint
用于React的ESLint规则

Installation

安装

Install ESLint either locally or globally.

可以全局或本地安装

$ npm install eslint --save-dev

If you installed ESLint globally, you have to install React plugin globally too. Otherwise, install it locally.
如果您全局安装ESLint,您不得不也全局安装React组件 ,否则就本地安装它。

$ npm install eslint-plugin-react --save-dev

Configuration

配置

Use our preset to get reasonable defaults:
使用我们的预先设置来获得合理的默认值:

  "extends": [
    "eslint:recommended",
    "plugin:react/recommended"
  ]

You should also specify settings that will be shared across all the plugin rules.
您还应该指定将在所有插件规则之间共享的设置。

{
  "settings": {
    "react": {
      "createClass": "createReactClass", // Regex for Component Factory to use, //使用组件工厂规则
                                         // default to "createReactClass" 
      "pragma": "React",  // Pragma to use, default to "React" 默认使用React语法
      "version": "detect", // React version. "detect" automatically picks the version you have installed. React版本,自动检索你安装的版本
                           // You can also use `16.0`, `16.3`, etc, if you want to override the detected value. 如果你想重写检索值,你也可以使用16.0,16.3等值。
      "flowVersion": "0.53" // Flow version  //流程版本
    },
    "propWrapperFunctions": [
        // The names of any function used to wrap propTypes, e.g. `forbidExtraProps`. If this isn't set, any propTypes wrapped in a function will be skipped. 任何函数名常常用于包裹propTypes,例如"forbidExtraProps",如果没有被设置,任何被函数包裹的propType将被忽略。
        "forbidExtraProps",
        {"property": "freeze", "object": "Object"},
        {"property": "myFavoriteWrapper"}
    ]
  }
}

If you do not use a preset you will need to specify individual rules and add extra configuration.
如果你没有使用预先设置,你就需要指定独有规则,并且添加额外的配置。

Add "react" to the plugins section.
添加"react"到插件部分

{
  "plugins": [
    "react"
  ]
}

Enable JSX support.
支持JSX语法
With ESLint 2+
在 ESLint 2+

{
  "parserOptions": {
    "ecmaFeatures": 
      "jsx": true
    }
  }
}

Enable the rules that you would like to use.
启用你想使用的规则

  "rules": {
    "react/jsx-uses-react": "error",
    "react/jsx-uses-vars": "error",
  }

List of supported rules

规则列表

JSX-specific rules

Other useful plugins

其他有用的插件

Shareable configurations

共用配置

Recommended

推荐

This plugin exports a recommended configuration that enforces React good practices.
该插件导出一个推荐的配置以实现更好的业务
To enable this configuration use the extends property in your .eslintrc config file:
在.eslintrc配置文件内使用extends 属性可以开启他

{
  "extends": ["eslint:recommended", "plugin:react/recommended"]
}

See ESLint documentation for more information about extending configuration files.
查阅ESLint Document 以获取更多关于扩展配置文件的信息。
The rules enabled in this configuration are:
该配置文件可使用的规则如下

All

This plugin also exports an all configuration that includes every available rule. This pairs well with the eslint:all rule.
该插件同样的导出一个囊括每一个可使用的规则,这与'eslint:all`规则很匹配

{
  "plugins": [
    "react"
  ],
  "extends": ["eslint:all", "plugin:react/all"]
}

Note: These configurations will import eslint-plugin-react and enable JSX in parser options.
备注:这些配置将导入'eslint-plugin-react' 并在解析器中启用JSX

License

ESLint-plugin-React is licensed under the MIT License.

相关文章

网友评论

      本文标题:ESLint-plugin-React 中文

      本文链接:https://www.haomeiwen.com/subject/gqebiqtx.html