Socket
Book a DemoInstallSign in
Socket

eslint-plugin-custom-element

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-custom-element

This plugin creates rules specific for validating custom element implementation in HTML

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Custom Element ESLint Plugin

This plugin creates custom rules to lint custom elements in HTML.

demo of eslint validation for custom elements

Usage

This plugin leverages the @html-eslint/eslint-plugin and @html-eslint/parser packages to parse the DOM.

npm install -D eslint-plugin-custom-element eslint @html-eslint/eslint-plugin @html-eslint/parser

NOTE: If you would like to have these rules automatically generated for you, check out the Custom Element ESLint Rule Generator.

Configuration

// eslint.config.js

import customElement from "eslint-plugin-custom-element";
import html from "@html-eslint/eslint-plugin";
import htmlParser from "@html-eslint/parser";

export default [
  {
    files: ["**/*.html"],
    languageOptions: {
      parser: htmlParser,
    },
    plugins: {
      html,
      "custom-element": customElement,
    },
    rules: {
      /* Add configuration for custom element rules */
    },
  },
];

For more configuration options, check out the HTML ESLint docs.

Rules

The plugin provides predefined rules for validating custom element APIs.

Constrained Attributes

The custom-element/constrained-attrs rule provides validation for attributes with predefined acceptable values.

// eslint.config.js

export default [
  {
    /* ...plugin config... */
    rules: {
      "custom-element/constrained-attrs": [
        "error",
        {
          tag: "my-button",
          attr: "appearance",
          values: ["primary", "outline", "default", "transparent"],
        },
      ],
    },
  },
];

Deprecated Attributes

The custom-element/no-deprecated-attrs rule notifies the developer when an attribute for a custom element is deprecated.

// eslint.config.js

export default [
  {
    /* ...plugin config... */
    rules: {
      "custom-element/no-deprecated-attrs": [
        "warn",
        {
          tag: "my-button",
          attr: "size",
        },
      ],
    },
  },
];

Deprecated Tag

The custom-element/no-deprecated-tags rule notifies the developer when a custom element is deprecated.

// eslint.config.js

export default [
  {
    /* ...plugin config... */
    rules: {
      "custom-element/no-deprecated-tags": [
        "warn",
        {
          tag: "your-element",
        },
      ],
    },
  },
];

Required Attributes

The custom-element/required-attrs rule notifies the developer if an expected attribute is not present on the custom element.

// eslint.config.js

export default [
  {
    /* ...plugin config... */
    rules: {
      "custom-element/required-attrs": [
        "error",
        {
          tag: "my-button",
          attr: "type",
        },
      ],
    },
  },
];

Boolean Attribute Values

The custom-element/no-boolean-attr-values rule notifies users that setting a value on boolean attributes will result in it always being true (ie - <my-button disabled="false"></my-button> will result in a disabled button).

// eslint.config.js

export default [
  {
    /* ...plugin config... */
    rules: {
      "custom-element/no-boolean-attr-values": [
        "error",
        {
          tag: "my-button",
          attr: "disabled",
        },
      ],
    },
  },
];

Keywords

web components

FAQs

Package last updated on 20 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.