Skip to content

Commit 3265da7

Browse files
fix: allow TSIntersectionType
1 parent 0abebc6 commit 3265da7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/rules/boolean-prop-naming.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ module.exports = {
384384
propType = annotation;
385385
} else if (annotation.type === 'TSTypeReference') {
386386
propType = objectTypeAnnotations.get(annotation.typeName.name);
387+
} else if (annotation.type === 'TSIntersectionType') {
388+
propType = annotation.types.flatMap((type) => objectTypeAnnotations.get(type.typeName.name));
387389
}
388390

389391
if (propType) {

tests/lib/rules/boolean-prop-naming.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,5 +1264,26 @@ ruleTester.run('boolean-prop-naming', rule, {
12641264
},
12651265
],
12661266
},
1267+
{
1268+
code: `
1269+
type Props = {
1270+
enabled: boolean
1271+
}
1272+
type BaseProps = {
1273+
semi: boolean
1274+
}
1275+
1276+
const Hello = (props: Props & BaseProps) => <div />;`,
1277+
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
1278+
features: ['ts', 'no-babel', 'no-ts-old'],
1279+
errors: [
1280+
{
1281+
message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
1282+
},
1283+
{
1284+
message: 'Prop name (semi) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
1285+
},
1286+
],
1287+
},
12671288
]),
12681289
});

0 commit comments

Comments
 (0)