diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index 2cc1416115..0166ca9ea2 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -137,37 +137,6 @@ module.exports = { return true; } - /** - * Checks if the prop is declared in destructured params - * @param {Object[]} params List of destructured param among props without declaredPropTypes - * @returns {Boolean} True if the prop is declared, false if not. - */ - function isDeclaredInDestructuredParam(params) { - let result = true; - params.forEach((param) => { - if (!param.properties) { - result = false; - return; - } - param.properties.forEach((property) => { - if (property.type === 'RestElement' || property.type === 'ExperimentalRestProperty') { - return; - } - const type = property.value.type; - const right = property.value.right; - if (type !== 'AssignmentPattern') { - result = false; - return; - } - if (type === 'AssignmentPattern' && right && right.expression && right.expression.type && right.expression.type !== 'Literal') { - result = false; - } - }); - }); - - return result; - } - /** * Checks if the prop is declared * @param {ASTNode} node The AST node being checked. @@ -185,9 +154,6 @@ module.exports = { return true; } - if (component && !isDeclared && !component.declaredPropTypes && component.node.params && (component.node.type === 'FunctionDeclaration' || component.node.type === 'FunctionExpression' || component.node.type === 'ArrowFunctionExpression')) { - return isDeclaredInDestructuredParam(component.node.params); - } node = node.parent; } return false; diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index b117901173..34ff21193b 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2987,46 +2987,6 @@ ruleTester.run('prop-types', rule, { `, parser: parsers['@TYPESCRIPT_ESLINT'] }, - { - code: ` - function Foo({ foo = "" }): JSX.Element { - return
{foo}
; - } - `, - parser: parsers['@TYPESCRIPT_ESLINT'] - }, - { - code: ` - function Foo({ bar = "" as string }): JSX.Element { - return
{bar}
; - } - `, - parser: parsers['@TYPESCRIPT_ESLINT'] - }, - { - code: ` - export default function ({ value = 'World' }) { - return

Hello {value}

- } - `, - parser: parsers['@TYPESCRIPT_ESLINT'] - }, - { - code: ` - const Foo: JSX.Element = ({ bar = "" }) => { - return
{bar}
; - } - `, - parser: parsers['@TYPESCRIPT_ESLINT'] - }, - { - code: ` - const Foo: JSX.Element = function foo ({ bar = "" }) { - return
{bar}
; - } - `, - parser: parsers['@TYPESCRIPT_ESLINT'] - }, // Issue: #2795 { code: ` @@ -4364,7 +4324,63 @@ ruleTester.run('prop-types', rule, { errors: [ {message: '\'name.constructor.firstname\' is missing in props validation'} ] - }, { + }, + { + code: ` + function Hello({ foo = '' }) { + return

{foo}

+ } + `, + errors: [ + {message: '\'foo\' is missing in props validation'} + ], + parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + const Foo: JSX.Element = ({ bar = "" }) => { + return
{bar}
; + } + `, + errors: [ + {message: '\'bar\' is missing in props validation'} + ], + parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + function Foo({ foo = "" }): JSX.Element { + return
{foo}
; + } + `, + errors: [ + {message: '\'foo\' is missing in props validation'} + ], + parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + const Foo: JSX.Element = function foo ({ bar = "" }) { + return
{bar}
; + } + `, + errors: [ + {message: '\'bar\' is missing in props validation'} + ], + parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { + code: ` + function Foo({ bar = "" as string }): JSX.Element { + return
{bar}
; + } + `, + errors: [ + {message: '\'bar\' is missing in props validation'} + ], + parser: parsers['@TYPESCRIPT_ESLINT'] + }, + { code: [ 'function SomeComponent({bar}) {', ' function f({foo}) {}',