Skip to content

Commit 901c794

Browse files
developer-bandiljharb
authored andcommitted
[Fix] boolean-prop-naming: detect TS interfaces
1 parent 8c2bdb2 commit 901c794

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
77

88
### Fixed
99
* [`jsx-no-leaked-render`]: prevent wrongly adding parens ([#3700][] @developer-bandi)
10+
* [`boolean-prop-naming`]: detect TS interfaces ([#3701][] @developer-bandi)
1011

12+
[#3701]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3701
1113
[#3700]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3700
1214

1315
## [7.34.0] - 2024.03.03

lib/rules/boolean-prop-naming.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ module.exports = {
264264
}
265265

266266
function findAllTypeAnnotations(identifier, node) {
267-
if (node.type === 'TSTypeLiteral' || node.type === 'ObjectTypeAnnotation') {
267+
if (node.type === 'TSTypeLiteral' || node.type === 'ObjectTypeAnnotation' || node.type === 'TSInterfaceBody') {
268268
const currentNode = [].concat(
269269
objectTypeAnnotations.get(identifier.name) || [],
270270
node
@@ -363,6 +363,10 @@ module.exports = {
363363
findAllTypeAnnotations(node.id, node.typeAnnotation);
364364
},
365365

366+
TSInterfaceDeclaration(node) {
367+
findAllTypeAnnotations(node.id, node.body);
368+
},
369+
366370
// eslint-disable-next-line object-shorthand
367371
'Program:exit'() {
368372
if (!rule) {
@@ -386,7 +390,7 @@ module.exports = {
386390
[].concat(propType).forEach((prop) => {
387391
validatePropNaming(
388392
component.node,
389-
prop.properties || prop.members
393+
prop.properties || prop.members || prop.body
390394
);
391395
});
392396
}

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

+15
Original file line numberDiff line numberDiff line change
@@ -1239,5 +1239,20 @@ ruleTester.run('boolean-prop-naming', rule, {
12391239
},
12401240
],
12411241
},
1242+
{
1243+
code: `
1244+
interface TestFNType {
1245+
enabled: boolean
1246+
}
1247+
const HelloNew = (props: TestFNType) => { return <div /> };
1248+
`,
1249+
options: [{ rule: '^is[A-Z]([A-Za-z0-9]?)+' }],
1250+
features: ['ts', 'no-babel'],
1251+
errors: [
1252+
{
1253+
message: 'Prop name (enabled) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)',
1254+
},
1255+
],
1256+
},
12421257
]),
12431258
});

0 commit comments

Comments
 (0)