Gathering detailed insights and metrics for prettier-plugin-svelte
Gathering detailed insights and metrics for prettier-plugin-svelte
Format your svelte components using prettier.
npm install prettier-plugin-svelte
Typescript
Module System
Node Version
NPM Version
96
Supply Chain
98.8
Quality
87.7
Maintenance
100
Vulnerability
99.6
License
TypeScript (64.61%)
HTML (34.44%)
JavaScript (0.95%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
38,551,191
Last Day
27,038
Last Week
456,754
Last Month
1,797,720
Last Year
18,231,418
MIT License
758 Stars
348 Commits
98 Forks
14 Watchers
5 Branches
44 Contributors
Updated on Feb 17, 2025
Minified
Minified + Gzipped
Latest Version
3.3.3
Package Id
prettier-plugin-svelte@3.3.3
Unpacked Size
1.43 MB
Size
283.50 kB
File Count
7
NPM Version
10.8.2
Node Version
20.18.0
Published on
Jan 13, 2025
Cumulative downloads
Total Downloads
Last Day
-6.2%
27,038
Compared to previous day
Last Week
2.9%
456,754
Compared to previous week
Last Month
30.3%
1,797,720
Compared to previous month
Last Year
60.7%
18,231,418
Compared to previous year
Format your Svelte components using Prettier.
{}
, event bindings on:click=""
, and moreThis plugin is bundled in the Svelte for VS Code extension. If you only format through the editor, you therefore don't need to do anything in addition.
The extension lets you define options through extension-specific configuration. These settings are ignored however if there's any configuration file (.prettierrc
for example) present.
Installing the plugin as a package allows:
prettier-plugin-svelte@3
only works with prettier@3
prettier-plugin-svelte@2
only works with prettier@2
Install Prettier and the plugin as a dev dependency:
1npm i --save-dev prettier-plugin-svelte prettier
Then create a .prettierrc
configuration file:
1// .prettierrc 2{ 3 // .. 4 "plugins": ["prettier-plugin-svelte"], 5 "pluginSearchDirs": ["."], // should be removed in v3 6 "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] 7}
If you want to customize some formatting behavior, see section Options.
Format your code using the Prettier CLI.
1npx prettier --write . # v3 2npx prettier --write --plugin prettier-plugin-svelte . # v2
As part of your scripts in package.json
:
1// package.json 2{ 3 // .. 4 "scripts": { 5 "format": "prettier --write .", // v3 6 "format": "prettier --write --plugin prettier-plugin-svelte ." // v2 7 } 8}
If you want to customize some formatting behavior, see section Options.
Configurations are optional
Make a .prettierrc
file in your project directory and add your preferred options to configure Prettier. When using Prettier through the CLI, you can also pass options through CLI flags, but a .prettierrc
file is recommended.
Sort order for svelte:options
, scripts, markup, and styles.
Format: join the keywords options
, scripts
, markup
, styles
with a -
in the order you want; or none
if you don't want Prettier to reorder anything.
Default | CLI Override | API Override |
---|---|---|
options-scripts-markup-styles | --svelte-sort-order <string> | svelteSortOrder: <string> |
The
options
order option only exists since version 2. If you use version 1 ofprettier-plugin-svelte
, omit that option (so for example only writescripts-markup-styles
).
More strict HTML syntax: Quotes in attributes and no self-closing DOM elements (except void elements).
In version 2 this overruled
svelteAllowShorthand
, which is no longer the case.
In Svelte 5, attributes are never quoted, because this will mean "stringify this attribute value" in a future Svelte version
Example:
1<!-- svelteStrictMode: true (Svelte 3 and 4) --> 2<div foo="{bar}"></div> 3<!-- svelteStrictMode: true (Svelte 5) --> 4<div foo={bar}></div> 5 6<!-- svelteStrictMode: false --> 7<div foo={bar} />
Default | CLI Override | API Override |
---|---|---|
false | --svelte-strict-mode <bool> | svelteStrictMode: <bool> |
Option to enable/disable component attribute shorthand if attribute name and expression are same.
Example:
1<!-- allowShorthand: true --> 2<input type="text" {value} /> 3 4<!-- allowShorthand: false --> 5<input type="text" value={value} />
Default | CLI Override | API Override |
---|---|---|
true | --svelte-allow-shorthand <bool> | svelteAllowShorthand: <bool> |
Deprecated since 2.5.0. Use Prettier 2.4.0 and bracketSameLine instead.
Put the >
of a multiline element on a new line. Roughly the Svelte equivalent of the jsxBracketSameLine rule. Setting this to false
will have no effect for whitespace-sensitive tags (inline elements) when there's no whitespace between the >
of the start tag and the inner content, or when there's no whitespace after the >
of the end tag. You can read more about HTML whitespace sensitivity here. You can adjust whitespace sensitivity through this setting.
Example:
1<!-- before formatting --> 2<span><div>foo</div><span>bar</span></span> 3<div pretend break>content</div> 4 5<!-- after formatting, svelteBracketNewLine true --> 6<span 7 ><div>foo</div> 8 <span>bar</span></span 9> 10<div 11 pretend 12 break 13> 14 content 15</div> 16 17<!-- after formatting, svelteBracketNewLine false --> 18<span 19 ><div>foo</div> 20 <span>bar</span></span> 21<div 22 pretend 23 break> 24 content 25</div>
Default | CLI Override | API Override |
---|---|---|
true | --svelte-bracket-new-line <bool> | svelteBracketNewLine: <bool> |
Whether or not to indent the code inside <script>
and <style>
tags in Svelte files. This saves an indentation level, but might break code folding in your editor.
Default | CLI Override | API Override |
---|---|---|
true | --svelte-indent-script-and-style <bool> | svelteIndentScriptAndStyle: <bool> |
.prettierrc
example1{ 2 "svelteSortOrder": "options-styles-scripts-markup", 3 "svelteStrictMode": true, 4 "svelteBracketNewLine": false, 5 "svelteAllowShorthand": false, 6 "svelteIndentScriptAndStyle": false 7}
1// .prettierrc 2{ 3 // .. 4 "plugins": [ 5 "prettier-plugin-svelte", 6 "prettier-plugin-tailwindcss" // MUST come last 7 ] 8}
Since we are using configuration overrides to handle svelte files, you might also have to configure the prettier.documentselectors in your VS Code settings.json
, to tell Prettier extension to handle svelte files, like this:
1// settings.json 2{ 3 // .. 4 "prettier.documentSelectors": ["**/*.svelte"] 5}
Usage in the browser is semi-supported. You can import the plugin from prettier-plugin-svelte/browser
to get a version that depends on prettier/standalone
and therefore doesn't use any node APIs. What isn't supported in a good way yet is using this without a build step - you still need a bundler like Vite to build everything together as one self-contained package in advance.
1# package.json 2- "format": "prettier --plugin-search-dir . --write ." 3+ "format": "prettier --write ."
1# package.json 2- "prettier": "^2.8.8", 3+ "prettier": "^3.1.0", 4- "prettier-plugin-svelte": "^2.10.1", 5+ "prettier-plugin-svelte": "^3.1.0",
1# .prettierrc 2- "pluginSearchDirs": ["."], 3+ "plugins": ["prettier-plugin-svelte"]
Version 3 contains the following breaking changes:
<div />
or <Component />
that stays as is, and so does <div></div>
/<Component></Component>
. If svelteStrictMode
is turned on, it will still only allow <div></div>
notation for elements (but it will leave your components alone)svelteAllowShorthand
now takes precedence over svelteStrictMode
, which no longer has any effect on that behavior. Set svelteAllowShorthand
to false
to get back the v2 behaviorsvelteSortOrder
options were removed, see the the options section above for which values are valid for that optionsVersion 3 of this plugin only works with Prettier version 3. Prettier version 3 contains some changes to how it loads plugins which may require you to adjust your configuration file:
"plugins": ["prettier-plugin-svelte"]
to your config if you haven't already. Also remove the deprecated option pluginSearchDirs
.require.resolve("prettier-plugin-svelte")
in your .prettierrc.cjs
to tell Prettier where to find the plugin, you may need to remove that and just write "prettier-plugin-svelte"
instead>
or <
) hugging the inner tag or text?If you are wondering why this code
1<span><span>assume very long text</span></span>
becomes this
1<span 2 ><span>assume very long text</span 3 ></span 4>
it's because of whitespace sensitivity. For inline elements (span
, a
, etc) it makes a difference when rendered if there's a space (or newline) between them. Since we don't know if your slot inside your Svelte component is surrounded by inline elements, Svelte components are treated as such, too. You can adjust this whitespace sensitivity through this setting. You can read more about HTML whitespace sensitivity here.
pnpm
You may need to use a .prettierrc.cjs
file instead to point Prettier to the exact location of the plugin using require.resolve
:
1module.exports = { 2 pluginSearchDirs: false, 3 plugins: [require('prettier-plugin-svelte')], 4 overrides: [{ files: '*.svelte', options: { parser: 'svelte' } }], 5};
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
1 commit(s) and 5 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 7/29 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More