Getting Started
@html-eslint/eslint-plugin-svelte is an ESLint plugin that validates HTML attribute values and baseline browser compatibility directly in your Svelte code. It extends the core @html-eslint functionality to work seamlessly with Svelte components.
Contents
Installation
- npm
npm install --save-dev eslint @html-eslint/eslint-plugin-svelte svelte-eslint-parser- yarn
yarn add -D eslint @html-eslint/eslint-plugin-svelte svelte-eslint-parser
Configuration
Update your ESLint configuration file:
Manual Configuration
// eslint.config.js (flat config)
import htmlSvelte from "@html-eslint/eslint-plugin-svelte";
import svelteParser from "svelte-eslint-parser";
export default [
{
files: [
"**/*.svelte",
"*.svelte",
// Need to specify the file extension for Svelte 5 with rune symbols
"**/*.svelte.js",
"*.svelte.js",
"**/*.svelte.ts",
"*.svelte.ts",
],
languageOptions: {
parser: svelteParser,
},
rules: {
"@html-eslint/svelte/class-spacing": "error",
},
},
];
Using Preset Configurations
The plugin provides two preset configurations:
recommended- Enables all available rules with error severityall- Enables all available rules with error severity (currently identical torecommended)
Using the Recommended Configuration
// eslint.config.js
import htmlSvelte from "@html-eslint/eslint-plugin-svelte";
import svelteParser from "svelte-eslint-parser";
export default [
{
files: ["**/*.svelte"],
languageOptions: {
parser: svelteParser,
},
...htmlSvelte.configs.recommended,
},
];
Using the All Configuration
// eslint.config.js
import htmlSvelte from "@html-eslint/eslint-plugin-svelte";
import svelteParser from "svelte-eslint-parser";
export default [
{
files: ["**/*.svelte"],
languageOptions: {
parser: svelteParser,
},
...htmlSvelte.configs.all,
},
];