prettier-plugin-svelte: prettier-ignore is ignored

The following snippet of code will get formatted regardless of whether the <!-- prettier-ignore --> comment is above the line. The standard prettier html parser handles this case.

<script>
// whatever
</script>

<!-- prettier-ignore -->
<span>[</span><span>{value}</span><span>]</span>

<style>
/* whatever */
</style>

The spans need to stay on one line as this component is inside of a <pre> tag and being on new lines modifies the outcome. (That’s a separate issue that can’t necessarily be handled by #28, so the prettier-ignores should be respected.)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 41
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

This would be greatly appreciated…

I just had this issue when trying to inject a dynamic style tag and found this worked, no prettier-ignore required:

{@html `<${'style'} class="block">
...
</style>`}

My other issue was that postCSS was clobbering the style tag: hiding it in the nested string got around that. Without doing that results in Prettier doing this:

{@html `<style class="block ✂prettier:content✂="LmFuaW1hdGlvbk5hbWUgewogI..."></style>`}

It is not working for me. I updated dependencies to

    "prettier": "^2.0.5",
    "prettier-plugin-svelte": "^1.1.0",

and this

    <!-- prettier-ignore -->
    <p>A veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy long sentence to make the tag wrap</p>

still wraps.

The prettier plugin seems to kick in since my <script> and <style> tags get reordered properly.

Is anyone else having issues with this?

Implemented in 1.1.0.

<!-- prettier-ignore --> still does not work in:

"prettier": "^2.6.2",
"prettier-plugin-svelte": "^2.7.0",

@dummdidumm Your example here does not work:

<!-- prettier-ignore -->
<div>
     {@html text1}<a href='#'>{@html linkText}</a>{@html text2}
</div>

prettier still formats everything in this node… nothing I can do will prevent prettier from running in a svelte file on any line. I was attempting to do this to bypass #240 which still seems to be a bug.

#130 will fix this

So after finally getting SCSS working with svelte beta/vsCode (and wanting to use .pug, which I know is not supported atm). I looked for away to omit <template> tag from being formatted. I found this thread and tried the above and it seems to be working for me? image One thing I know that I did is make a .prettierrc in my root app folder with

// .prettierrc
{
  "svelteSortOrder": "scripts-markup-styles",
  "svelteStrictMode": true,
  "svelteBracketNewLine": true,
  "svelteAllowShorthand": false
}

Not sure that matters any though. As it seems to work in .css/.html/.svelte files shown in screencap. Any thing I can do to help just ask I will spend time(though I am quite the noob).