Gathering detailed insights and metrics for prettier-plugin-svelte
Gathering detailed insights and metrics for prettier-plugin-svelte
Gathering detailed insights and metrics for prettier-plugin-svelte
Gathering detailed insights and metrics for prettier-plugin-svelte
eslint-plugin-prettier
Runs prettier as an eslint rule
@sveltejs/vite-plugin-svelte
The official [Svelte](https://svelte.dev) plugin for [Vite](https://vitejs.dev).
eslint-plugin-svelte
ESLint plugin for Svelte using AST
@sveltejs/vite-plugin-svelte-inspector
A [Svelte](https://svelte.dev) inspector plugin for [Vite](https://vitejs.dev).
Format your svelte components using prettier.
npm install prettier-plugin-svelte
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
746 Stars
347 Commits
97 Forks
14 Watching
5 Branches
44 Contributors
Updated on 22 Nov 2024
Minified
Minified + Gzipped
TypeScript (64.61%)
HTML (34.44%)
JavaScript (0.95%)
Cumulative downloads
Total Downloads
Last day
1.1%
86,205
Compared to previous day
Last week
6.3%
466,703
Compared to previous week
Last month
17.2%
1,838,866
Compared to previous month
Last year
65.1%
16,719,753
Compared to previous year
This documentation is for
prettier-plugin-svelte
version 4 which only works with Svelte 5. See this branch for documentation of previous versions.
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@4
only works with prettier@3
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 .
As part of your scripts in package.json
:
1// package.json 2{ 3 // .. 4 "scripts": { 5 "format": "prettier --write ." 6 } 7}
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
).
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 "svelteBracketNewLine": false, 4 "svelteAllowShorthand": false, 5 "svelteIndentScriptAndStyle": false 6}
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.
For migration to
prettier-plugin-svelte@3
see here.
Upgrade to Svelte 5 before upgrading to prettier-plugin-svelte@4
, as it doesn't support older Svelte versions.
svelteStrictMode
option has been removed. Attributes are now never quoted, because this will mean "stringify this attribute value" in a future Svelte version.
>
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.
No vulnerabilities found.
Reason
5 commit(s) and 9 issue activity found in the last 90 days -- score normalized to 10
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
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 2024-11-18
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