Skip to content

Commit

Permalink
Merge 7d24b9c into 57d0df7
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Oct 25, 2020
2 parents 57d0df7 + 7d24b9c commit a5d9df9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,10 @@ function componentRule(rule, context) {
return undefined;
}
if (utils.isInAllowedPositionForComponent(node) && utils.isReturningJSXOrNull(node)) {
return node;
if (!node.id || isFirstLetterCapitalized(node.id.name)) {
return node;
}
return undefined;
}

// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
Expand Down
3 changes: 2 additions & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
return;
}

if (isInsideClassBody(node)) {
// https://github.com/yannickcr/eslint-plugin-react/issues/2784
if (isInsideClassBody(node) && !astUtil.isFunction(node)) {
return;
}

Expand Down
31 changes: 31 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,37 @@ ruleTester.run('prop-types', rule, {
}
export default InputField`,
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React from 'react'
class Factory {
getRenderFunction() {
return function renderFunction({ name }) {
return <div>Hello {name}</div>
}
}
}
`
},
{
code: `
import React from 'react'
type ComponentProps = {
name: string
}
class Factory {
getComponent() {
return function Component({ name }: ComponentProps) {
return <div>Hello {name}</div>
}
}
}
`,
parser: parsers['@TYPESCRIPT_ESLINT']
}
])
),
Expand Down

0 comments on commit a5d9df9

Please sign in to comment.