Skip to content

Commit 0abebc6

Browse files
developer-bandiljharb
authored andcommitted
[Fix] boolean-prop-naming: literalType error fix
1 parent 901c794 commit 0abebc6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

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

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

lib/rules/boolean-prop-naming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ module.exports = {
380380
let propType;
381381
if (annotation.type === 'GenericTypeAnnotation') {
382382
propType = objectTypeAnnotations.get(annotation.id.name);
383-
} else if (annotation.type === 'ObjectTypeAnnotation') {
383+
} else if (annotation.type === 'ObjectTypeAnnotation' || annotation.type === 'TSTypeLiteral') {
384384
propType = annotation;
385385
} else if (annotation.type === 'TSTypeReference') {
386386
propType = objectTypeAnnotations.get(annotation.typeName.name);

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

+10
Original file line numberDiff line numberDiff line change
@@ -1254,5 +1254,15 @@ ruleTester.run('boolean-prop-naming', rule, {
12541254
},
12551255
],
12561256
},
1257+
{
1258+
code: 'const Hello = (props: {enabled:boolean}) => <div />;',
1259+
options: [{ rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+' }],
1260+
features: ['ts', 'no-babel'],
1261+
errors: [
1262+
{
1263+
message: 'Prop name (enabled) doesn\'t match rule (^(is|has)[A-Z]([A-Za-z0-9]?)+)',
1264+
},
1265+
],
1266+
},
12571267
]),
12581268
});

0 commit comments

Comments
 (0)