Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives about missing props for functional components #472

Closed
0x80 opened this issue Feb 28, 2016 · 6 comments
Closed

False positives about missing props for functional components #472

0x80 opened this issue Feb 28, 2016 · 6 comments

Comments

@0x80
Copy link

0x80 commented Feb 28, 2016

With the current version the code below gives false positives about missing proptypes for all props.

import { PropTypes } from 'react'
const { element, node, string } = PropTypes

Card.propTypes = {
  title: string.isRequired,
  children: element.isRequired,
  footer: node
}

export default function Card ({ title, children, footer }) {
  return (
    <div/>
  )
}

eslint 2.2.0
eslint-plugin-react 4.1.0
eslint-config-standard-react 2.3.0

.eslintrc

{
  "parser": "babel-eslint",
  "extends": ["standard", "standard-react"],
  "rules" : {
    "react/react-in-jsx-scope": 0,
    "padded-blocks" : 0,
    "space-before-function-paren": 0,
    "no-multi-spaces": 0,
    "key-spacing": 0,
    "arrow-parens": 0
  }
}
@smaye81
Copy link

smaye81 commented Mar 4, 2016

I am still seeing false positives with the following syntax. Not sure what I'm missing. This is with v4.1.0 and eslint v2.2.0.

import React, { PropTypes } from 'react';
import {
    ProgressBar
} from 'react-bootstrap';

const TableProgressBar = React.createClass({

    render () {
        return (
            <tr className="table-progress-bar">
                <td colSpan="5">
                    <ProgressBar active now={100} />
                    <p>{this.props.message}</p>
                </td>
            </tr>
        )
    }
});

TableProgressBar.propTypes = {
    message: PropTypes.string
};

export default TableProgressBar

And this is the message I see:
13:36 error 'message' is missing in props validation react/prop-types

@smaye81
Copy link

smaye81 commented Mar 4, 2016

So it looks like this might not be supported syntax according to this:

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prop-types.md

Looks like the Component.propTypes = ... is only supported with stateless functional components, but not with React.createClass. I sorta feel like it should be though. Thoughts? If so, I can create a PR

@ljharb
Copy link
Member

ljharb commented Mar 4, 2016

It definitely shouldn't be because I'm pretty sure that doesn't work. With React.createClass, you need to include propTypes in the actual object passed to React.createClass.

@smaye81
Copy link

smaye81 commented Mar 5, 2016

No, you don't have to do it that way. My entire app is structured like my example above and it works fine.

I think this prop-types rule is a great rule and I want to be able to apply it without restructuring every component in my application.

@ljharb
Copy link
Member

ljharb commented Mar 5, 2016

That's entirely undocumented and discouraged (since createClass is deprecated anyways) - I'm not sure it's a good thing to support.

@smaye81
Copy link

smaye81 commented Mar 5, 2016

React.createClass is not deprecated nor can I find anywhere that says this syntax is discouraged. But no worries. I'll refactor to adhere to the supported syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants