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

require-default-props - fixing an edge case where linting stops early #1380

Merged
merged 1 commit into from Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rules/require-default-props.js
Expand Up @@ -578,7 +578,7 @@ module.exports = {

// If no propTypes could be found, we don't report anything.
if (!list[component].propTypes) {
return;
continue;
}

reportPropTypesWithoutDefault(
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/require-default-props.js
Expand Up @@ -1307,6 +1307,25 @@ ruleTester.run('require-default-props', rule, {
}]
},

// component with no declared props followed by a failing component
{
code: [
'var ComponentWithNoProps = ({ bar = "bar" }) => {',
' return <div>Hello {this.props.foo}</div>;',
'}',
'var Greetings = ({ foo = "foo" }) => {',
' return <div>Hello {this.props.foo}</div>;',
'}',
'Greetings.propTypes = {',
' foo: PropTypes.string',
'};'
].join('\n'),
errors: [{
message: 'propType "foo" is not required, but has no corresponding defaultProp declaration.',
line: 8,
column: 3
}]
},
//
// with Flow annotations
{
Expand Down