html-eslint v0.69.0

id-naming-convention

This rule enforces a consistent naming convention for id attribute values.

How to use

// eslint.config.js (flat config)
import angularTemplate from "@html-eslint/eslint-plugin-angular-template";
import templateParser from "@angular-eslint/template-parser";

export default [
  {
    files: ["**/*.html"],
    languageOptions: {
      parser: templateParser,
    },
    plugins: {
      "@html-eslint/angular-template": angularTemplate,
    },
    rules: {
      "@html-eslint/angular-template/id-naming-convention": "error",
    },
  },
];

Rule Details

This rule supports four naming conventions. camelCase, snake_case, PascalCase, kebab-case (default snake_case). It also supports regex, which allows you to define a custom naming convention.

Options

  1. "snake_case" (default): Enforce snake_case format.
  2. "camelCase": Enforce camelCase format.
  3. "PascalCase": Enforce PascalCase format.
  4. "kebab-case": Enforce kebab-case format.
  5. "regex", { "pattern": "^my-regex$", "flags": "i" }: Enforce a format defined by a custom regex. The flags option is optional.

Examples

Examples of incorrect code for this rule with the default "snake_case" option:

<div id="Foo"></div>

Examples of correct code for this rule with the default "snake_case" option:

<div id="foo_bar"></div>

Note: An id whose value is a bound attribute (e.g. <div [id]="dynamicId"></div>), or an element on a custom element (names containing -), can't be statically verified, so it is ignored.

Further Reading

Wiki - Naming convention