Linting
Some routing mistakes pass TypeScript. A few throw on first render; others never throw, and leave a dead link or a page that screen readers misread. Linting catches both kinds before you run the app.
What breaks without linting
A dead href on a button
Under the 1.x default (assignHref: true), uiSref writes an inert href onto a <button> and prints a development warning:
lit-ui-router/sref-assign-hrefhtml`<button ${uiSref('home')}>Home</button>`;uiSref writes an href to <button>, which has no href in HTML. Pass { assignHref: 'auto' } to write it only to links; 'auto' becomes the default in 2.0.html`<button ${uiSref('home', {}, { assignHref: 'auto' })}>Home</button>`;lit-ui-router/sref-assign-href catches this and --fix rewrites the call to uiSref('home', {}, { assignHref: 'auto' }) (see Design System Links for how assignHref treats native and custom elements).
A directive in the wrong template part
Binding uiSref as an attribute value throws in the directive constructor on first render (The `uiSref` directive must be used as an element):
lit-ui-router/directive-positionhtml`<a href=${uiSref('home')}>Home</a>`;`uiSref` must be used as an element part (`<a ${uiSref(...)}>`); it throws in attribute or child position.// Element part: uiSref manages href and click navigation
html`<a ${uiSref('home')}>Home</a>`;
// Attribute part: srefHref computes the href string
html`<a href=${srefHref('home')}>Home</a>`;lit-ui-router/directive-position flags misplaced directives with no autofix; move uiSref to an element part or switch to srefHref.
An active link with no aria-current
srefActiveClass paints CSS classes only, so an active link looks right while screen readers receive no active-page signal:
lit-ui-router/sref-active-class-aria-currenthtml`<a
href=${srefHref('home')}
class=${srefActiveClass({ state: 'home', activeClasses: ['active'] })}
>Home</a
>`;srefActiveClass marks this <a> active for CSS only; bind aria-current=${srefAriaCurrent({ state: 'home' })} beside it so assistive technology gets the same signal.html`<a
href=${srefHref('home')}
class=${srefActiveClass({ state: 'home', activeClasses: ['active'] })}
aria-current=${srefAriaCurrent({ state: 'home' })}
>Home</a
>`;lit-ui-router/sref-active-class-aria-current reports the missing attribute and --fix binds aria-current=${srefAriaCurrent({ state: 'home' })} beside class.
Add the plugin
Install eslint-plugin-lit-ui-router:
npm install --save-dev eslint-plugin-lit-ui-routerconfigs.recommended sets no files, so ESLint 9 and 10 apply it only to the .js, .mjs, and .cjs files they lint by default and skip .ts files without a message. A TypeScript app needs a config entry whose files glob covers .ts and that sets a TypeScript parser. typescript-eslint's configs.recommended does both; its configs.base or a bare languageOptions.parser sets no files and still lints nothing. Spread ...litUiRouter.configs.recommended into your existing flat config after that TypeScript entry and after eslint-plugin-lit-a11y (the Lit accessibility plugin, whose anchor-is-valid rule ours replaces):
import litA11y from 'eslint-plugin-lit-a11y';
import litUiRouter from 'eslint-plugin-lit-ui-router';
import tseslint from 'typescript-eslint';
export default [
...tseslint.configs.recommended,
litA11y.configs.recommended, // optional
...litUiRouter.configs.recommended,
];See examples/lint-eslint on GitHub for a complete TypeScript config, and the rules table for all six recommended rules. Configure settings when your app uses design-system link elements (linkElements), a typed uiSref wrapper module (litUiRouterSources), or prerendered templates (allowElementParts: false). Because every rule is syntax-only, the plugin also runs under oxlint as a JS plugin (alpha); see the oxlint setup in the package README.
Where lint sits among author-time checks
Each layer catches a different class of mistake:
- Typed routes (
ui-router-registry) catch misspelled state names and wrong parameter shapes during TypeScript checking. - Lint (
eslint-plugin-lit-ui-router) catches misplaced directives, inerthrefs, hrefless anchors, and missing or overwrittenaria-currentbindings across every file, including code paths a development run may never visit (see Catching the same problems at author time). - Development warnings (The warnings) catch runtime wiring faults such as a missing
<ui-router>ancestor or duplicate copies oflitwhile the app runs in development.
Once ESLint is configured to match and parse your TypeScript files, every recommended rule defaults to error, so npx eslint . fails in CI on violations and editor ESLint integrations surface the same diagnostics and autofixes as you edit.
The rest of your Lit code
eslint-plugin-litchecks general Lithtmltemplates in ESLint for invalid HTML, duplicate bindings, and legacy syntax.lit-analyzertype-checks template bindings against element declarations, though its last npm release was January 2024 (2.0.3), so verify TypeScript compatibility before adopting it.stylelintwithpostcss-litlints CSS insidecsstagged templates, not<style>elements inhtmltemplates. Preferstatic styles = css`...`onLitElementclasses over<style>inrender(), as Lit's styles documentation recommends, so styles are shared and linted directly.
Gaps in today's Lit tooling
Several parts of the Lit ecosystem sit at an awkward seam as older tools age out and faster native tools take shape. Two small internal wrappers under tools/ close the gaps for our own workspace; neither is published to npm, and both are short enough to read or copy if you need the same coverage:
- Template type-checking.
lit-analyzeris unmaintained (2.0.3from January 2024 is stilllatest).tools/lit-template-lintparseshtmltemplates withparse5, lowers them to TypeScript using element and attribute data from@webref/elements,@webref/idl, and@vscode/web-custom-data, and checks them through the TypeScript 7.1 betatypescript/syncAPI (typescript@7.1.0-beta). Native ports of that same API, such astsrs(a Rust port of TypeScript 7 exposing./sync, untested here), show where fast template checking is heading. <style>in templates.postcss-litparsescsstagged templates only.tools/postcss-lit-htmlwrapspostcss-litas one stylelintcustomSyntaxthat locateshtmlandsvgtemplates with@babel/parser, extracts<style>elements withparse5, maps findings back to source positions, and writesstylelint --fixchanges back in place.- Faster linting with oxlint. Because
eslint-plugin-lit-ui-routeris syntax-only, it loads into oxlint throughjsPlugins(alpha) alongside oxlint's native rules, as in.oxlintrc.json; see the plugin README's#oxlint-alphasection for the config.