Skip to content

no-unused-vars errors for jsx inside html #295

Open
@dmail

Description

@dmail

Description

ESLint no-unused-vars rule reports all jsx components declared in HTML as unused.

Linting the following html would report 'App' is assigned a value but never used error:

<!doctype html>
<html>
  <head>
    <title>Title</title>
    <meta charset="utf-8" />
    <link rel="icon" href="data:," />
  </head>

  <body>
    <div id="app"></div>
    <script type="module">
      import { render } from "preact";
   
      const App = () => {
        return "Hello world";
      };
      render(
        <App />,
        document.querySelector("#app"),
      );
    </script>
  </body>
</html>

Alternatives

Disable locally

How?

// eslint-disable-next-line no-unused-vars on each jsx component

Problem

Having to manually add this all the time

Disable no-unused-vars for react pattern

How?

Add "varsIgnorePattern": "React" in my ESLint config. see varsIgnorePattern

Problem

Looks like a hack. Have false positive preventing ESLint to find actually unused-vars.

Additional context

The ESLint rule "react/jsx-uses-react" should be able to mark variables as used. But it seems this rule is not applied to the js found in HTML files by this plugin.

I've tried to add .html and .js extensions eslint-plugin-react configuration

{
  "react/jsx-filename-extension": ["error",  { "extensions": [".jsx", ".html", ".js"] }],
}

But it does not work.

Any idea what's going on?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @dmail

      Issue actions

        no-unused-vars errors for jsx inside html · Issue #295 · BenoitZugmeyer/eslint-plugin-html