svelte-eslint-parser

Svelte parser for ESLint

MIT 147 个版本
安装
npm install svelte-eslint-parser
yarn add svelte-eslint-parser
pnpm add svelte-eslint-parser
bun add svelte-eslint-parser
README

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status Coverage Status

svelte-eslint-parser

Svelte parser for ESLint

Live DEMODiscord

Motivation

The svelte-eslint-parser aims to make it easy to create your own ESLint rules for Svelte.

eslint-plugin-svelte is an ESLint plugin built upon this parser, and it already implements some rules.

ESLint Plugins Using svelte-eslint-parser

eslint-plugin-svelte

ESLint plugin for Svelte.
Provides a variety of template-based checks using the Svelte AST.

@intlify/eslint-plugin-svelte

ESLint plugin for internationalization (i18n) in Svelte applications, offering helpful i18n-related rules.


Installation

npm install --save-dev eslint svelte-eslint-parser

Usage

ESLint Config (eslint.config.js)

import js from "@eslint/js";
import svelteParser from "svelte-eslint-parser";

export default [
  js.configs.recommended,
  {
    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,
    },
  },
];

CLI

eslint "src/**/*.{js,svelte}"

Options

The parserOptions for this parser generally match what espree—ESLint's default parser—supports.

For example:

import svelteParser from "svelte-eslint-parser";

export default [
  // ...
  {
    files: [
      // Set .svelte/.js/.ts files. See above for more details.
    ],
    languageOptions: {
      parser: svelteParser,
      parserOptions: {
        sourceType: "module",
        ecmaVersion: 2024,
        ecmaFeatures: {
          globalReturn: false,
          impliedStrict: false,
          jsx: false,
        },
      },
    },
  },
];

parserOptions.parser

Use the parserOptions.parser property to define a custom parser for <script> tags. Any additional parser options (besides the parser itself) are passed along to the specified parser.

import tsParser from "@typescript-eslint/parser";

export default [
  {
    files: [
      // Set .svelte/.js/.ts files. See above for more details.
    ],
    languageOptions: {
      parser: svelteParser,
      parserOptions: {
        parser: tsParser,
      },
    },
  },
];

Using TypeScript in <script>

If you use @typescript-eslint/parser for TypeScript within <script> of .svelte files, additional configuration is needed. For example:

import tsParser from "@typescript-eslint/parser";

export default [
  // Other config for non-Svelte files
  {
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        project: "path/to/your/tsconfig.json",
        extraFileExtensions: [".svelte"],
      },
    },
  },
  // Svelte config
  {
    files: [
      // Set .svelte/.js/.ts files. See above for more details.
    ],
    languageOptions: {
      parser: svelteParser,
      // Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
      parserOptions: {
        parser: tsParser,
      },
    },
  },
];

Multiple parsers

To switch parsers for each language, provide an object:

import tsParser from "@typescript-eslint/parser";
import espree from "espree";

export default [
  {
    files: [
      // Set .svelte/.js/.ts files. See above for more details.
    ],
    languageOptions: {
      parser: svelteParser,
      parserOptions: {
        parser: {
          ts: tsParser,
          js: espree,
          typescript: tsParser,
        },
      },
    },
  },
];

parserOptions.svelteConfig

If you use eslint.config.js, you can specify a svelte.config.js file via parserOptions.svelteConfig.

import svelteConfig from "./svelte.config.js";

export default [
  {
    files: [
      // Set .svelte/.js/.ts files. See above for more details.
    ],
    languageOptions: {
      parser: svelteParser,
      parserOptions: {
        svelteConfig,
      },
    },
  },
];

If parserOptions.svelteConfig is not set, the parser attempts to statically read some config from svelte.config.js.

parserOptions.svelteFeatures

You can configure how Svelte-specific features are parsed via parserOptions.svelteFeatures.

For example:

export default [
  {
    files: [
      // Set .svelte/.js/.ts files. See above for more details.
    ],
    languageOptions: {
      parser: svelteParser,
      parserOptions: {
        svelteFeatures: {
          // This is for Svelte 5. The default is true.
          // If false, ESLint won't recognize rune symbols.
          // If not specified, the parser tries to read compilerOptions.runes from `svelte.config.js`.
          // If `parserOptions.svelteConfig` is not given and static analysis fails, it defaults to true.
          runes: true,
        },
      },
    },
  },
];

Experimental

ts.sys.readFile hook for type-aware Svelte lint

⚠️ Experimental. Opt-in only; behavior may change or be removed.

Speeds up type-aware lint of .svelte files. Your ESLint config must already list .svelte via parserOptions.extraFileExtensions.

SVELTE_ESLINT_PARSER_EXPERIMENTAL_TS_SYS_HOOK=1 \
  eslint --no-cache --concurrency auto .

Caveat: rules that read raw TypeScript diagnostics (program.getSemanticDiagnostics() and friends) report positions inside the parser's virtual shim — a pre-existing property of type-aware Svelte lint, not specific to the hook.


Editor Integrations

Visual Studio Code

Use the dbaeumer.vscode-eslint extension provided by Microsoft.

By default, it only targets *.js and *.jsx, so you need to configure .svelte file support. For example, in .vscode/settings.json:

{
  "eslint.validate": ["javascript", "javascriptreact", "svelte"]
}

Usage for Custom Rules / Plugins

  • See AST.md for the AST specification. You can explore it on the Live DEMO.
  • This parser generates its own ScopeManager. Check the Live DEMO.
  • Several rules are [already implemented] in [eslint-plugin-svelte], and their source code can be a helpful reference.

Contributing

Contributions are welcome! Please open an issue or submit a PR on GitHub.
For internal details, see internal-mechanism.md.


License

See LICENSE (MIT) for rights and limitations.

版本列表
1.8.0 2026-06-04
1.7.1 2026-06-02
1.7.0 2026-05-30
1.6.1 2026-05-05
1.6.0 2026-03-05
1.5.1 2026-02-24
1.5.0 2026-02-24
1.4.1 2025-12-04
1.4.0 2025-10-19
1.3.3 2025-09-21
1.3.2 2025-09-10
1.3.1 2025-08-02
1.3.0 2025-07-16
1.2.0 2025-05-15
1.1.3 2025-04-19
1.1.2 2025-04-03
1.1.1 2025-03-27
1.1.0 2025-03-17
1.0.1 2025-03-05
1.0.0 2025-02-25
1.0.0-next.13 2025-01-16
1.0.0-next.12 2025-01-15
1.0.0-next.11 2025-01-14
1.0.0-next.10 2025-01-13
1.0.0-next.9 2025-01-13
1.0.0-next.8 2025-01-12
1.0.0-next.7 2025-01-12
1.0.0-next.6 2024-12-31
1.0.0-next.5 2024-12-31
1.0.0-next.4 2024-12-10
1.0.0-next.3 2024-12-02
1.0.0-next.2 2024-12-02
1.0.0-next.1 2024-12-01
1.0.0-next.0 2024-11-27
0.43.0 2024-10-20
0.42.0 2024-10-16
0.41.1 2024-09-13
0.41.0 2024-07-19
0.40.0 2024-07-11
0.39.2 2024-06-23
0.39.1 2024-06-17
0.39.0 2024-06-17
0.38.0 2024-06-15
0.37.0 2024-06-10
0.36.0 2024-05-09
0.35.0 2024-04-22
0.34.1 2024-04-09
0.34.0 2024-04-07
0.34.0-next.12 2024-03-08
0.34.0-next.11 2024-03-03
0.34.0-next.10 2024-02-29
0.34.0-next.9 2024-02-24
0.34.0-next.8 2024-01-21
0.34.0-next.7 2024-01-21
0.34.0-next.6 2023-12-02
0.34.0-next.5 2023-11-26
0.34.0-next.4 2023-11-22
0.34.0-next.3 2023-11-21
0.34.0-next.2 2023-11-20
0.34.0-next.1 2023-11-17
0.34.0-next.0 2023-11-14
0.33.1 2023-10-03
0.33.0 2023-08-21
0.32.2 2023-07-20
0.32.1 2023-07-08
0.32.0 2023-06-28
0.31.0 2023-06-11
0.30.0 2023-06-01
0.29.0 2023-05-18
0.28.0 2023-05-09
0.27.0 2023-04-26
0.26.1 2023-04-14
0.26.0 2023-04-07
0.25.1 2023-04-02
0.25.0 2023-04-01
0.24.2 2023-03-17
0.24.1 2023-03-17
0.24.0 2023-03-08
0.23.0 2023-02-03
0.22.4 2023-01-15
0.22.3 2022-12-25
0.22.2 2022-12-15
0.22.1 2022-11-29
0.22.0 2022-11-24
0.21.0 2022-11-14
0.20.0 2022-11-01
0.19.3 2022-10-28
0.19.2 2022-10-27
0.19.1 2022-10-27
0.19.0 2022-10-25
0.18.4 2022-09-28
0.18.3 2022-09-16
0.18.2 2022-09-05
0.18.1 2022-08-31
0.18.0 2022-08-12
0.17.0 2022-07-25
0.16.6 2022-07-23
0.16.5 2022-07-21
0.16.4 2022-06-24
0.16.3 2022-06-04
0.16.2 2022-04-18
0.16.1 2022-04-15
0.16.0 2022-04-09
0.15.0 2022-02-15
0.14.0 2022-02-05
0.13.0 2022-01-21
0.12.0 2022-01-14
0.11.0 2022-01-13
0.10.0 2022-01-12
0.9.2 2021-12-14
0.9.1 2021-12-10
0.9.0 2021-12-08
0.8.0 2021-11-30
0.7.0 2021-11-28
0.6.1 2021-11-28
0.6.0 2021-11-06
0.5.0 2021-10-14
0.4.6 2021-10-05
0.4.5 2021-07-21
0.4.4 2021-07-20
0.4.3 2021-07-15
0.4.2 2021-07-15
0.4.1 2021-06-29
0.4.0 2021-06-29
0.3.0 2021-06-19
0.2.1 2021-06-18
0.2.0 2021-06-18
0.1.0 2021-05-27
0.0.19 2021-05-22
0.0.18 2021-05-19
0.0.17 2021-05-18
0.0.16 2021-05-18
0.0.15 2021-05-15
0.0.14 2021-05-14
0.0.13 2021-05-12
0.0.12 2021-05-12
0.0.11 2021-05-11
0.0.10 2021-05-07
0.0.9 2021-05-05
0.0.8 2021-04-30
0.0.7 2021-04-29
0.0.6 2021-04-29
0.0.5 2021-04-28
0.0.4 2021-04-28
0.0.3 2021-04-27
0.0.2 2021-04-27
0.0.1 2021-04-27