-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Evgueni Naverniouk
committed
Aug 21, 2016
1 parent
4be546a
commit 504bcd5
Showing
6 changed files
with
2,924 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Prevent definitions of unused prop types (unused-prop-types) | ||
|
||
Warns you if you have defined a prop type but it is never being used anywhere. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered warnings: | ||
|
||
```jsx | ||
var Hello = React.createClass({ | ||
propTypes: { | ||
name: React.PropTypes.string | ||
}, | ||
render: function() { | ||
return <div>Hello Bob</div>; | ||
} | ||
}); | ||
|
||
var Hello = React.createClass({ | ||
propTypes: { | ||
firstname: React.PropTypes.string.isRequired, | ||
middlename: React.PropTypes.string.isRequired, // middlename is never used below | ||
lastname: React.PropTypes.string.isRequired | ||
}, | ||
render: function() { | ||
return <div>Hello {this.props.firstname} {this.props.lastname}</div>; | ||
} | ||
}); | ||
``` | ||
|
||
The following patterns are not considered warnings: | ||
|
||
```jsx | ||
var Hello = React.createClass({ | ||
propTypes: { | ||
name: React.PropTypes.string | ||
}, | ||
render: function() { | ||
return <div>Hello {this.props.name}</div>; | ||
} | ||
}); | ||
``` | ||
|
||
## Rule Options | ||
|
||
This rule can take one argument to ignore some specific props during validation. | ||
|
||
``` | ||
... | ||
"prop-types": [<enabled>, { customValidators: <customValidator> }] | ||
... | ||
``` | ||
|
||
* `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0. | ||
* `customValidators`: optional array of validators used for propTypes validation. | ||
* `skipShapeProps`: In some cases it is impossible to accurately detect whether or not a `React.PropTypes.shape`'s values are being used. Setting this option to `true` will skip validation of `PropTypes.shape`. | ||
|
||
## About component detection | ||
|
||
For this rule to work we need to detect React components, this could be very hard since components could be declared in a lot of ways. | ||
|
||
For now we should detect components created with: | ||
|
||
* `React.createClass()` | ||
* an ES6 class that inherit from `React.Component` or `Component` | ||
* a stateless function that return JSX or the result of a `React.createElement` call. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.