From 48291e82a1f87665a96ce84486f793b07f4d44ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=89=E1=85=A1=E1=86=BC?= =?UTF-8?q?=E1=84=83=E1=85=AE?= Date: Fri, 8 Mar 2024 21:02:12 +0900 Subject: [PATCH] [Fix] `boolean-prop-naming`: allow TSIntersectionType --- CHANGELOG.md | 2 ++ lib/rules/boolean-prop-naming.js | 3 +++ tests/lib/rules/boolean-prop-naming.js | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e22a6c8efb..937ded5283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index cc41537f21..2ed70cbfde 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -5,6 +5,7 @@ 'use strict'; +const flatMap = require('array.prototype.flatmap'); const values = require('object.values'); const Components = require('../util/Components'); @@ -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) { diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index 0ce676f97e..18932bb215 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -1245,7 +1245,7 @@ ruleTester.run('boolean-prop-naming', rule, { enabled: boolean } const HelloNew = (props: TestFNType) => { return
}; - `, + `, options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }], features: ['ts', 'no-babel'], errors: [ @@ -1264,5 +1264,27 @@ ruleTester.run('boolean-prop-naming', rule, { }, ], }, + { + code: ` + type Props = { + enabled: boolean + } + type BaseProps = { + semi: boolean + } + + const Hello = (props: Props & BaseProps) =>
; + `, + 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]?)+)', + }, + ], + }, ]), });