-
-
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
Allow skipping prop-types validation when not declared #846
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -1305,6 +1305,62 @@ ruleTester.run('prop-types', rule, { | |
'}' | ||
].join('\n'), | ||
parser: 'babel-eslint' | ||
}, { | ||
code: [ | ||
'var Hello = React.createClass({', | ||
' render: function() {', | ||
' return <div>{this.props.name}</div>;', | ||
' }', | ||
'});' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions | ||
}, { | ||
code: [ | ||
'var Hello = React.createClass({', | ||
' render: function() {', | ||
' return <div>{this.props.name}</div>;', | ||
' }', | ||
'});' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions | ||
}, { | ||
code: [ | ||
'class Hello extends React.Component {', | ||
' render() {', | ||
' return <div>{this.props.name}</div>;', | ||
' }', | ||
'}' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions | ||
}, { | ||
code: [ | ||
'var Hello = React.createClass({', | ||
' propTypes: {', | ||
' name: React.PropTypes.object.isRequired', | ||
' },', | ||
' render: function() {', | ||
' return <div>{this.props.name}</div>;', | ||
' }', | ||
'});' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions | ||
}, { | ||
code: [ | ||
'var Hello = React.createClass({', | ||
' propTypes: {', | ||
' name: React.PropTypes.object.isRequired', | ||
' },', | ||
' render: function() {', | ||
' return <div>{this.props.name}</div>;', | ||
' }', | ||
'});' | ||
].join('\n'), | ||
options: [{skipUndeclared: false}], | ||
parserOptions: parserOptions | ||
} | ||
], | ||
|
||
|
@@ -2312,6 +2368,85 @@ ruleTester.run('prop-types', rule, { | |
column: 27, | ||
type: 'Property' | ||
}] | ||
}, { | ||
code: [ | ||
'var Hello = React.createClass({', | ||
' propTypes: {},', | ||
' render: function() {', | ||
' return <div>{this.props.firstname}</div>;', | ||
' }', | ||
'});' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions, | ||
errors: [{ | ||
message: '\'firstname\' is missing in props validation', | ||
line: 4, | ||
column: 29 | ||
}] | ||
}, { | ||
code: [ | ||
'var Hello = function(props) {', | ||
' return <div>{props.firstname}</div>;', | ||
'};', | ||
'Hello.propTypes = {}' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions, | ||
errors: [{ | ||
message: '\'firstname\' is missing in props validation', | ||
line: 2, | ||
column: 22 | ||
}] | ||
}, { | ||
code: [ | ||
'class Hello extends React.Component {', | ||
' static get propTypes() {', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure thing - I've added that as an additional case |
||
' return {};', | ||
' }', | ||
' render() {', | ||
' return <div>{this.props.firstname}</div>;', | ||
' }', | ||
'}' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions, | ||
errors: [{ | ||
message: '\'firstname\' is missing in props validation', | ||
line: 6, | ||
column: 29 | ||
}] | ||
}, { | ||
code: [ | ||
'class Hello extends React.Component {', | ||
' render() {', | ||
' return <div>{this.props.firstname}</div>;', | ||
' }', | ||
'}', | ||
'Hello.propTypes = {};' | ||
].join('\n'), | ||
options: [{skipUndeclared: true}], | ||
parserOptions: parserOptions, | ||
errors: [{ | ||
message: '\'firstname\' is missing in props validation', | ||
line: 3, | ||
column: 29 | ||
}] | ||
}, { | ||
code: [ | ||
'var Hello = React.createClass({', | ||
' render: function() {', | ||
' return <div>{this.props.firstname}</div>;', | ||
' }', | ||
'});' | ||
].join('\n'), | ||
options: [{skipUndeclared: false}], | ||
parserOptions: parserOptions, | ||
errors: [{ | ||
message: '\'firstname\' is missing in props validation', | ||
line: 3, | ||
column: 29 | ||
}] | ||
} | ||
] | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this would be
static propTypes = () => {
- i don't thinkpropTypes
is expected to be anything but a data property.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied how the other static propTypes were declared in this file. upon closer inspection, this file is inconsistent in how it declares static proptypes. I see three different types:
static get propTypes() {
static propTypes = {
static propTypes: {
do you think I should introduce a fourth type? i'm also happy to consolidate them but I think that is outside the scope of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm not sure why we have the getter version, and the "fourth" type is in fact the most standard. The third type there isn't actually valid because of the
static
keyword, but I think you mean its use inReact.createClass
, which is fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not worry about consolidating them in this PR, but please do add a
Hello.propTypes = { … }
variant.