Svelte Editor Tools

The Svelte for VS Code extension gives your editor a full understanding of .svelte files. Open the Extensions panel, search for Svelte for VS Code, and press Install. The extension highlights markup, script, and style sections inside a single file, so each part carries its own colors.

The extension runs the Svelte language server in the background. The server reads your component, checks it, and sends hints back to the editor. Autocomplete suggests props and imports, hover cards describe variables, and a click on a component name jumps to its file. Editors such as Neovim, Sublime Text, and the JetBrains family connect to the same language server through their own plugins.

Editor Feedback Diagram

You type code in App.svelte
        |
        v
Svelte Language Server reads the file
        |
        +--> Autocomplete suggestions
        +--> Hover descriptions
        +--> Red and yellow underlines
        |
        v
You fix the issue before opening the browser

Formatting With Prettier

Prettier rewrites code into one consistent layout. The Svelte plugin teaches Prettier how to handle markup, blocks, and styles in .svelte files. Install both packages as development tools.

npm install --save-dev prettier prettier-plugin-svelte

Create a file named .prettierrc in the project root and register the plugin.

{
  "plugins": ["prettier-plugin-svelte"],
  "overrides": [
    { "files": "*.svelte", "options": { "parser": "svelte" } }
  ]
}

VS Code settings can format every file on save. Add these lines to your settings file, and the editor tidies each component whenever you press save.

{
  "editor.formatOnSave": true,
  "[svelte]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

Checking Code With svelte-check

The svelte-check command scans the whole project and reports problems in one list. It finds type errors, unused CSS selectors, and accessibility issues such as an image without alt text. Run it from the project root.

npx svelte-check

Projects created with the official sv tool usually include a check script in package.json, so npm run check performs the same scan. Many teams run this command before every commit.

Linting With ESLint

ESLint enforces coding rules. The eslint-plugin-svelte package adds rules written for Svelte syntax. One rule asks for a key in each block, and another warns about unsafe HTML output. Linting catches habits that cause bugs long before users meet them.

Browser Feedback While You Work

The Vite development server refreshes the page each time you save, and it keeps component state in many cases. The browser console shows Svelte warnings during development, including accessibility hints. Keep the console open while you build, since it works as a second reviewer.

A Layman Analogy

Picture a writer preparing a book. A spell checker underlines misspelled words, a style guide keeps formatting consistent, and a proofreader scans the finished manuscript. The language server acts as the spell checker, Prettier acts as the style guide, and svelte-check acts as the proofreader.

Tool Summary

Tool                  Job                          When It Runs
--------------------  ---------------------------  ------------------
Svelte extension      Highlight and autocomplete   While you type
Prettier              Format code                  On save
svelte-check          Find type and a11y issues    On demand
ESLint                Enforce coding rules         On save or commit

Common Mistakes To Avoid

  • Skipping the Prettier plugin and wondering why .svelte files stay unformatted
  • Ignoring yellow underlines that point to real accessibility problems
  • Installing two competing Svelte extensions in the same editor

Key Points

  • The Svelte extension provides highlighting, autocomplete, and diagnostics
  • Prettier with the Svelte plugin keeps every file consistent
  • svelte-check scans the whole project for errors and warnings
  • ESLint adds Svelte-aware rules for cleaner code