Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Format your Svelte components using Prettier.
- Format your HTML, CSS, and JavaScript using prettier
- Format Svelte syntax, e.g. each loops, if statements, await blocks, etc.
- Format the JavaScript expressions embedded in the Svelte syntax
- e.g. expressions inside of `{}`, event bindings `on:click=""`, and more
- e.g. expressions inside of `{}`, event bindings `onclick={...}`, and more

## VS Code Extension

Expand All @@ -28,7 +28,7 @@ Installing the plugin as a package allows:

### Compatibility

- `prettier-plugin-svelte@4` only works with `prettier@3`
- `prettier-plugin-svelte@4` only works with `prettier@3` and Svelte 5+
- `prettier-plugin-svelte@3` only works with `prettier@3`
- `prettier-plugin-svelte@2` only works with `prettier@2`

Expand Down Expand Up @@ -113,47 +113,6 @@ Example:
| ------- | --------------------------------- | ------------------------------ |
| `true` | `--svelte-allow-shorthand <bool>` | `svelteAllowShorthand: <bool>` |

### Svelte Bracket New Line

> Deprecated since 2.5.0. Use Prettier 2.4.0 and [bracketSameLine](https://prettier.io/docs/en/options.html#bracket-line) instead.

Put the `>` of a multiline element on a new line. Roughly the Svelte equivalent of the [jsxBracketSameLine](https://prettier.io/docs/en/options.html#jsx-brackets) 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](https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting). You can adjust whitespace sensitivity through [this setting](https://prettier.io/docs/en/options.html#html-whitespace-sensitivity).

Example:

<!-- prettier-ignore -->
```html
<!-- before formatting -->
<span><div>foo</div><span>bar</span></span>
<div pretend break>content</div>

<!-- after formatting, svelteBracketNewLine true -->
<span
><div>foo</div>
<span>bar</span></span
>
<div
pretend
break
>
content
</div>

<!-- after formatting, svelteBracketNewLine false -->
<span
><div>foo</div>
<span>bar</span></span>
<div
pretend
break>
content
</div>
```

| Default | CLI Override | API Override |
| ------- | ---------------------------------- | ------------------------------ |
| `true` | `--svelte-bracket-new-line <bool>` | `svelteBracketNewLine: <bool>` |

### Svelte Indent Script And Style

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.
Expand All @@ -167,7 +126,6 @@ Whether or not to indent the code inside `<script>` and `<style>` tags in Svelte
```json
{
"svelteSortOrder": "options-styles-scripts-markup",
"svelteBracketNewLine": false,
"svelteAllowShorthand": false,
"svelteIndentScriptAndStyle": false
}
Expand Down Expand Up @@ -207,9 +165,9 @@ Usage in the browser is semi-supported. You can import the plugin from `prettier

> For migration to `prettier-plugin-svelte@3` [see here](https://github.com/sveltejs/prettier-plugin-svelte/tree/version-3?tab=readme-ov-file#migration).

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.
- 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.
- `svelteBracketNewLine` option has been removed. Use Prettier's [bracketSameLine](https://prettier.io/docs/en/options.html#bracket-line) option instead.

## FAQ

Expand Down
1 change: 0 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Config } from 'prettier';

export interface PluginConfig {
svelteSortOrder?: SortOrder;
svelteBracketNewLine?: boolean;
svelteAllowShorthand?: boolean;
svelteIndentScriptAndStyle?: boolean;
svelte5CompilerPath?: string;
Expand Down
13 changes: 1 addition & 12 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ export const options: Record<keyof PluginConfig, SupportOption> = {
makeChoice('none'),
],
},
// todo: remove in v4
svelteBracketNewLine: {
category: 'Svelte',
type: 'boolean',
description: 'Put the `>` of a multiline element on a new line',
deprecated: '2.5.0',
},
svelteAllowShorthand: {
category: 'Svelte',
type: 'boolean',
Expand Down Expand Up @@ -93,9 +86,5 @@ export function parseSortOrder(
}

export function isBracketSameLine(options: ParserOptions): boolean {
return options.svelteBracketNewLine != null
? !options.svelteBracketNewLine
: options.bracketSameLine != null
? options.bracketSameLine
: false;
return options.bracketSameLine != null ? options.bracketSameLine : false;
}
2 changes: 1 addition & 1 deletion test/formatting/samples/attributes-no-newline/options.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"svelteBracketNewLine": false
"bracketSameLine": true
}
Loading