ESLint plugin for Svelte applications providing comprehensive linting rules and configurations using AST parsing
npx @tessl/cli install tessl/npm-eslint-plugin-svelte@3.12.0ESLint plugin for Svelte applications providing comprehensive linting rules and configurations using AST parsing. It leverages the AST generated by svelte-eslint-parser to deliver custom linting for Svelte's unique syntax and component structure.
npm install --save-dev eslint-plugin-svelteimport svelte from "eslint-plugin-svelte";For individual components:
import { configs, rules, meta, processors } from "eslint-plugin-svelte";// eslint.config.js
import js from '@eslint/js';
import svelte from 'eslint-plugin-svelte';
import globals from 'globals';
export default [
js.configs.recommended,
...svelte.configs.recommended,
{
languageOptions: {
globals: {
...globals.browser,
...globals.node
}
}
}
];// eslint.config.js
import js from '@eslint/js';
import svelte from 'eslint-plugin-svelte';
import ts from 'typescript-eslint';
export default ts.config(
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs.recommended,
{
files: ['**/*.svelte', '**/*.svelte.ts'],
languageOptions: {
parserOptions: {
projectService: true,
extraFileExtensions: ['.svelte']
}
}
}
);eslint-plugin-svelte is structured around four main components:
Predefined ESLint configurations optimized for Svelte development with different rule sets and compatibility options.
interface PluginConfigs {
base: Linter.Config[];
recommended: Linter.Config[];
prettier: Linter.Config[];
all: Linter.Config[];
'flat/base': Linter.Config[];
'flat/recommended': Linter.Config[];
'flat/prettier': Linter.Config[];
'flat/all': Linter.Config[];
}Comprehensive collection of ESLint rules specifically designed for Svelte applications, covering security, best practices, styling, and Svelte-specific patterns.
interface PluginRules extends Record<string, Rule.RuleModule> {
// 79 individual rules available
'no-at-html-tags': Rule.RuleModule;
'prefer-class-directive': Rule.RuleModule;
'valid-compile': Rule.RuleModule;
// ... and 76 more rules
}Custom ESLint processor for handling Svelte files, supporting comment directives and proper AST parsing.
interface SvelteProcessor {
preprocess(code: string, filename: string): string[];
postprocess(messages: Linter.LintMessage[][], filename: string): Linter.LintMessage[];
supportsAutofix: boolean;
meta: {
name: string;
version: string;
};
}interface PluginMeta {
name: "eslint-plugin-svelte";
version: "3.12.1";
}interface ESLintPluginSvelte {
configs: PluginConfigs;
rules: PluginRules;
meta: PluginMeta;
processors: {
'.svelte': SvelteProcessor;
svelte: SvelteProcessor;
};
}interface RuleModule {
meta: RuleMetaData;
create: (context: RuleContext) => RuleListener;
}
interface RuleMetaData {
docs: {
description: string;
category: RuleCategory;
recommended: boolean | 'base';
url: string;
ruleId: string;
ruleName: string;
};
messages: { [messageId: string]: string };
fixable?: 'code' | 'whitespace';
hasSuggestions?: boolean;
schema: JSONSchema4 | JSONSchema4[];
type: 'problem' | 'suggestion' | 'layout';
}
type RuleCategory =
| 'Possible Errors'
| 'Security Vulnerability'
| 'Best Practices'
| 'Stylistic Issues'
| 'Extension Rules'
| 'SvelteKit'
| 'Experimental'
| 'System';interface RuleContext {
id: string;
options: any[];
settings?: {
svelte?: {
ignoreWarnings?: unknown;
compileOptions?: {
babel?: boolean;
postcss?: false | { configFilePath?: unknown };
};
kit?: {
files?: {
routes?: string;
};
};
};
};
filename: string;
sourceCode: SourceCode;
report(descriptor: ReportDescriptor): void;
}