Max P February 2016

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.

Answers


Naren February 2016

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)

Post Status

Asked in February 2016
Viewed 1,665 times
Voted 7
Answered 1 times

Search




Leave an answer