@zerebos/eslint-config-svelte
v1.0.1
Published
An opinionated config for an opinionated person
Maintainers
Readme
@zerebos/eslint-config-svelte
A comprehensive ESLint configuration for Svelte projects with TypeScript support.
Features
- 🚀 Built on top of the official
eslint-plugin-svelterecommended config - 📝 TypeScript support with
typescript-eslintintegration - 🔒 Security-focused rules (no
@htmltags, target="_blank" protection) - 🎨 Consistent code style and formatting
- ⚡ Performance optimizations
- 🧹 Best practices enforcement
Installation
npm install -D @zerebos/eslint-config-svelte eslintPeer Dependencies
This config requires the following peer dependencies:
npm install -D eslint-plugin-svelte typescript-eslintUsage
Basic Setup
Create an eslint.config.js file in your project root:
import { build } from "@zerebos/eslint-config-svelte";
export default build();With Custom Svelte Config
If you have a custom svelte.config.js, pass it to the build function:
import { build } from "@zerebos/eslint-config-svelte";
import svelteConfig from "./svelte.config.js";
export default build(svelteConfig);Extending the Configuration
You can extend or override rules as needed:
import { build } from "@zerebos/eslint-config-svelte";
export default [
...build(),
{
rules: {
// Override or add custom rules
"svelte/no-at-debug-tags": "warn", // Change from error to warning
"svelte/prefer-style-directive": "off", // Disable rule
}
}
];What's Included
File Targeting
**/*.svelte- Svelte component files**/*.svelte.ts- TypeScript files in Svelte components
Key Rules
Error-Level Rules
- Component Logic: Prevents infinite reactive loops, invalid reactive statements
- Template Safety: Blocks dangerous HTML injection, ensures proper event handlers
- TypeScript Integration: Enforces TypeScript in script blocks
- Store Patterns: Validates Svelte store usage and patterns
- Accessibility: Button type requirements, proper ARIA usage
Style & Consistency
- HTML Formatting: Consistent quote style, self-closing tags, spacing
- Attribute Organization: Proper linebreaks and spacing for readability
- Directive Usage: Prefers shorthand syntax where applicable
- Comment Standards: Consistent comment formatting
Security
svelte/no-at-html-tags: Prevents XSS vulnerabilitiessvelte/no-target-blank: Protects against reverse tabnabbing
Configuration Details
TypeScript Setup
This configuration assumes you're using TypeScript and enforces:
"block-lang": ["error", {script: "ts"}]- Requires TypeScript in script blocks- Proper TypeScript parser integration with Svelte files
Disabled Rules
svelte/no-dom-manipulating: Disabled to allow direct DOM manipulation when neededsvelte/no-inline-styles: Disabled for flexibilitysvelte/indent: Disabled to avoid conflicts with Prettiersvelte/max-attributes-per-line: Disabled for developer preferencesvelte/sort-attributes: Disabled to allow manual organization
Integration with Other Tools
Prettier
This config is designed to work alongside Prettier. Make sure to install:
npm install -D prettier prettier-plugin-svelteVS Code
For the best experience, install these VS Code extensions:
Add to your VS Code settings:
{
"eslint.validate": ["svelte"],
"svelte.enable-ts-plugin": true
}Common Issues
TypeScript Errors
If you're seeing TypeScript-related errors, ensure:
- You have a valid
tsconfig.jsonin your project - Your
svelte.config.jsincludes proper TypeScript preprocessing - You've installed
typescriptand@tsconfig/svelte
Parser Errors
If ESLint can't parse your Svelte files:
- Ensure
eslint-plugin-svelteis installed - Check that your
eslint.config.jsis using this config correctly - Verify your Svelte version compatibility
Example Project Structure
my-svelte-project/
├── src/
│ ├── lib/
│ │ └── Component.svelte
│ ├── routes/
│ │ └── +page.svelte
│ └── app.html
├── eslint.config.js
├── svelte.config.js
├── tsconfig.json
└── package.jsonContributing
Issues and pull requests are welcome! Please check the main repository for contribution guidelines.
Related Packages
@zerebos/eslint-config- Base ESLint configuration@zerebos/eslint-config-typescript- TypeScript ESLint configuration
