False positive for react/prop-types props validation (stateless component)
See original GitHub issueI’m getting an error for a prop missing in props validation, when the prop is included the prop-types, similar to #258.
eslint
version v3.2.2eslint-plugin-react
v6.0.0
Here’s the error:
% eslint test.js
/Users/lauren/Projects/eslint-error/test.js
10:31 error 'onChange' is missing in props validation react/prop-types
✖ 1 problem (1 error, 0 warnings)
Here’s the code:
import React from "react";
import Slider from "./slider";
const StatelessCell = props =>
<div>
<a href="#" onClick={e => props.onChange(e)} />
<Slider value={props.severity}
onClick={severity => props.onChange({severity})} />
<Slider value={props.severity}
onClick={severity => props.onChange({severity})} />
</div>;
StatelessCell.PropTypes = {
severity: React.PropTypes.number,
onChange: React.PropTypes.func.isRequired,
};
export default StatelessCell;
Here’s my .eslintrc.json:
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"no-console": [
"error",
{
"allow": ["warn", "error"]
}
],
"indent": [
"error",
"tab",
{
"SwitchCase": 1
}
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-unused-vars": [
"error",
{
"vars": "all",
"argsIgnorePattern": "^_$"
}
],
"comma-dangle": [
"error",
"always-multiline"
],
"no-shadow": [
"error", { "hoist": "never" }
]
}
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:20
- Comments:5 (2 by maintainers)
Top Results From Across the Web
False positive for react/prop-types props validation ...
I'm getting an error for a prop missing in props validation, when the prop is included the prop-types, similar to #258.
Read more >false positive in prop-types validation - reactjs
You are not doing anything wrong. The problem is that every function that returns a JSX component is technically a stateless component.
Read more >How to validate React props using PropTypes
Learn how to validate props with React PropTypes, React's internal mechanism for adding type checking to component props.
Read more >searchprops' is missing in props validation
yannickcr/eslint-plugin-reactFalse Positive: "react/prop-types [PROP_NAME] is missing in props validation" when using stateless components + destructured ...
Read more >Don't Call PropTypes Warning
Fixing the false positive in third party PropTypes. If you are an author of a third party PropTypes library and you let consumers...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I get the same, and also a
displayName
missing error too:I’m using the
react/recommended
configPlease do not comment with “+1”, it adds noise and adds no value - please show your support by adding a reaction emoji to the original post. I’ll delete all the existing +1 comments, and any future ones.
Thanks for participating!