Skip to content

Allow exceptions for "no-node-access" #593

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

Closed
alexey-kozlenkov opened this issue May 25, 2022 · 3 comments · Fixed by #611
Closed

Allow exceptions for "no-node-access" #593

alexey-kozlenkov opened this issue May 25, 2022 · 3 comments · Fixed by #611
Labels
enhancement New feature or request released

Comments

@alexey-kozlenkov
Copy link

alexey-kozlenkov commented May 25, 2022

What rule do you want to change?

no-node-access

Does this change cause the rule to produce more or fewer warnings?

Fewer warnings

How will the change be implemented?

render method returns container which has content rendered inside it (div element by default - docs )

The easiest way to access content itself is by using firstChild property
This is hardly avoidable in some cases, such as:

  • snapshot testing
  • testing if rendering simply has/has not happened
  • counting child elements

The rule could ignore firstChild(only?) in some cases.

Example code

const MyComponent = () => <div>Any kind of stuff</div>
describe('some test', () => {
  it('test case', () => {
    const { container } = render(<MyComponent />)

    expect(container.firstChild).toMatchSnapshot()
  })
})

How does the current rule affect the code?

Currently rule highlights container.firstChild part as a mistaken direct Node access

How will the new rule affect the code?

Won't highlight it

Anything else?

No response

Do you want to submit a pull request to change the rule?

No

@alexey-kozlenkov alexey-kozlenkov added enhancement New feature or request triage Pending to be triaged by a maintainer labels May 25, 2022
@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label May 26, 2022
@Belco90
Copy link
Member

Belco90 commented May 26, 2022

Thanks for reporting @alexey-kozlenkov!

I was tempted to suggest an option like allowedProperties where you could specify all the properties needed, but that could be use as an escape hatch. So my proposal is to add a new allowContainerFirstChild option, which would be a boolean to prevent reporting container.firstChild. What do you think?

What about no-container? Does that rule complain about container.firstChild?

@alexey-kozlenkov
Copy link
Author

Sure, that would do the job!

No, no-container does not report these lines

@github-actions
Copy link

🎉 This issue has been resolved in version 5.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants