Skip to content

no-node-access reports issue with object method #1063

@ribeiroguilherme

Description

@ribeiroguilherme

Have you read the Troubleshooting section?

Yes

Plugin version

v7.6.6

ESLint version

v9.30.1

Node.js version

22.17.1

Bug description

When using a object that has a method named similar to HTML element methods, the no-node-access complains that function calls should not directly access a node.

test('should submit the payment', async () => {
    const pm = new PaymentMethod();
    pm.submit();
    //       ^ - Avoid direct Node access. Prefer using the methods from Testing Library. eslint testing-library/no-node-access 

I took a look at the Aggressive Reporting section and also in the optional configuration that can be passed to the no-node-access rule but couldn't manage to go around this issue.

Steps to reproduce

Add the following code to a test file:

class PaymentMethod {
    submit() {}
    click() {}
}

test('should submit the payment', () => {
    const pm = new PaymentMethod();
    pm.click();
    //      ^ - Avoid direct Node access. Prefer using the methods from Testing Library. eslint testing-library/no-node-access
    pm.submit();
    //      ^ - Avoid direct Node access. Prefer using the methods from Testing Library. eslint testing-library/no-node-access
    // ...
});

Error output/screenshots

No response

ESLint configuration

import testingLibrary from 'eslint-plugin-testing-library';
// ...

export default [
  // ...
  {
        name: 'Testing files rules',
        files: ['**/?(*.)+(spec|test).[jt]s?(x)'],
        plugins: {
            'testing-library': testingLibrary
        },
        ...testingLibrary.configs['flat/dom'],
        ...testingLibrary.configs['flat/react']
    }
];

Rule(s) affected

no-node-access

Anything else?

No response

Do you want to submit a pull request to fix this bug?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriagePending to be triaged by a maintainer

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions