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 @@ -9,7 +9,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`jsx-no-leaked-render`]: prevent wrongly adding parens ([#3700][] @developer-bandi)
* [`boolean-prop-naming`]: detect TS interfaces ([#3701][] @developer-bandi)
* [`boolean-prop-naming`]: literalType error fix ([#3704][] @developer-bandi)
* [`boolean-prop-naming`]: allow TSIntersectionType ([#3705][] @developer-bandi)

[#3705]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3705
[#3704]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3704
[#3701]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3701
[#3700]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3700
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

'use strict';

const flatMap = require('array.prototype.flatmap');
const values = require('object.values');

const Components = require('../util/Components');
Expand Down Expand Up @@ -384,6 +385,8 @@ module.exports = {
propType = annotation;
} 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));
}

if (propType) {
Expand Down
24 changes: 23 additions & 1 deletion tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ ruleTester.run('boolean-prop-naming', rule, {
enabled: boolean
}
const HelloNew = (props: TestFNType) => { return <div /> };
`,
`,
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
features: ['ts', 'no-babel'],
errors: [
Expand All @@ -1264,5 +1264,27 @@ ruleTester.run('boolean-prop-naming', rule, {
},
],
},
{
code: `
type Props = {
enabled: boolean
}
type BaseProps = {
semi: boolean
}

const Hello = (props: Props & BaseProps) => <div />;
`,
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
features: ['ts', 'no-babel', 'no-ts-old'],
errors: [
{
message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
},
{
message: 'Prop name (semi) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
},
],
},
]),
});