Skip to content

About

Lit web component lint rules for ESLint and Oxlint

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

eslint-plugin-lit-robust

Your Lit component type-checks, the build is green, and the list still won't re-render. No error, no warning, just a stale screen.

lit-robust catches the Lit bugs your compiler can't see, at lint time instead of in a bug report. Runs on ESLint and Oxlint.

class TodoList extends LitElement {
  @property({ type: Array })
  accessor items: string[] = [];

  add(item: string): void {
    // ❌ no-array-mutation-without-reassign: same array, so Lit sees no change
    // this.items.push(item);

    // ✅ a new array, so Lit re-renders
    this.items = [...this.items, item];
  }
}

A few more quiet ones it spots:

Install

# ESLint 9+
npm install --save-dev eslint eslint-plugin-lit-robust typescript-eslint jiti
# Oxlint, through Vite+
npm install --save-dev vite-plus eslint-plugin-lit-robust

Requires Node.js 22.18+, and lit installed where the linted code is.

Usage

The package's only export is the plugin. Its flat configs are at plugin.configs; combine as many as you want.

// ESLint 9+: eslint.config.ts (needs jiti)
import plugin from "eslint-plugin-lit-robust";
import { parser } from "typescript-eslint";
const ts = { files: ["**/*.ts"], languageOptions: { parser } };
export default [ts, plugin.configs.core, plugin.configs.strict];
// Oxlint, through Vite+: vite.config.ts
import plugin from "eslint-plugin-lit-robust";
import { defineConfig } from "vite-plus";
const rules = { ...plugin.configs.core.rules, ...plugin.configs.strict.rules };
export default defineConfig({
  lint: { jsPlugins: ["eslint-plugin-lit-robust"], rules },
});

Oxlint plugins carry no configs, so spread a config's rules instead. Every rule is set to "error"; to turn one off, set it after the config, e.g. "lit-robust/no-timers": "off".

The rules assume standard decorators, not experimentalDecorators. They use no type information: they follow imports into other files and packages to tell Lit's LitElement and html from look-alikes, and stay silent when they cannot tell.

Configs and rules

Config What it enforces
core Lit code that does not do what it looks like it does. Start here.
strict Stricter Lit style: decorators, a directive allowlist, tag and event maps, no manual update.
dom-ref Reach the DOM through a createRef ref, nothing else.
reactive-controller Anything with a lifetime (timers, listeners, fetch) belongs in a controller.
naming What elements, controllers, attributes, and events are called.
all Every rule, including ones added later.

Each rule belongs to exactly one config besides all. Rules take no options; each links to its docs with incorrect and correct examples.

💼 Configurations enabled in.
🧩 Set in the core configuration.
🔗 Set in the dom-ref configuration.
🔤 Set in the naming configuration.
🔄 Set in the reactive-controller configuration.
🔒 Set in the strict configuration.
🔧 Automatically fixable by the --fix CLI option.
💡 Manually fixable by editor suggestions.

