Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork25
sveltejs/svelte-eslint-parser
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Svelte parser forESLint.
You can check it onOnline DEMO.
Thesvelte-eslint-parser aims to make it easy to create your own ESLint rules forSvelte.
Theeslint-plugin-svelte is an ESLint plugin that uses thesvelte-eslint-parser. I have alreadyimplemented 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.
Thesvelte-eslint-parser can not be used with theeslint-plugin-svelte3.
npm install --save-dev eslint svelte-eslint-parser
- Write
overrides.parseroption into your.eslintrc.*file. - Use glob patterns or
--ext .svelteCLI option.
{"extends":"eslint:recommended","overrides": [ {"files": ["*.svelte"],"parser":"svelte-eslint-parser" } ]}$eslint"src/**/*.{js,svelte}"#or$eslint src --ext .svelte
parserOptions has the same properties as whatespree, the default parser of ESLint, is supporting.For example:
{"parser":"svelte-eslint-parser","parserOptions": {"sourceType":"module","ecmaVersion":2021,"ecmaFeatures": {"globalReturn":false,"impliedStrict":false,"jsx":false } }}You can useparserOptions.parser property to specify a custom parser to parse<script> tags.Other properties than parser would be given to the specified parser.For example:
{"parser":"svelte-eslint-parser","parserOptions": {"parser":"@typescript-eslint/parser" }}For example, if you are using the"@typescript-eslint/parser", and if you want to use TypeScript in<script> of.svelte, you need to add moreparserOptions configuration.
module.exports={// ...parser:"@typescript-eslint/parser",parserOptions:{// ...project:"path/to/your/tsconfig.json",extraFileExtensions:[".svelte"],// This is a required setting in `@typescript-eslint/parser` v4.24.0.},overrides:[{files:["*.svelte"],parser:"svelte-eslint-parser",// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.parserOptions:{parser:"@typescript-eslint/parser",},},// ...],// ...}
If you want to switch the parser for each lang, specify the object.
{"parser":"svelte-eslint-parser","parserOptions": {"parser": {"ts":"@typescript-eslint/parser","js":"espree","typescript":"@typescript-eslint/parser" } }}When using JavaScript configuration (.eslintrc.js), you can also give the parser object directly.
consttsParser=require("@typescript-eslint/parser")constespree=require("espree")module.exports={parser:"svelte-eslint-parser",parserOptions:{// Single parserparser:tsParser,// Multiple parserparser:{js:espree,ts:tsParser,}},}
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.
When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.
{"overrides": [ {"files": ["*.svelte"],"parser":"svelte-eslint-parser","parserOptions": {"parser":"...",... } }, {"files": ["*.svelte.js"],"parser":"svelte-eslint-parser","parserOptions": {... } }, {"files": ["*.svelte.ts"],"parser":"svelte-eslint-parser","parserOptions": {"parser":"...(ts parser)...",... } } ]}Use thedbaeumer.vscode-eslint extension that Microsoft provides officially.
You have to configure theeslint.validate option of the extension to check.svelte files, because the extension targets only*.js or*.jsx files by default.
Example.vscode/settings.json:
{"eslint.validate": ["javascript","javascriptreact","svelte" ]}- AST.md is AST specification. You can check it on theOnline DEMO.
- The parser will generate its ownScopeManager. You can check it on theOnline DEMO.
- I have alreadyimplemented some rules in the
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 theLICENSE file for license rights and limitations (MIT).
About
Svelte parser for ESLint
Topics
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors13
Uh oh!
There was an error while loading.Please reload this page.