diff --git a/src/rules/no-node-access.ts b/src/rules/no-node-access.ts index f711267e..ba195cb0 100644 --- a/src/rules/no-node-access.ts +++ b/src/rules/no-node-access.ts @@ -65,6 +65,12 @@ export default createTestingLibraryRule({ return; } + // Skip if this MemberExpression is the object of another MemberExpression + // to avoid duplicate reports for chained property access + if (isMemberExpression(node.parent) && node.parent.object === node) { + return; + } + const propertyName = ASTUtils.isIdentifier(node.property) ? node.property.name : null; diff --git a/tests/rules/no-node-access.test.ts b/tests/rules/no-node-access.test.ts index fe39f57f..2c82251e 100644 --- a/tests/rules/no-node-access.test.ts +++ b/tests/rules/no-node-access.test.ts @@ -527,6 +527,33 @@ ruleTester.run(rule.name, rule, { }, { code: ` + import { screen } from '${testingFramework}'; + + const rowHeader = screen.getByRole('rowheader'); + const radioContainer = + (rowHeader.parentElement && rowHeader.parentElement.nextElementSibling) || + rowHeader.parentElement; + `, + errors: [ + { + line: 6, + column: 24, + messageId: 'noNodeAccess', + }, + { + line: 6, + column: 65, + messageId: 'noNodeAccess', + }, + { + line: 7, + column: 23, + messageId: 'noNodeAccess', + }, + ], + }, + { + code: ` import { render } from '${testingFramework}'; const { getByText } = render()