Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`no-unknown-property`]: support `popover`, `popovertarget`, `popovertargetaction` attributes ([#3707][] @ljharb)
* [`no-unknown-property`]: only match `data-*` attributes containing `-` ([#3713][] @silverwind)
* [`checked-requires-onchange-or-readonly`]: correct options that were behaving opposite ([#3715][] @jaesoekjjang)
* [`boolean-prop-naming`]: avoid a crash with a non-TSTypeReference type ([#3718][] @developer-bandi)

### Changed
* [`boolean-prop-naming`]: improve error message (@ljharb)

[#3718]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3718
[#3715]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3715
[#3713]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3713
[#3707]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3707
Expand Down
6 changes: 5 additions & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ 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) => (
type.type === 'TSTypeReference'
? objectTypeAnnotations.get(type.typeName.name)
: type
));
}

if (propType) {
Expand Down
33 changes: 31 additions & 2 deletions tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -1312,10 +1312,10 @@ ruleTester.run('boolean-prop-naming', rule, {
code: `
type Props = {
enabled: boolean
}
};
type BaseProps = {
semi: boolean
}
};

const Hello = (props: Props & BaseProps) => <div />;
`,
Expand All @@ -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]?)+',
},
},
],
},
]),
});