Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive for no-node-access when accessing variable declaration's property children, activeElement, firstChild etc #683

Open
sjarva opened this issue Oct 23, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@sjarva
Copy link
Collaborator

sjarva commented Oct 23, 2022

Have you read the Troubleshooting section?

Yes

Plugin version

v5.9.1

ESLint version

v8.23.0

Node.js version

16.10.0

package manager and version

npm 7.24.0

Operating system

macOS Big Sur, version 11.6

Bug description

Extracted to an issue of its own from discussion in #386.

Steps to reproduce

  1. Have a unit test with a variable declaration that has a children property
  2. Access that property in some part of the test (e.g. expect statement)
  3. Run linter and see an error

For example, here is a test code snippet that produces the error:

import { render } from '@testing-library/react'; // Does not matter which library, this error happens with all

const navItemWithChildren = {
	title: 'Cars',
	children: [
		{
		title: 'Add car',
		},
		{
		title: 'All cars',
		},
	],
	};

render(<NavComponent itemWithChildren={navItemWithChildren} />)
expect(
	screen.getByText(navItemWithChildren.children[0].title),
	).toBeVisible();

Error output/screenshots

18:42 error Avoid direct Node access. Prefer using the methods from Testing Library testing-library/no-node-access

ESLint configuration

Recommend rules

Rule(s) affected

no-node-access

Anything else?

children and all other property names listed in PROPERTIES_RETURNING_NODES in lib/util/index.ts should not produce this error, if they happen to be properties of some variable declaration.

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

No

@sjarva sjarva added bug Something isn't working triage Pending to be triaged by a maintainer labels Oct 23, 2022
@Belco90
Copy link
Member

Belco90 commented Oct 23, 2022

Thanks for reporting this. We already got other complaints about this, definitely a legit bug. Not really sure what pattern we could use to decide when to report properties from this rule.

@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Oct 23, 2022
@sjarva
Copy link
Collaborator Author

sjarva commented Oct 23, 2022

I have an idea of how to do this, but I'm afraid that I don't have the words to explain it clearly enough 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants