-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 negative of prop-types with stateless components #735
Comments
Another example: 🚫 reports error: function Foo({bar}) {
return <div>{bar}</div>
}
Foo.propTypes = {
bar: PropTypes.string.isRequired
} Passes: Foo.propTypes = {
bar: PropTypes.string.isRequired
}
function Foo({bar}) {
return <div>{bar}</div>
} |
@kossnocorp How is created your This code is working: var Panel = {}; // <= Declare Panel
Panel.Body = ({children}) => (
<div className='Panel-body'>
{children}
</div>
)
Panel.Body.propTypes = {
children: PropTypes.node
} @kentcdodds What version of eslint and eslint-plugin-react are you using? Your first example is working for me with eslint-plugin-react |
@yannickcr the I have errors: ... on such code: import React, {PropTypes, Component} from 'react'
import classNames from 'classnames'
export default class Panel extends Component {
static propTypes = {
children: PropTypes.node,
color: PropTypes.oneOf(['green', 'red', 'orange', 'grey', 'blue'])
}
render () {
const {color, children} = this.props
const panelClasses = classNames('Panel', {
[`is-${color}`]: color,
'has-color': color
})
return (
<section className={panelClasses}>
{children}
</section>
)
}
}
Panel.Header = ({children}) => (
<header className='Panel-header'>
{children}
</header>
)
Panel.Header.propTypes = {
children: PropTypes.node
}
Panel.Body = ({children}) => (
<div className='Panel-body'>
{children}
</div>
)
Panel.Body.propTypes = {
children: PropTypes.node
} The version is Thank you a lot for great work! |
@kentcdodds I just tried your code and I don't have the error: You could try to upgrade I suppose, I had |
Ok, seems the issue comes from here. I'll have a look. |
Huh, it looks like my issue is possibly related but I'm not sure what's going on... Here's how I can reproduce the issue: import React, {PropTypes} from 'react'
function Foo({bar}) { // react/prop-types error reported for bar on this line
const {baz} = Foo
return <div>{baz} {bar}</div>
}
Foo.propTypes = {
bar: PropTypes.string.isRequired,
}
Foo.baz = 'hi' This does not produce any error: import React, {PropTypes} from 'react'
function Foo({bar}) {
const baz = Foo.baz
return <div>{baz} {bar}</div>
}
Foo.propTypes = {
bar: PropTypes.string.isRequired,
}
Foo.baz = 'hi' Looks like destructuring a property off of the function (whether inside the function itself or not) is causing issues. |
@kentcdodds ok, it's a different problem then. Can you open a new issue with your last message? Thanks. |
Cool, will do, thanks! |
When a stateless component is created as a property of an object,
prop-types
gives false negative:🚫 reports "'children' is missing in props validation":
👌🏽 works fine:
The text was updated successfully, but these errors were encountered: