Skip to content

Commit

Permalink
[Fix] Detect JSX returned by sequential expression (tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikol committed Sep 20, 2020
1 parent 4dc6752 commit 866f20e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/util/Components.js
Expand Up @@ -71,7 +71,7 @@ function isReturnsLogicalJSX(node, property, strict) {
: (returnsLogicalJSXLeft || returnsLogicalJSXRight);
}

function isReturnsSequentialJSX(node, property, strict) {
function isReturnsSequentialJSX(node, property) {
return node[property]
&& node[property].type === 'SequenceExpression'
&& jsxUtil.isJSX(node[property].expressions[node[property].expressions.length - 1]);
Expand Down Expand Up @@ -463,7 +463,7 @@ function componentRule(rule, context) {

const returnsConditionalJSX = isReturnsConditionalJSX(node, property, strict);
const returnsLogicalJSX = isReturnsLogicalJSX(node, property, strict);
const returnsSequentialJSX = isReturnsSequentialJSX(node, property, strict);
const returnsSequentialJSX = isReturnsSequentialJSX(node, property);

const returnsJSX = node[property] && jsxUtil.isJSX(node[property]);
const returnsPragmaCreateElement = this.isCreateElement(node[property]);
Expand Down
27 changes: 27 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -2501,6 +2501,20 @@ ruleTester.run('prop-types', rule, {
export default function() {}
`
},
{
code: `
function Component(props) {
return 0,
<div>
Hello, { props.name }!
</div>
}
Component.propTypes = {
name: PropTypes.string.isRequired
}
`
},
parsers.TS([
{
code: `
Expand Down Expand Up @@ -5591,6 +5605,19 @@ ruleTester.run('prop-types', rule, {
message: '\'foo.baz\' is missing in props validation'
}]
},
{
code: `
function Component(props) {
return 0,
<div>
Hello, { props.name }!
</div>
}
`,
errors: [{
message: '\'name\' is missing in props validation'
}]
},
parsers.TS([
{
code: `
Expand Down

0 comments on commit 866f20e

Please sign in to comment.