百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

eslint-plugin-svelte

> 前端框架
开源

使用 AST 的 Svelte 专用 ESLint 插件

400 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 AST 的 Svelte 专用 ESLint 插件

Introduction

eslint-plugin-svelte is the official ESLint plugin for Svelte.
It leverages the AST generated by svelte-eslint-parser to provide custom linting for Svelte.\

[!NOTE]

eslint-plugin-svelte and svelte-eslint-parser cannot be used alongside eslint-plugin-svelte3.

Installation

CLI

The recommended way to get started is to use the CLI.

bash
# new project
npx sv create

# existing project
npx sv add eslint

See the CLI docs for more details.

Manual Setup

bash
npm install --save-dev svelte eslint eslint-plugin-svelte globals

[!NOTE]

Requirements:

  • ESLint v8.57.1, v9.0.0, and above
  • Node.js v18.18.0, v20.9.0, v21.1.0 and above

Usage

Use eslint.config.js to configure rules. See ESLint documentation for more details.

Configuration

JavaScript project

…

TypeScript project

bash
npm install --save-dev typescript-eslint
…

[!WARNING] The TypeScript parser uses a singleton internally, meaning it only respects the options provided during its initial initialization. If you try to change the options for a different file or override them later, the parser will ignore the new options, which may lead to errors. For more context, see typescript-eslint/typescript-eslint#6778.

Svelte config inside vite.config.js

The Svelte config can also be passed to the sveltekit() or svelte() plugin in vite.config.js; SvelteKit 3 projects do this by default. Use @sveltejs/load-config to load it:

javascript
// eslint.config.js
import { loadConfig } from '@sveltejs/load-config';

const svelteConfig = (await loadConfig('./', { traverse: false }))?.config;

Available Configurations

This plugin provides the following configurations:

  • svelte.configs.base - Required for Svelte parsing. Does not include any rules. Ideal for building a custom configurations.
  • svelte.configs.recommended - Extends base and includes rules for best practices.
  • svelte.configs.prettier - Extends base and disables rules that may conflict with Prettier. Prettier still needs to be configured to work with Svelte, for example, by using prettier-plugin-svelte.
  • svelte.configs.all - Not Recommended - Extends base and includes all rules. Subject to change with every major and minor release. Use at your own risk.

For more details, see the rule list to explore the rules provided by this plugin.

settings.svelte

You can customize the behavior of this plugin using specific settings.

…

Editor Integrations

Visual Studio Code
Install dbaeumer.vscode-eslint.
Configure .svelte files in .vscode/settings.json:

Migration Guide

If you’re migrating from eslint-plugin-svelte@1 or @ota-meshi/eslint-plugin-svelte, see the migration guide.

Versioning Policy

This project follows Semantic Versioning. Unlike ESLint’s versioning policy, new rules may be added to the recommended config in minor releases. If these rules cause unwanted warnings, you can disable them.

Rules

:wrench: Indicates that the rule is fixable, and using --fix option on the command line can automatically fix some of the reported problems.
:bulb: Indicates that some problems reported by the rule are manually fixable by editor suggestions.
:star: Indicates that the rule is included in the plugin:svelte/recommended config.

Possible Errors

These rules relate to possible syntax or logic errors in Svelte code:

Rule ID Description
svelte/infinite-reactive-loop Svelte runtime prevents calling the same reactive statement twice in a microtask. But between different microtask, it doesn't prevent. :star:
svelte/no-bind-value-on-checkable-inputs disallow useless bind:value on and :bulb:
svelte/no-conflicting-module-names disallow a .svelte component and a same-named runes module (e.g. Foo.svelte and Foo.svelte.ts) from coexisting
svelte/no-dom-manipulating disallow DOM manipulating :star:
svelte/no-dupe-else-if-blocks disallow duplicate conditions in {#if} / {:else if} chains :star:
svelte/no-dupe-on-directives disallow duplicate on: directives :star:
svelte/no-dupe-style-properties disallow duplicate style properties :star:
svelte/no-dupe-use-directives disallow duplicate use: directives :star:
svelte/no-nested-style-tag disallow `` elements nested inside other elements or blocks
svelte/no-not-function-handler disallow use of not function in event handler :star:
svelte/no-object-in-text-mustaches disallow objects in text mustache interpolation :star:
svelte/no-raw-special-elements Checks for invalid raw HTML elements :star::wrench:
svelte/no-reactive-reassign disallow reassigning reactive values :star:
svelte/no-shorthand-style-property-overrides disallow shorthand style properties that override related longhand properties :star:
svelte/no-store-async disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features :star:
svelte/no-top-level-browser-globals disallow using top-level browser global variables
svelte/no-unknown-style-directive-property disallow unknown style:property :star:
svelte/prefer-svelte-reactivity disallow using mutable instances of built-in classes where a reactive alternative is provided by svelte/reactivity :star:
svelte/require-store-callbacks-use-set-param store callbacks must use set param :bulb:
svelte/require-store-reactive-access disallow to use of the store itself as an operand. Need to use $ prefix or get function. :star::wrench:
svelte/valid-compile disallow warnings when compiling.
svelte/valid-style-parse require valid style element parsing

Security Vulnerability

These rules relate to security vulnerabilities in Svelte code:

Rule ID Description
svelte/no-at-html-tags disallow use of {@html} to prevent XSS attack :star:
svelte/no-target-blank disallow target="_blank" attribute without rel="noopener noreferrer"

Best Practices

These rules relate to better ways of doing things to help you avoid problems:

Rule ID Description
svelte/block-lang disallows the use of languages other than those specified in the configuration for the lang attribute of and blocks. :bulb:
svelte/button-has-type disallow usage of button without an explicit type attribute
svelte/no-add-event-listener Warns against the use of addEventListener :bulb:
svelte/no-at-const-tags disallow the use of {@const} in favor of {const ...} declaration tags :wrench:
svelte/no-at-debug-tags disallow the use of {@debug} :star::bulb:
svelte/no-ignored-unsubscribe disallow ignoring the unsubscribe method returned by the subscribe() on Svelte stores.
svelte/no-immutable-reactive-statements disallow reactive statements that don't reference reactive values. :star:
svelte/no-inline-styles disallow attributes and directives that produce inline styles
svelte/no-inspect Warns against the use of $inspect directive :star:
svelte/no-reactive-functions it's not necessary to define functions in reactive statements :star::bulb:
svelte/no-reactive-literals don't assign literal values in reactive statements :star::bulb:
svelte/no-svelte-internal svelte/internal will be removed in Svelte 6. :star:
svelte/no-unnecessary-state-wrap Disallow unnecessary $state wrapping of reactive classes :star::bulb:
svelte/no-unused-class-name disallow the use of a class in the template without a corresponding style
[svelte/no-unused-props](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-p

Issues· 138 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScripteslinteslint-pluginsveltesveltejs

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架