Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I can't catch a place, where I'm fault.

my .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
  }
}

My webpack.config section about lint:

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

And my component

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
}

I have exception: 1:17 error "PropTypes" is defined but never used no-unused-vars

Hmm, what I'm doing wrong?

P.S. With babel5 - all works correctly.

like image 849
Max P Avatar asked Feb 08 '16 18:02

Max P


1 Answers

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

You're already importing React.PropTypes as PropTypes, so in this case, just change this to name: PropTypes.string.isRequired (or remove the PropTypes import on top)

like image 147
Naren Avatar answered Oct 20 '22 03:10

Naren