我没把握住我错的地方。

我的.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
}

我有异常(exception):
1:17错误“PropTypes”已定义,但从未使用过no-unused-vars

嗯,我做错了什么?

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

最佳答案

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

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

关于reactjs - 定义了PropType,但是从未使用过(ESLint,babel 6),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35276673/

10-12 16:27