Skip to content

Commit 74ce9dd

Browse files
authored
fix(no-node-access): prevent duplicate errors for chained property access (#1260)
Fixes #1256
1 parent d5aa504 commit 74ce9dd

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/rules/no-node-access.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export default createTestingLibraryRule<Options, MessageIds>({
6565
return;
6666
}
6767

68+
// Skip if this MemberExpression is the object of another MemberExpression
69+
// to avoid duplicate reports for chained property access
70+
if (isMemberExpression(node.parent) && node.parent.object === node) {
71+
return;
72+
}
73+
6874
const propertyName = ASTUtils.isIdentifier(node.property)
6975
? node.property.name
7076
: null;

tests/rules/no-node-access.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,33 @@ ruleTester.run(rule.name, rule, {
527527
},
528528
{
529529
code: `
530+
import { screen } from '${testingFramework}';
531+
532+
const rowHeader = screen.getByRole('rowheader');
533+
const radioContainer =
534+
(rowHeader.parentElement && rowHeader.parentElement.nextElementSibling) ||
535+
rowHeader.parentElement;
536+
`,
537+
errors: [
538+
{
539+
line: 6,
540+
column: 24,
541+
messageId: 'noNodeAccess',
542+
},
543+
{
544+
line: 6,
545+
column: 65,
546+
messageId: 'noNodeAccess',
547+
},
548+
{
549+
line: 7,
550+
column: 23,
551+
messageId: 'noNodeAccess',
552+
},
553+
],
554+
},
555+
{
556+
code: `
530557
import { render } from '${testingFramework}';
531558
532559
const { getByText } = render(<Example />)

0 commit comments

Comments
 (0)