PropTypes 已定义,但从未使用过(ESLint、babel 6)

PropTypes defined, but never used (ESLint, babel 6)

我抓不到一个地方,我错了。

我的.eslintrc

{
  "extends": "eslint:recommended",
  "parser": "babel-eslint",
  "env": {
    "browser": true,
    "node": true
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "no-console": 0,
    "new-cap": 0,
    "strict": 0,
    "no-underscore-dangle": 0,
    "no-use-before-define": 0,
    "eol-last": 0,
    "quotes": [2, "single"],
    "jsx-quotes": 1,
    "react/jsx-no-undef": 1,
    "react/jsx-uses-react": 1,
    "react/jsx-uses-vars": 1
  }
}

我关于 lint 的 webpack.config 部分:

preLoaders: [
  {
    test: /\.js$/,
    loaders: ['eslint'],
    include: [
      path.resolve(__dirname, "src"),
    ],
  }
],

还有我的组件

import React, { PropTypes, Component } from 'react'

export default class User extends Component {
  render() {
    const { name } = this.props
    return <div>
      <p>Hello, {name}!</p>
    </div>
  }
}

User.propTypes = {
  name: React.PropTypes.string.isRequired
}

我有例外: 1:17 错误 "PropTypes" 已定义但从未使用过 no-unused-vars

嗯,我做错了什么?

P.S。使用 babel5 - 一切正常。

User.propTypes = {
  name: React.PropTypes.string.isRequired
}

您已经将 React.PropTypes 导入为 PropTypes,因此在这种情况下,只需将其更改为 name: PropTypes.string.isRequired(或删除顶部的 PropTypes 导入)