Skip to content

Commit 48291e8

Browse files
developer-bandiljharb
authored andcommitted
[Fix] boolean-prop-naming: allow TSIntersectionType
1 parent 0abebc6 commit 48291e8

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
99
* [`jsx-no-leaked-render`]: prevent wrongly adding parens ([#3700][] @developer-bandi)
1010
* [`boolean-prop-naming`]: detect TS interfaces ([#3701][] @developer-bandi)
1111
* [`boolean-prop-naming`]: literalType error fix ([#3704][] @developer-bandi)
12+
* [`boolean-prop-naming`]: allow TSIntersectionType ([#3705][] @developer-bandi)
1213

14+
[#3705]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3705
1315
[#3704]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3704
1416
[#3701]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3701
1517
[#3700]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3700

lib/rules/boolean-prop-naming.js

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
'use strict';
77

8+
const flatMap = require('array.prototype.flatmap');
89
const values = require('object.values');
910

1011
const Components = require('../util/Components');
@@ -384,6 +385,8 @@ module.exports = {
384385
propType = annotation;
385386
} else if (annotation.type === 'TSTypeReference') {
386387
propType = objectTypeAnnotations.get(annotation.typeName.name);
388+
} else if (annotation.type === 'TSIntersectionType') {
389+
propType = flatMap(annotation.types, (type) => objectTypeAnnotations.get(type.typeName.name));
387390
}
388391

389392
if (propType) {

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ ruleTester.run('boolean-prop-naming', rule, {
12451245
enabled: boolean
12461246
}
12471247
const HelloNew = (props: TestFNType) => { return <div /> };
1248-
`,
1248+
`,
12491249
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
12501250
features: ['ts', 'no-babel'],
12511251
errors: [
@@ -1264,5 +1264,27 @@ 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+
`,
1278+
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
1279+
features: ['ts', 'no-babel', 'no-ts-old'],
1280+
errors: [
1281+
{
1282+
message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
1283+
},
1284+
{
1285+
message: 'Prop name (semi) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
1286+
},
1287+
],
1288+
},
12671289
]),
12681290
});

0 commit comments

Comments
 (0)