Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] boolean-prop-naming: literal TSIntersectionType not allow error fix #3705

Merged
1 commit merged into from
Mar 8, 2024
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 @@
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));

Check warning on line 389 in lib/rules/boolean-prop-naming.js

View check run for this annotation

Codecov / codecov/patch

lib/rules/boolean-prop-naming.js#L388-L389

Added lines #L388 - L389 were not covered by tests
}

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]?)+)',
},
],
},
]),
});
Loading