svelte · patrickjs — Cursor rule: Svelte best practices
A Cursor rule that steers the agent toward Svelte conventions: component structure, reactivity, stores, SvelteKit routing and tests. Useful when the agent writes or edits Svelte code.
.cursor/rules/svelte.mdcWhat svelte does
The file tells Cursor what to follow when it touches .svelte files and src/**/*.ts or src/**/*.js. Sections cover component structure, reactive declarations, stores, performance, routing, forms, TypeScript types, testing and build tooling. Routing points at SvelteKit, the build section at Vite.
The rule does not apply project-wide: it carries alwaysApply: false and relies on globs instead. So it only fires on files that match those patterns. Worth checking if your components live outside src — the globs would need editing.
Installation is one file at .cursor/rules/svelte.mdc. No dependencies, no API keys; the content is plain markdown with frontmatter.
What it helps with
- keep Svelte components small and single-purpose
- type props and events for TypeScript
- split state into modular stores
- set up routing and layouts with SvelteKit
- cover components and stores with tests
Example prompts for the agent
- add a new form component with validation following the svelte rule
- rewrite this store using derived values and subscriptions
- check this file for unnecessary reactivity against the svelte rule
How to install svelte
Manually: put the files in place
.cursor/rules/svelte.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/svelte.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/svelte.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/svelte.mdManually: put the files in place
.clinerules/svelte.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about svelte
How do I install svelte in Cursor?
Create .cursor/rules/svelte.mdc and paste the rule content into it. That is the whole setup.
What does the svelte rule do?
It gives Cursor conventions for Svelte code: component structure, reactivity, stores, routing, forms, types, testing and build setup.
When does the rule apply?
It sets alwaysApply: false, so it only applies to files matching **/*.svelte, src/**/*.ts and src/**/*.js.
Source text
svelte.mdc · CC0-1.0
--- description: "Svelte best practices and patterns for modern web applications" globs: **/*.svelte, src/**/*.ts, src/**/*.js alwaysApply: false --- # Svelte Best Practices ## Component Structure - Keep components small and focused - Use proper TypeScript integration - Implement proper props typing - Use proper event dispatching - Keep markup clean and readable - Use proper slot implementation ## Reactivity - Use proper reactive declarations - Implement proper stores - Use proper reactive statements - Handle derived values properly - Use proper lifecycle functions - Implement proper bindings ## State Management - Use proper Svelte stores - Keep stores modular - Use proper derived stores - Implement proper actions - Handle async state properly - Use proper store subscriptions ## Performance - Use proper component lazy loading - Implement proper transitions - Use proper animations - Avoid unnecessary reactivity - Use proper event forwarding - Implement proper key blocks ## Routing - Use SvelteKit for routing - Implement proper layouts - Use proper route parameters - Handle loading states properly - Implement proper error pages - Use proper navigation methods ## Forms - Use proper form bindings - Implement proper validation - Handle form submission properly - Show proper loading states - Use proper error handling - Implement proper form reset ## TypeScript Integration - Use proper component types - Implement proper prop types - Use proper event types - Handle proper type inference - Use proper store types - Implement proper action types ## Testing - Write proper unit tests - Implement proper component tests - Use proper testing libraries - Test stores properly - Implement proper mocking - Test async operations ## Best Practices - Follow Svelte style guide - Use proper naming conventions - Keep components organized - Implement proper error handling - Use proper event handling - Document complex logic ## Build and Tooling - Use Vite for development - Configure proper build setup - Use proper environment variables - Implement proper code splitting - Use proper asset handling - Configure proper optimization
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules
Similar IDE rules
All IDE rules for Frontend and UI →svelte by other authors comes first.