Skip to content

Fail no-container on use of innerHTML #883

Open
@CodingItWrong

Description

@CodingItWrong

What rule do you want to change?

no-container

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

More warnings

How will the change be implemented?

The rule will look for usages of container.innerHTML in addition to looking for usages of methods like container.querySelector()

Example code

const { container } = render(<Greeting />);
expect(container.innerHTML).toContain("Hello");

How does the current rule affect the code?

The current rule allows this code. It only errors if a method like container.querySelector is accessed.

How will the new rule affect the code?

The updated rule would fail on usages of container.innerHTML just as it does with the methods.

Anything else?

Descriptions of the rule would need to be updated from saying "disallow the user of container methods" to "container methods and properties" (or something)

If we found that anyone has use cases where using innerHTML is commonly needed but container methods are not, we could either make it configurable whether it's allowed, or make it a separate rule very similar to no-container

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

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions