Skip to content

Commit 3cdaed2

Browse files
fix: intersection with literal Type
1 parent e4ecbcf commit 3cdaed2

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/rules/boolean-prop-naming.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,12 @@ module.exports = {
386386
} else if (annotation.type === 'TSTypeReference') {
387387
propType = objectTypeAnnotations.get(annotation.typeName.name);
388388
} else if (annotation.type === 'TSIntersectionType') {
389-
propType = flatMap(annotation.types, (type) => objectTypeAnnotations.get(type.typeName.name));
389+
propType = flatMap(annotation.types, (type) => {
390+
if (type.type === 'TSTypeReference') {
391+
return objectTypeAnnotations.get(type.typeName.name);
392+
}
393+
return type;
394+
});
390395
}
391396

392397
if (propType) {

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

+29
Original file line numberDiff line numberDiff line change
@@ -1338,5 +1338,34 @@ ruleTester.run('boolean-prop-naming', rule, {
13381338
},
13391339
],
13401340
},
1341+
{
1342+
code: `
1343+
type Props = {
1344+
enabled: boolean
1345+
}
1346+
1347+
const Hello = (props: Props & {
1348+
semi: boolean
1349+
}) => <div />;
1350+
`,
1351+
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
1352+
features: ['ts', 'no-babel', 'no-ts-old'],
1353+
errors: [
1354+
{
1355+
messageId: 'patternMismatch',
1356+
data: {
1357+
propName: 'enabled',
1358+
pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
1359+
},
1360+
},
1361+
{
1362+
messageId: 'patternMismatch',
1363+
data: {
1364+
propName: 'semi',
1365+
pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
1366+
},
1367+
},
1368+
],
1369+
},
13411370
]),
13421371
});

0 commit comments

Comments
 (0)