Skip to content

Commit

Permalink
[Fix]: add more tests, use indexOf instead of includes
Browse files Browse the repository at this point in the history
  • Loading branch information
vedadeepta committed Aug 25, 2021
1 parent ea30053 commit a315a2f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/propTypes.js
Expand Up @@ -925,7 +925,7 @@ module.exports = function propTypesInstructions(context, components, utils) {

const typeName = context.getSourceCode().getText(annotation.typeName).replace(/ /g, '');

if (!allowedGenericTypes.includes(typeName)) return;
if (allowedGenericTypes.indexOf(typeName) === -1) return;

markPropTypesAsDeclared(node, resolveTypeAnnotation(siblingIdentifier));
} else {
Expand Down
36 changes: 36 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -6670,6 +6670,42 @@ ruleTester.run('prop-types', rule, {
}
],
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React from 'react';
interface PersonProps {
test: string;
}
const Person: React.FunctionComponent<PersonProps> = (props): React.ReactElement => (
<div>{props.username}</div>
);
`,
errors: [
{
messageId: 'missingPropType',
data: {name: 'username'}
}
],
parser: parsers['@TYPESCRIPT_ESLINT']
},
{
code: `
import React from 'react';
interface PersonProps {
username: string;
}
const Person: React.FunctionComponent<PersonProps> = (props): React.ReactElement => (
<div>{props.test}</div>
);
`,
errors: [
{
messageId: 'missingPropType',
data: {name: 'test'}
}
],
parser: parsers['@TYPESCRIPT_ESLINT']
}
])
)
Expand Down

0 comments on commit a315a2f

Please sign in to comment.