Skip to content

Commit

Permalink
Merge 20103c5 into 911f66e
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Wullems committed Aug 30, 2020
2 parents 911f66e + 20103c5 commit 05f56f4
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,10 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Added
* [`button-has-type`]: support trivial ternary expressions ([#2748][] @Hypnosphi)

### Fixed
* [`function-component-definition`]: ignore object properties ([#2771][] @stefan-wullems)

[#2771]: https://github.com/yannickcr/eslint-plugin-react/pull/2771
[#2748]: https://github.com/yannickcr/eslint-plugin-react/pull/2748

## [7.20.6] - 2020.08.12
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/function-component-definition.js
Expand Up @@ -156,6 +156,9 @@ module.exports = {

function validate(node, functionType) {
if (!components.get(node)) return;

if (node.parent && node.parent.type === 'Property') return;

if (hasName(node) && namedConfig !== functionType) {
report(node, {
message: ERROR_MESSAGES[namedConfig],
Expand Down
138 changes: 138 additions & 0 deletions tests/lib/rules/function-component-definition.js
Expand Up @@ -166,6 +166,144 @@ ruleTester.run('function-component-definition', rule, {
code: 'function Hello(props): ReactNode { return <p/> }',
options: [{namedComponents: 'function-declaration'}],
parser: parsers.TYPESCRIPT_ESLINT
},
// https://github.com/yannickcr/eslint-plugin-react/issues/2765
{
code: [
'const obj = {',
' serialize: (el) => {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'function-declaration'}]
}, {
code: [
'const obj = {',
' serialize: (el) => {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'arrow-function'}]
}, {
code: [
'const obj = {',
' serialize: (el) => {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'function-expression'}]
},
{
code: [
'const obj = {',
' serialize: function (el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'function-declaration'}]
}, {
code: [
'const obj = {',
' serialize: function (el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'arrow-function'}]
}, {
code: [
'const obj = {',
' serialize: function (el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'function-expression'}]
}, {
code: [
'const obj = {',
' serialize(el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'function-declaration'}]
}, {
code: [
'const obj = {',
' serialize(el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'arrow-function'}]
}, {
code: [
'const obj = {',
' serialize(el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{namedComponents: 'function-expression'}]
}, {
code: [
'const obj = {',
' serialize(el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'arrow-function'}]
}, {
code: [
'const obj = {',
' serialize(el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'function-expression'}]
}, {
code: [
'const obj = {',
' serialize: (el) => {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'arrow-function'}]
}, {
code: [
'const obj = {',
' serialize: (el) => {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'function-expression'}]
}, {
code: [
'const obj = {',
' serialize: function (el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'arrow-function'}]
}, {
code: [
'const obj = {',
' serialize: function (el) {',
' return <p/>',
' }',
'}'
].join('\n'),
options: [{unnamedComponents: 'function-expression'}]
}],

invalid: [{
Expand Down

0 comments on commit 05f56f4

Please sign in to comment.