Guide
Install
npm install --save-dev @rsvelte/cli To use typecheck, also install a type checker. In package.json scripts, the command is rsvelte:
{
"scripts": {
"lint": "rsvelte lint",
"format": "rsvelte format",
"typecheck": "rsvelte typecheck"
}
} rsvelte help prints an overview. rsvelte help lint or rsvelte lint --help prints help for one command.
lint
rsvelte lint [oxlint options] [path...] lint is oxlint with a built-in
Svelte linter. It takes oxlint's options (rsvelte lint --help), reads oxlint's
configuration, .oxlintrc.json or oxlint.config.ts (which Node
evaluates), and prints and exits as oxlint does. oxlint checks each file it checks, and the
scripts of each .svelte file, with its own rules. The Svelte linter checks the whole .svelte file with the svelte/ rules, and runs no-unused-vars and no-undef there instead of oxlint, because they read
the template.
The configuration turns Svelte rules on and off as it does oxlint's, under the svelte/ prefix, with no plugins entry. Each rule has one of oxlint's categories, and by default only correctness runs:
{
"categories": { "suspicious": "warn" },
"env": { "browser": true },
"rules": { "svelte/no-at-html-tags": "error", "svelte/no-inspect": "off" },
"settings": { "svelte": { "ignoreWarnings": ["a11y_autofocus"] } }
} The Svelte linter reads settings.svelte as eslint-plugin-svelte does, the globals of env and globals, and the nearest svelte.config.js. A Svelte
rule that also applies to scripts, such as svelte/no-inspect, also checks JavaScript
and TypeScript files. In .svelte.js and .svelte.ts modules, oxlint's
rules read the runes as globals.
Comments such as // oxlint-disable-next-line turn off a Svelte rule as they turn off
one of oxlint's. In the markup, write them as HTML comments: <!-- oxlint-disable-next-line -->.
format
rsvelte format [path...] [--check] format is oxfmt, the
formatter of the oxc project, with a built-in Svelte formatter. It accepts oxfmt's options (rsvelte format --help). It reads its settings from .oxfmtrc.json or oxfmt.config.ts, which
it runs with node, and from .editorconfig. It reads the files to skip
from .prettierignore. With --check, it writes nothing and lists the
files that need formatting.
It formats each file that oxfmt formats itself, such as TypeScript, JSON, CSS and Markdown. It
also formats the svelte code blocks in Markdown. It skips the files that oxfmt hands
to Prettier.
It formats Svelte files with every option that oxfmt gives prettier-plugin-svelte. It applies sortImports, jsdoc and sortTailwindcss to them as oxfmt
does. "svelte": false in the configuration turns Svelte formatting off. Like oxfmt,
it refuses a configuration that sets experimentalTernaries, which oxc does not print
yet.
typecheck
rsvelte typecheck typecheck type checks the files that a tsconfig.json selects, and
reports the errors that svelte-check reports. It takes no paths. It prints one error per line, as tsc --pretty false does.
It runs a TypeScript 7 type checker from the project's node_modules. Install one of
these. The project also needs svelte.
npm install --save-dev tsrs # recommended: a Rust port of TypeScript 7
npm install --save-dev typescript # 7.1 or newer
npm install --save-dev @typescript/native-preview # 7.1 or newer The typescript.check entry of rsvelte.config.json (see Configuration) picks the tsconfig.json:
- No configuration file, or no
typescript.check: thetsconfig.jsonin the current directory. typescript.checkwith"tsconfig": the file at that path.typescript.checkwithout"tsconfig": thetsconfig.jsonnext to the configuration file.
Configuration
typecheck reads rsvelte.config.json. The file can also be a rsvelte.config.js or rsvelte.config.ts, which Node evaluates. rsvelte
looks for the file in the current directory, then in each parent. Use --config <file> to choose a file. Two configuration files in one directory are
an error. lint reads .oxlintrc.json and format reads .oxfmtrc.json instead.
{
"plugins": {
"typescript.check": { "tsconfig": "tsconfig.app.json" }
}
} typescript.check takes command, the type checker. Without it, rsvelte
runs the first of tsrs, @typescript/native-preview and typescript that the project installs. It also takes tsconfig, the tsconfig.json to check. Paths start from the directory of the configuration file. An
unknown key is an error. The configuration reference lists every option.
Exit codes
| Command | 1 | 2 |
|---|---|---|
lint | It found an error, or a warning with --deny-warnings, or the oxlint
configuration is invalid | - |
typecheck | It found an error (warnings alone exit with 0) | It could not run |
format | --check found a file to format, or the oxfmt configuration is invalid | format failed on a file (for example, because of an unsupported Svelte option),
or no path matched a file |
With ESLint
@rsvelte/eslint-plugin turns
off the ESLint rules that rsvelte adds to oxlint, and eslint-plugin-oxlint those of
oxlint, so you see each problem once. Use the version of @rsvelte/eslint-plugin that
matches @rsvelte/cli.
npm install --save-dev @rsvelte/eslint-plugin eslint-plugin-oxlint // eslint.config.js
import svelte from 'eslint-plugin-svelte';
import oxlint from 'eslint-plugin-oxlint';
import rsvelte from '@rsvelte/eslint-plugin';
export default [
...svelte.configs.recommended,
...oxlint.buildFromOxlintConfigFile('./.oxlintrc.json'),
...rsvelte.buildFromOxlintConfigFile('./.oxlintrc.json'), // last
]; Each turns off the rules your .oxlintrc.json turns on. rsvelte.configs['flat/recommended'] instead turns off the rules of the correctness category, and flat/all every rule outside the nursery category of rules in
development.
A script that runs both: "lint": "rsvelte lint && eslint"
Svelte 4 and legacy mode
rsvelte supports Svelte 5 components in runes mode only. A component that uses one of these is in legacy mode:
export let$:$$props$$restProps<svelte:options runes={false} />
typecheckgives wrong results for a component in legacy mode. For one without<script lang="ts">, it can report no error at all.lintandformatread legacy syntax, but their results can differ from the official tools.
For a Svelte 4 project, use the official tools: svelte-check, eslint-plugin-svelte and prettier-plugin-svelte.