Skip to content

Commit

Permalink
Merge 74c4eed into 2bf24b2
Browse files Browse the repository at this point in the history
  • Loading branch information
mikol committed Sep 20, 2020
2 parents 2bf24b2 + 74c4eed commit f35cc8f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -18,7 +18,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`prop-types`]: Detect TypeScript types for destructured default prop values ([#2780][] @sunghyunjo)
* [`jsx-pascal-case`]: Handle single character namespaced component ([#2791][] @daviferreira)
* [`jsx-closing-bracket-location`]: In `tag-aligned`, made a distinction between tabs and spaces ([#2796][] @Moong0122)
* [`jsx-handler-names`]: false positive when handler name begins with number ([#2801][] @mikol)
* [`jsx-handler-names`]: false positive when handler name begins with number ([#1689][] @jsphstls)
* [`prop-types`]: Detect JSX returned by sequential expression ([#2801][] @mikol)

[#2801]: https://github.com/yannickcr/eslint-plugin-react/pull/2801
[#2796]: https://github.com/yannickcr/eslint-plugin-react/pull/2796
Expand All @@ -33,6 +34,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
[#2767]: https://github.com/yannickcr/eslint-plugin-react/pull/2767
[#2761]: https://github.com/yannickcr/eslint-plugin-react/pull/2761
[#2748]: https://github.com/yannickcr/eslint-plugin-react/pull/2748
[#1689]: https://github.com/yannickcr/eslint-plugin-react/pull/1689

## [7.20.6] - 2020.08.12

Expand Down
8 changes: 8 additions & 0 deletions lib/util/Components.js
Expand Up @@ -71,6 +71,12 @@ function isReturnsLogicalJSX(node, property, strict) {
: (returnsLogicalJSXLeft || returnsLogicalJSXRight);
}

function isReturnsSequentialJSX(node, property) {
return node[property]
&& node[property].type === 'SequenceExpression'
&& jsxUtil.isJSX(node[property].expressions[node[property].expressions.length - 1]);
}

const Lists = new WeakMap();

/**
Expand Down Expand Up @@ -457,13 +463,15 @@ function componentRule(rule, context) {

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

const returnsJSX = node[property] && jsxUtil.isJSX(node[property]);
const returnsPragmaCreateElement = this.isCreateElement(node[property]);

return !!(
returnsConditionalJSX
|| returnsLogicalJSX
|| returnsSequentialJSX
|| returnsJSX
|| returnsPragmaCreateElement
);
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 f35cc8f

Please sign in to comment.