Skip to content

Commit

Permalink
[Fix] prop-types: className missing in prop validation false negative
Browse files Browse the repository at this point in the history
  • Loading branch information
akulsr0 committed May 6, 2024
1 parent 03cd4b5 commit aa0910d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
// So we should construct an optional children prop
this.shouldSpecifyOptionalChildrenProps = true;

this.shouldSpecifyClassNameProp = true;

const rightMostName = getRightMostTypeName(node.typeName);
const importedName = localToImportedMap[rightMostName];
const idx = genericTypeParamIndexWherePropsArePresent[
Expand Down Expand Up @@ -825,6 +827,14 @@ module.exports = function propTypesInstructions(context, components, utils) {
isRequired: false,
};
}
if (this.shouldSpecifyClassNameProp) {
this.declaredPropTypes.className = {
fullName: 'className',
name: 'className',
isRequired: false,
};
}

this.foundDeclaredPropertiesList.forEach((tsInterfaceBody) => {
if (tsInterfaceBody && (tsInterfaceBody.type === 'TSPropertySignature' || tsInterfaceBody.type === 'TSMethodSignature')) {
let accessor = 'name';
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4181,6 +4181,16 @@ ruleTester.run('prop-types', rule, {
);
`,
features: ['types'],
},
{
code: `
import React from "react"
export function Heading({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
return <div className={cn("font-semibold text-lg", className)} {...props} />
}
`,
features: ['types'],
}
)),

Expand Down

0 comments on commit aa0910d

Please sign in to comment.