html-eslint v0.69.0

no-restricted-tags

This rule disallows the use of specified tags in Svelte components.

How to use

// eslint.config.js (flat config)
import htmlSvelte from "@html-eslint/eslint-plugin-svelte";

export default [
  {
    files: ["**/*.svelte"],
    plugins: {
      "@html-eslint/svelte": htmlSvelte,
    },
    rules: {
      "@html-eslint/svelte/no-restricted-tags": [
        "error",
        {
          tagPatterns: ["^div$", "^span$"],
          message: "Use semantic elements instead of div and span.",
        },
      ],
    },
  },
];

Rule Details

This rule allows you to specify tags that you don't want to use in your application.

Options

This rule takes an array of option objects, where the tagPatterns are specified.

  1. tagPatterns: An array of strings representing regular expression patterns. It disallows tag names that match any of the patterns.
  2. message (optional): A custom error message to be shown when the rule is triggered.

Examples of incorrect code for this rule with the option below:

{
  "tagPatterns": ["^div$", "^span$"],
  "message": "Use semantic elements instead of generic containers"
}
<div>Content</div>
<span>Text</span>

Examples of correct code for this rule with the option above:

<article>Content</article>
<p>Text</p>
<section>Content</section>