ESLint-plugin-React 中文

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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 从篆书《峄山刻石》写到隶书《张迁碑》,愈发喜欢起来。张迁碑古拙而又呆萌。
    筑墨为城阅读 529评论 0 0
  • 望着湛蓝的天空白云飘摇 雨过后风吹来空气丝丝的甜 草是翠色欲流 菜花黄得流金 阳光遍洒 花草树木迎风探头 春姑娘暗...
    祈祷无忧阅读 432评论 0 1
  • 身体,今天更好些了。下午陪女儿睡了2个多小时,精神焕发。晚上陪儿子去看巜摔跤吧!爸爸》。忙碌半年,电影都没看。这部...
    王悦yue阅读 98评论 0 3
  • 英国作为世界上现代化最早的一批国家,现在也陷入了国民数学水平低下的问题。而数学水平的低下直接导致社会运行成本的大幅...
    浪上头了阅读 216评论 0 1