Skip to content

Commit

Permalink
fix: intersection with literal Type
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-bandi committed Mar 16, 2024
1 parent e4ecbcf commit 3cdaed2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/boolean-prop-naming.js
Expand Up @@ -386,7 +386,12 @@ module.exports = {
} else if (annotation.type === 'TSTypeReference') {
propType = objectTypeAnnotations.get(annotation.typeName.name);
} else if (annotation.type === 'TSIntersectionType') {
propType = flatMap(annotation.types, (type) => objectTypeAnnotations.get(type.typeName.name));
propType = flatMap(annotation.types, (type) => {
if (type.type === 'TSTypeReference') {
return objectTypeAnnotations.get(type.typeName.name);
}
return type;
});
}

if (propType) {
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/rules/boolean-prop-naming.js
Expand Up @@ -1338,5 +1338,34 @@ ruleTester.run('boolean-prop-naming', rule, {
},
],
},
{
code: `
type Props = {
enabled: boolean
}
const Hello = (props: Props & {
semi: boolean
}) => <div />;
`,
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
features: ['ts', 'no-babel', 'no-ts-old'],
errors: [
{
messageId: 'patternMismatch',
data: {
propName: 'enabled',
pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
},
},
{
messageId: 'patternMismatch',
data: {
propName: 'semi',
pattern: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
},
},
],
},
]),
});

0 comments on commit 3cdaed2

Please sign in to comment.