Skip to content

[Feat]: require-dom-props for enforcing properties on DOM Elements #3642

Open
@intellix

Description

@intellix

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

So you've optimised your bundles, your images and improved your Lighthouse score and someone adds an <iframe> element to the bottom of the homepage containing a grid of youtube video previews. Lighthouse tells you that you didn't need that extra 8mb on your homepage.

Not everyone knows about the <iframe loading="lazy"> property to fix this and it was an oversight not to include it. In order to fix this, it would be great to have a linting rule that enforced you to explicitly provide properties to certain DOM elements, like iframe. That way when it was added, in order for the regression, a developer would have had to explicitly state loading="eager" (the default).

I can see that there are rules for forbidding certain properties on DOM/Components but I don't see a rule for requiring properties to exist on certain elements and components.

If a more generic rule was added that supported this, you could essentially deprecate this property as it would be achieveable via the new rule: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/iframe-missing-sandbox.md

Expected Behavior

I should get a linting warning when someone adds an iframe and doesn't provide the loading property.

eslint-plugin-react version

N/A

eslint version

N/A

node version

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions