Gathering detailed insights and metrics for svelte-eslint-parser
Gathering detailed insights and metrics for svelte-eslint-parser
Gathering detailed insights and metrics for svelte-eslint-parser
Gathering detailed insights and metrics for svelte-eslint-parser
npm install svelte-eslint-parser
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
95 Stars
685 Commits
21 Forks
7 Watching
13 Branches
13 Contributors
Updated on 27 Nov 2024
TypeScript (85.97%)
Svelte (9.76%)
JavaScript (3.98%)
Dockerfile (0.22%)
HTML (0.07%)
CSS (0.01%)
Cumulative downloads
Total Downloads
Last day
6.8%
82,153
Compared to previous day
Last week
5.6%
428,716
Compared to previous week
Last month
13.7%
1,716,659
Compared to previous month
Last year
320.8%
15,599,802
Compared to previous year
1
47
Svelte parser for ESLint.
You can check it on Online DEMO.
[!NOTE] This README is in development.
Please refer to the README for the version you are using.
For example, https://github.com/sveltejs/svelte-eslint-parser/blob/v0.43.0/README.md
Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5.
The svelte-eslint-parser aims to make it easy to create your own ESLint rules for Svelte.
The eslint-plugin-svelte
is an ESLint plugin that uses the svelte-eslint-parser. I have already implemented some rules.
ESLint plugin for Svelte.
It provides many unique check rules by using the template AST.
ESLint plugin for internationalization (i18n) with Svelte.
It provides rules to help internationalization your application created with Svelte.
The svelte-eslint-parser can not be used with the eslint-plugin-svelte3.
1npm install --save-dev eslint svelte-eslint-parser
parser
option into your ESLint Config file.--ext .svelte
CLI option.eslint.config.js
)1import js from "@eslint/js"; 2import svelteParser from "svelte-eslint-parser"; 3export default [ 4 js.configs.recommended, 5 { 6 files: ["**/*.svelte", "*.svelte"], 7 languageOptions: { 8 parser: svelteParser, 9 }, 10 }, 11];
.eslintrc.*
)1{ 2 "extends": "eslint:recommended", 3 "overrides": [ 4 { 5 "files": ["*.svelte"], 6 "parser": "svelte-eslint-parser" 7 } 8 ] 9}
1$ eslint "src/**/*.{js,svelte}" 2# or 3$ eslint src --ext .svelte
parserOptions
has the same properties as what espree, the default parser of ESLint, is supporting.
For example:
1{ 2 "parserOptions": { 3 "sourceType": "module", 4 "ecmaVersion": 2021, 5 "ecmaFeatures": { 6 "globalReturn": false, 7 "impliedStrict": false, 8 "jsx": false 9 } 10 } 11}
You can use parserOptions.parser
property to specify a custom parser to parse <script>
tags.
Other properties than parser would be given to the specified parser.
For example in eslint.config.js
:
1import tsParser from "@typescript-eslint/parser"; 2export default [ 3 { 4 files: ["**/*.svelte", "*.svelte"], 5 languageOptions: { 6 parser: svelteParser, 7 parserOptions: { 8 parser: tsParser, 9 }, 10 }, 11 }, 12];
For example in .eslintrc.*
:
1{ 2 "parser": "svelte-eslint-parser", 3 "parserOptions": { 4 "parser": "@typescript-eslint/parser" 5 } 6}
If you are using the "@typescript-eslint/parser"
, and if you want to use TypeScript in <script>
of .svelte
, you need to add more parserOptions
configuration.
For example in eslint.config.js
:
1import tsParser from "@typescript-eslint/parser"; 2export default [ 3 // ... 4 { 5 // ... 6 languageOptions: { 7 parser: tsParser, 8 parserOptions: { 9 // ... 10 project: "path/to/your/tsconfig.json", 11 extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0. 12 }, 13 }, 14 }, 15 { 16 files: ["**/*.svelte", "*.svelte"], 17 languageOptions: { 18 parser: svelteParser, 19 // Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration. 20 parserOptions: { 21 parser: tsParser, 22 }, 23 }, 24 // ... 25 }, 26];
For example in .eslintrc.*
:
1module.exports = { 2 // ... 3 parser: "@typescript-eslint/parser", 4 parserOptions: { 5 // ... 6 project: "path/to/your/tsconfig.json", 7 extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0. 8 }, 9 overrides: [ 10 { 11 files: ["*.svelte"], 12 parser: "svelte-eslint-parser", 13 // Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration. 14 parserOptions: { 15 parser: "@typescript-eslint/parser", 16 }, 17 }, 18 // ... 19 ], 20 // ... 21};
If you want to switch the parser for each lang, specify the object.
For example in eslint.config.js
:
1import tsParser from "@typescript-eslint/parser"; 2import espree from "espree"; 3export default [ 4 { 5 files: ["**/*.svelte", "*.svelte"], 6 languageOptions: { 7 parser: svelteParser, 8 parserOptions: { 9 parser: { 10 ts: tsParser, 11 js: espree, 12 typescript: tsParser, 13 }, 14 }, 15 }, 16 }, 17];
For example in .eslintrc.*
:
1{ 2 "parser": "svelte-eslint-parser", 3 "parserOptions": { 4 "parser": { 5 "ts": "@typescript-eslint/parser", 6 "js": "espree", 7 "typescript": "@typescript-eslint/parser" 8 } 9 } 10}
If you are using eslint.config.js
, you can provide a svelte.config.js
in the parserOptions.svelteConfig
property.
For example:
1import svelteConfig from "./svelte.config.js"; 2export default [ 3 { 4 files: ["**/*.svelte", "*.svelte"], 5 languageOptions: { 6 parser: svelteParser, 7 parserOptions: { 8 svelteConfig: svelteConfig, 9 }, 10 }, 11 }, 12];
If parserOptions.svelteConfig
is not specified, some config will be statically parsed from the svelte.config.js
file.
The .eslintrc.*
style configuration cannot load svelte.config.js
because it cannot use ESM. We recommend using the eslint.config.js
style configuration.
You can use parserOptions.svelteFeatures
property to specify how to parse related to Svelte features.
For example in eslint.config.js
:
1export default [ 2 { 3 files: ["**/*.svelte", "*.svelte"], 4 languageOptions: { 5 parser: svelteParser, 6 parserOptions: { 7 svelteFeatures: { 8 /* -- Experimental Svelte Features -- */ 9 /* It may be changed or removed in minor versions without notice. */ 10 // This option is for Svelte 5. The default value is `true`. 11 // If `false`, ESLint will not recognize rune symbols. 12 // If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`. 13 // If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`. 14 runes: true, 15 }, 16 }, 17 }, 18 }, 19];
For example in .eslintrc.*
:
1{ 2 "parser": "svelte-eslint-parser", 3 "parserOptions": { 4 "svelteFeatures": { 5 /* -- Experimental Svelte Features -- */ 6 /* It may be changed or removed in minor versions without notice. */ 7 // This option is for Svelte 5. The default value is `true`. 8 // If `false`, ESLint will not recognize rune symbols. 9 // If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`. 10 // If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`. 11 "runes": true, 12 }, 13 }, 14}
This is an experimental feature. It may be changed or removed in minor versions without notice.
If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse *.js
and *.ts
files.
If you don't want to use Runes, you may need to configure. Please read parserOptions.svelteFeatures for more details.
When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.
For example in eslint.config.js
:
1import svelteConfig from "./svelte.config.js"; 2export default [ 3 { 4 files: ["**/*.svelte", "*.svelte"], 5 languageOptions: { 6 parser: svelteParser, 7 parserOptions: { 8 parser: "...", 9 svelteConfig, 10 /* ... */ 11 }, 12 }, 13 }, 14 { 15 files: ["**/*.svelte.js", "*.svelte.js"], 16 languageOptions: { 17 parser: svelteParser, 18 parserOptions: { 19 svelteConfig, 20 /* ... */ 21 }, 22 }, 23 }, 24 { 25 files: ["**/*.svelte.ts", "*.svelte.ts"], 26 languageOptions: { 27 parser: svelteParser, 28 parserOptions: { 29 parser: "...(ts parser)...", 30 svelteConfig, 31 /* ... */ 32 }, 33 }, 34 }, 35];
For example in .eslintrc.*
:
1{ 2 "overrides": [ 3 { 4 "files": ["*.svelte"], 5 "parser": "svelte-eslint-parser", 6 "parserOptions": { 7 "parser": "...", 8 /* ... */ 9 }, 10 }, 11 { 12 "files": ["*.svelte.js"], 13 "parser": "svelte-eslint-parser", 14 "parserOptions": { 15 /* ... */ 16 }, 17 }, 18 { 19 "files": ["*.svelte.ts"], 20 "parser": "svelte-eslint-parser", 21 "parserOptions": { 22 "parser": "...(ts parser)...", 23 /* ... */ 24 }, 25 }, 26 ], 27}
Use the dbaeumer.vscode-eslint extension that Microsoft provides officially.
You have to configure the eslint.validate
option of the extension to check .svelte
files, because the extension targets only *.js
or *.jsx
files by default.
Example .vscode/settings.json:
1{ 2 "eslint.validate": ["javascript", "javascriptreact", "svelte"] 3}
eslint-plugin-svelte
. The source code for these rules will be helpful to you.Welcome contributing!
Please use GitHub's Issues/PRs.
See also the documentation for the internal mechanism.
See the LICENSE file for license rights and limitations (MIT).
No vulnerabilities found.
No security vulnerabilities found.
@typescript-eslint/parser
An ESLint custom parser which leverages TypeScript ESTree
eslint-plugin-svelte3
An ESLint plugin for Svelte v3 components.
@babel/eslint-parser
ESLint parser that allows for linting of experimental syntax transformed by Babel
vue-eslint-parser
The ESLint custom parser for `.vue` files.