Name                                   Description 💼 🔧 💡
attribute-names Require an explicit attribute option on camelCase reactive properties 🔤 💡
attribute-value-entities Require HTML entities for &, <, >, and " in template attribute values 🧩 🔧 💡
binding-positions Disallow bindings in tag names, closing tags, and attribute names 🧩
composed-requires-bubbles Require bubbles: true on events constructed with composed: true 🧩 💡
directive-allowlist Disallow Lit directive imports other than ref and repeat 🔒
event-name-case Require kebab-case names for events created with new CustomEvent() or new Event() 🔤 💡
host-constructor Require a reactive controller constructor to be exactly constructor(host: ReactiveControllerHost) 🔄 💡
lifecycle-allowlist Disallow Lit component lifecycle overrides other than styles and render 🔄
lifecycle-super Require Lit lifecycle overrides to call their super implementation 🧩 💡
no-array-mutation-without-reassign Disallow mutating array methods on reactive properties 🧩 💡
no-async-lifecycle Disallow async Lit lifecycle hooks 🧩
no-async-render Disallow an async render() on Lit components 🧩
no-attribute-property-binding-conflict Disallow binding one name as both an attribute and a property on an element 🧩 💡
no-boolean-property-default-true Disallow a type: Boolean reactive property whose default is not literal false 🔒 💡
no-camelcase-attribute Disallow uppercase letters and underscores in html template attribute names 🔤 💡
no-classfield-shadowing Disallow class fields that shadow reactive properties 🧩 💡
no-component-disposables Disallow creating disposable resources and listeners inside a Lit component 🔄
no-context-mutation-by-consumer Disallow assigning to fields declared with @consume 🧩
no-dispatch-in-render Disallow dispatching events from render() 🧩
no-dom-query Disallow querySelector and querySelectorAll inside a Lit component 🔗
no-duplicate-context-provider Disallow providing the same context twice from one class 🧩
no-duplicate-property-declaration Disallow declaring a reactive property both by decorator and in static properties 🧩
no-duplicate-slot-names Disallow two slots with the same name in one template 🧩
no-duplicate-tag-registration Disallow registering the same custom element tag twice in one file 🧩
no-duplicate-template-bindings Disallow binding the same attribute, property, or event twice on one element 🧩 💡
no-event-target-subclass Disallow classes that extend EventTarget 🔒
no-fetch-in-component Disallow calling fetch inside a Lit component 🔄
no-index-as-repeat-key Disallow repeat key functions that return the item index 🧩
no-inline-event-attribute Disallow inline event handler attributes in templates 🧩 💡
no-inner-html-assignment Disallow assigning to innerHTML or outerHTML 🧩
no-invalid-escape-sequences Disallow malformed \x and \u escapes in templates 🧩 💡
no-invalid-html Disallow template markup that is not valid HTML 🧩 💡
no-jsx-attribute-names Disallow the JSX attribute names className and htmlFor in templates 🧩 💡
no-legacy-imports Disallow Lit 1 module paths and the names Lit 2 removed 🧩 💡
no-legacy-template-syntax Disallow Polymer-style [[...]] and {{...}} bindings in templates 🧩
no-light-dom Disallow createRenderRoot() returning this in a Lit component 🔒
no-manual-update Disallow a Lit component scheduling its own updates 🔒
no-multiple-default-slots Disallow more than one default <slot> in a template 🧩
no-native-attributes Disallow reactive properties named after global HTML attributes 🧩
no-partial-property-binding Disallow property, event, and boolean bindings that are not the whole attribute value 🧩
no-private-properties Disallow declaring a private field as a public reactive property 🧩
no-property-assignment-in-constructor Disallow assigning a reactive property in the constructor 🔒
no-property-change-in-updated Disallow changing a reactive property in updated() or firstUpdated() 🧩
no-property-change-update Disallow changing a reactive property in update() 🧩
no-property-named-like-lifecycle Disallow fields and reactive properties named after Lit lifecycle members 🧩
no-query-decorators Disallow the Lit @query decorators and their imports 🔗
no-render-root-escape Disallow a Lit component's render root escaping the component 🔗
no-request-update-in-updated Disallow calling requestUpdate() in updated() or firstUpdated() 🧩
no-script-in-template Disallow <script> elements in templates 🧩
no-self-closing-non-void Disallow self-closing syntax on non-void HTML elements in templates 🧩 💡
no-string-context-key Disallow a string literal as a createContext() key 🔒 💡
no-this-assign-in-render Disallow assigning to this or its members inside render() 🧩
no-this-in-static-styles Disallow this inside static styles 🧩
no-timers Disallow setTimeout, setInterval, requestAnimationFrame, and queueMicrotask inside a Lit component 🔄
no-unsafe-css Disallow unsafeCSS from Lit 🧩
no-unsafe-html Disallow the unsafeHTML and unsafeSVG directives 🧩
no-update-complete Disallow accessing updateComplete 🔒
no-useless-template-literals Disallow an html template that holds only a single binding 🧩 💡
no-value-attribute Disallow a bound value attribute on a form control 🧩 💡
paired-lifecycle Require a reactive controller to define both hostConnected and hostDisconnected, or neither 🔄
prefer-context-decorators Enforce @provide and @consume over constructing ContextProvider or ContextConsumer 🔒
prefer-create-ref Enforce createRef over a ref callback that only stashes the element 🔗
prefer-decorators Enforce @property and @state decorators over static properties 🔒
prefer-static-styles Enforce static styles over <style> elements in templates 🧩
require-accessor-with-decorators Require accessor on fields decorated with @property or @state 🧩 💡
require-context-type Require an explicit type argument on createContext() 🧩
require-controller-suffix Require reactive controller class names to end in Controller 🔤
require-custom-element-registration Require every Lit component in a file to be registered as a custom element 🔒
require-dashed-tag Require custom element names that the registry accepts 🧩
require-direct-registration-import Require importing the module that registers each custom element a template uses 🧩
require-dispatch-on-this Require a component's events to be dispatched on the component itself 🧩 💡
require-element-suffix Require registered component class names to end in Element 🔤
require-event-in-event-map Require an HTMLElementEventMap entry for every event a Lit component constructs 🔒 💡
require-property-type Require a type on every @property that has an attribute 🧩
require-repeat-key Require a key function in repeat() 🧩
require-scalar-reflect Require reflected properties to declare a scalar type 🧩
require-tag-name-map Require an HTMLElementTagNameMap entry for every @customElement registration 🔒 💡
require-tag-prefix Require a namespace prefix in custom element names 🔤
self-registration Require a reactive controller to call host.addController(this) in its constructor 🔄 💡
simple-template-expressions Enforce plain names and member chains as template bindings 🧩
svg-template-for-svg-content Require SVG-only elements to sit in an svg template or an <svg> element 🧩
tag-matches-class-name Require a @customElement tag to name its class 🔤
value-after-constraints Enforce setting value after every validity constraint attribute 🧩

License: MIT.

About

Lit web component lint rules for ESLint and Oxlint

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages