# Introduction `eslint-plugin-svelte` is the official [ESLint] plugin for [Svelte]. It provides many unique check rules by using the template AST. You can check on the [Online DEMO](https://sveltejs.github.io/eslint-plugin-svelte/playground/). [![NPM license](https://img.shields.io/npm/l/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte) [![NPM version](https://img.shields.io/npm/v/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte) [![NPM downloads](https://img.shields.io/badge/dynamic/json.svg?label=downloads&colorB=green&suffix=/day&query=$.downloads&uri=https://api.npmjs.org//downloads/point/last-day/eslint-plugin-svelte&maxAge=3600)](http://www.npmtrends.com/eslint-plugin-svelte) [![NPM downloads](https://img.shields.io/npm/dw/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte) [![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte) [![NPM downloads](https://img.shields.io/npm/dy/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte) [![NPM downloads](https://img.shields.io/npm/dt/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte) [![Build Status](https://github.com/sveltejs/eslint-plugin-svelte/workflows/CI/badge.svg?branch=main)](https://github.com/sveltejs/eslint-plugin-svelte/actions?query=workflow%3ACI) [![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fsveltejs%2Feslint-plugin-svelte%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage) [![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/atlassian/changesets) ## :name_badge: What is this plugin? [ESLint] plugin for [Svelte]. It provides many unique check rules using the AST generated by [svelte-eslint-parser]. ### ❗ Attention The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3]. [svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser [eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3 ## Migration Guide To migrate from `eslint-plugin-svelte` v1, or [`@ota-meshi/eslint-plugin-svelte`](https://www.npmjs.com/package/@ota-meshi/eslint-plugin-svelte), please refer to the [migration guide](https://sveltejs.github.io/eslint-plugin-svelte/migration/). ## :book: Documentation See [documents](https://sveltejs.github.io/eslint-plugin-svelte/). ## :cd: Installation ```bash npm install --save-dev eslint eslint-plugin-svelte svelte ``` > **Requirements** > > - ESLint v7.0.0 and above > - Node.js v14.17.x, v16.x and above ## :book: Usage ### Configuration Use `.eslintrc.*` file to configure rules. See also: . Example **.eslintrc.js**: ```js module.exports = { extends: [ // add more generic rule sets here, such as: // 'eslint:recommended', 'plugin:svelte/recommended' ], rules: { // override/add rules settings here, such as: // 'svelte/rule-name': 'error' } }; ``` This plugin provides configs: - `plugin:svelte/base` ... Configuration to enable correct Svelte parsing. - `plugin:svelte/recommended` ... Above, plus rules to prevent errors or unintended behavior. - `plugin:svelte/prettier` ... Turns off rules that may conflict with [Prettier](https://prettier.io/) (You still need to configure prettier to work with svelte yourself, for example by using [prettier-plugin-svelte](https://github.com/sveltejs/prettier-plugin-svelte).). - `plugin:svelte/all` ... All rules. This configuration is not recommended for production use because it changes with every minor and major version of `eslint-plugin-svelte`. Use it at your own risk. See [the rule list](https://sveltejs.github.io/eslint-plugin-svelte/rules/) to get the `rules` that this plugin provides. ::: warning ❗ Attention The `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3]. If you are using [eslint-plugin-svelte3] you need to remove it. ```diff "plugins": [ - "svelte3" ] ``` ::: #### Parser Configuration If you have specified a parser, you need to configure a parser for `.svelte`. For example, if you are using the `"@babel/eslint-parser"`, configure it as follows: ```js module.exports = { // ... extends: ['plugin:svelte/recommended'], // ... parser: '@babel/eslint-parser', // Add an `overrides` section to add a parser configuration for svelte. overrides: [ { files: ['*.svelte'], parser: 'svelte-eslint-parser' } // ... ] // ... }; ``` For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `