Skip to content

Commit aa0910d

Browse files
committed
[Fix] prop-types: className missing in prop validation false negative
1 parent 03cd4b5 commit aa0910d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/util/propTypes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
634634
// So we should construct an optional children prop
635635
this.shouldSpecifyOptionalChildrenProps = true;
636636

637+
this.shouldSpecifyClassNameProp = true;
638+
637639
const rightMostName = getRightMostTypeName(node.typeName);
638640
const importedName = localToImportedMap[rightMostName];
639641
const idx = genericTypeParamIndexWherePropsArePresent[
@@ -825,6 +827,14 @@ module.exports = function propTypesInstructions(context, components, utils) {
825827
isRequired: false,
826828
};
827829
}
830+
if (this.shouldSpecifyClassNameProp) {
831+
this.declaredPropTypes.className = {
832+
fullName: 'className',
833+
name: 'className',
834+
isRequired: false,
835+
};
836+
}
837+
828838
this.foundDeclaredPropertiesList.forEach((tsInterfaceBody) => {
829839
if (tsInterfaceBody && (tsInterfaceBody.type === 'TSPropertySignature' || tsInterfaceBody.type === 'TSMethodSignature')) {
830840
let accessor = 'name';

tests/lib/rules/prop-types.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4181,6 +4181,16 @@ ruleTester.run('prop-types', rule, {
41814181
);
41824182
`,
41834183
features: ['types'],
4184+
},
4185+
{
4186+
code: `
4187+
import React from "react"
4188+
4189+
export function Heading({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) {
4190+
return <div className={cn("font-semibold text-lg", className)} {...props} />
4191+
}
4192+
`,
4193+
features: ['types'],
41844194
}
41854195
)),
41864196

0 commit comments

Comments
 (0)