All Projects → ota-meshi → svelte-eslint-parser

ota-meshi / svelte-eslint-parser

Licence: MIT license
Svelte parser for ESLint

Programming Languages

typescript
32286 projects
Svelte
593 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to svelte-eslint-parser

eslint-plugin-svelte
ESLint plugin for Svelte using AST
Stars: ✭ 22 (-26.67%)
Mutual labels:  eslint, svelte, sveltejs
kahi-ui
Straight-forward Svelte UI for the Web
Stars: ✭ 169 (+463.33%)
Mutual labels:  svelte, sveltejs
ctx-core
A composable monorepo web-service/front-end toolkit
Stars: ✭ 25 (-16.67%)
Mutual labels:  svelte, sveltejs
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (+130%)
Mutual labels:  svelte, sveltejs
svelte-color-picker
A color picker component for svelte
Stars: ✭ 96 (+220%)
Mutual labels:  svelte, sveltejs
hagura-sveltekit
A minimal markdown blog template built using SvelteKit
Stars: ✭ 51 (+70%)
Mutual labels:  svelte, sveltejs
aqua-fanpage
⚓ 湊あくあ Fanpage created with Svelte and Sveltestrap.
Stars: ✭ 30 (+0%)
Mutual labels:  svelte, sveltejs
fastify-vite
This plugin lets you load a Vite client application and set it up for Server-Side Rendering (SSR) with Fastify.
Stars: ✭ 497 (+1556.67%)
Mutual labels:  svelte, sveltejs
ModalFileManager
A file manager built using Svelte and Wails. It has hotkeys that are modal just like Vim and NeoVim.
Stars: ✭ 21 (-30%)
Mutual labels:  svelte, sveltejs
svelte-typewriter
A simple and reusable typewriter effect for your Svelte applications
Stars: ✭ 204 (+580%)
Mutual labels:  svelte, sveltejs
svelte-accessible-dialog
An accessible dialog component for Svelte apps
Stars: ✭ 24 (-20%)
Mutual labels:  svelte, sveltejs
sveltekit-blog
Sveltekit blog starter project created with sveltekit, typescript, tailwindcss, postcss, husky, and storybook. The project has the structure set up for the scaleable web application.
Stars: ✭ 100 (+233.33%)
Mutual labels:  svelte, sveltejs
svelte-portal
Svelte component for rendering outside the DOM of parent component
Stars: ✭ 261 (+770%)
Mutual labels:  svelte, sveltejs
sdk-for-svelte
Appwrite SDK for Svelte 🧡 ⚠️ Warning - this SDK was designed to support Appwrite 0.9 and is not compatible with the latest Appwrite versions. We are planing to refactor it as part of the SDK Generator for better support and maintenance.
Stars: ✭ 69 (+130%)
Mutual labels:  svelte, sveltejs
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (+60%)
Mutual labels:  svelte, sveltejs
d3-fdg-svelte
d3 Force Directed Graph example (d3-force) implemented in sveltejs. REPL:
Stars: ✭ 31 (+3.33%)
Mutual labels:  svelte, sveltejs
svelte-undoable
Memento design pattern in Svelte
Stars: ✭ 39 (+30%)
Mutual labels:  svelte, sveltejs
fa-svelte
Font Awesome 5 for svelte.js
Stars: ✭ 72 (+140%)
Mutual labels:  svelte, sveltejs
SvelteTetris
Basic Tetris game created with Svelte
Stars: ✭ 21 (-30%)
Mutual labels:  svelte, sveltejs
s-date-range-picker
📅 A date range picker built with Svelte
Stars: ✭ 13 (-56.67%)
Mutual labels:  svelte, sveltejs

svelte-eslint-parser

Svelte parser for ESLint.
You can check it on Online DEMO.

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

Why?

Svelte has the official ESLint plugin the eslint-plugin-svelte3. The eslint-plugin-svelte3 works well enough to check scripts. However, it does not handle the AST of the template, which makes it very difficult for third parties to create their own the ESLint rules for the Svelte.

The svelte-eslint-parser aims to make it easy to create your own rules for the Svelte by allowing the template AST to be used in the rules.

The eslint-plugin-svelte is an ESLint plugin that uses the svelte-eslint-parser. I have already implemented some rules.

Benefits of Using AST

ESLint Plugins Using svelte-eslint-parser

eslint-plugin-svelte

ESLint plugin for Svelte.
It provides many unique check rules by using the template AST.

@intlify/eslint-plugin-svelte

ESLint plugin for internationalization (i18n) with Svelte.
It provides rules to help internationalization your application created with Svelte.

Attention

The svelte-eslint-parser can not be used with the eslint-plugin-svelte3.

💿 Installation

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

📖 Usage

  1. Write overrides.parser option into your .eslintrc.* file.
  2. Use glob patterns or --ext .svelte CLI option.
{
    "extends": "eslint:recommended",
    "overrides": [
        {
            "files": ["*.svelte"],
            "parser": "svelte-eslint-parser"
        }
    ]
}
$ eslint "src/**/*.{js,svelte}"
# or
$ eslint src --ext .svelte

🔧 Options

parserOptions has the same properties as what espree, 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
        }
    }
}

parserOptions.parser

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:

{
    "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 more parserOptions 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",
      },
    },
    // ...
  ],
  // ...
}

Multiple parsers

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"
        }
    }
}

💻 Editor Integrations

Visual Studio Code

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:

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

Usage for Custom Rules / Plugins

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

See also the documentation for the internal mechanism.

🔒 License

See the LICENSE file for license rights and limitations (MIT).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].