prettier-plugin-svelte icon indicating copy to clipboard operation
prettier-plugin-svelte copied to clipboard

Choose what to format

Open gbouteiller opened this issue 5 years ago • 5 comments

Hello, First of all, thank you for your work. I'm currently using your plugin via the vscode extension but I posted the issue here as I think it is more appropriate. I'm using pug templating so I have 3 main tags in my files : template, script and style. Currently, the plugin does not give you the opportunity to choose what to format and I ended up deactivating formatting because it messes up my pug template. Would it be possible to activate/deactivate formatting for script/style/template independently as it is the case for Vue with Vetur? Thank you.

gbouteiller avatar Aug 14 '19 09:08 gbouteiller

I'm using stylus for my CSS and this plugin either messes the styles up or refuses to process the file altogether. Would love an option to bypass prettifying everything inside the <style> tag.

umanghome avatar Sep 13 '19 19:09 umanghome

I have the same problem as @umanghome. I can't even disable it, it's terrible. please at least let us disable it!

ghost avatar Sep 30 '19 22:09 ghost

Would implementing <!-- prettier-ignore --> here address the issue? See https://prettier.io/docs/en/ignore.html

Seems it is already partially implemented for HTML, but not for <script> and <style>.

jesseskinner avatar Aug 30 '20 02:08 jesseskinner

Choosing what to format feels like the wrong solution, prettier is an opinionated code formatter after all. What we can - and did - though is to disable formatting for unsupported languages and supporting the <!-- prettier-ignore --> comment which marks the next node as "do not format". What's missing is support for default languages from svelte.config.js but I'm not sure if we can add this in a good way.

dummdidumm avatar Jan 06 '21 08:01 dummdidumm

I'm having a bit of trouble with this. <!-- prettier-ignore --> does not prevent formatting from occurring in my Svelte files. The example below shows the mess Prettier has made of a style element inside a template literal. I'm using the official Svelte plugin for VS Code and Svelte 3.0.

<!-- prettier-ignore -->
<script>
	export let animationName;
	export let calculatedLength;
	export let keyFrames;

	let styleElement = `
<style ✂prettier:content✂="Cgkuc3R1ZmYgewoJCWNvbG9yOiByZWQ7Cgl9Cg=="></style>
	`;
</script>

I'm getting around it for now by adding the file in question to my .prettierignore.

RapidOwl avatar Mar 23 '21 22:03 RapidOwl