Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prettier-ignore is ignored #59

Closed
taylorzane opened this issue Oct 9, 2019 · 16 comments
Closed

prettier-ignore is ignored #59

taylorzane opened this issue Oct 9, 2019 · 16 comments

Comments

@taylorzane
Copy link
Contributor

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.)

philipp-tailor pushed a commit to philipp-tailor/svelte_sidebar that referenced this issue Nov 18, 2019
`prettier-plugin-svelte` does not respect `prettier`s ignore rules
(laid out [here](https://prettier.io/docs/en/ignore).
There's an open issue for that:
sveltejs/prettier-plugin-svelte#59
Until there's no way to not have `prettier` break the word into two,
I'll chose the tradeoff to have the word broken in the wrong place for
small phones.
@foodwaterwifi
Copy link

This would be greatly appreciated.....................

RedHatter pushed a commit to RedHatter/prettier-plugin-svelte that referenced this issue Mar 13, 2020
@Conduitry
Copy link
Member

Implemented in 1.1.0.

@m4rrc0
Copy link

m4rrc0 commented May 10, 2020

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?

@jonas-veselka
Copy link

Also not working for me. I need this line to be ignored because of unwanted spaces from the new lines.

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

@Conduitry Conduitry reopened this May 20, 2020
@b1mind
Copy link

b1mind commented May 27, 2020

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 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).

@jonas-veselka
Copy link

jonas-veselka commented Jun 3, 2020

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

This unfortunately doesn't work for me. But thanks for sharing Your settings. It must be caused by something different.

@will-stone
Copy link

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>`}

@luizschiestl
Copy link

Any progress or workaraound on that? Note that svelte files listed in .prettierignore are also not ignored, so my only current option is to set "svelte.plugin.svelte.format.enable": false in VS Code settings which will unfortunately disable formatting for all svelte files.

@nauta
Copy link

nauta commented Jun 18, 2020

In VS Code, using the "Svelte Beta" extension instead of the more popular "Svelte" extension from James Birtles (that uses this plugin's older 0.7.0 version), fixed at least the prettier-ignore feature in html for me.

@luizschiestl
Copy link

In VS Code, using the "Svelte Beta" extension instead of the more popular "Svelte" extension from James Birtles (that uses this plugin's older 0.7.0 version), fixed at least the prettier-ignore feature in html for me.

Didn't work for me. Do you mind sharing your VS Code settings?

@b1mind
Copy link

b1mind commented Jun 20, 2020

Really stabbing in the dark here... Cause I did some real wacky things in my process.

Uninstall prettier and all svelte extension. > Installed prettier > installed old svelte > load svelte a file > uninstall old svelte extension > install Svelte Beta > reload vsCode.

Not sure if this will work but it is how I had installed things.

@dummdidumm
Copy link
Member

This issue is now about multiple things at once. The original issue, supporting prettier-ignore, is implemented, so I'm going to close. If it does not work for you when using the VSCode extension, I suggest to take a second look at the setup instructions to make sure you don't have an old extension installed and don't treat Svelte as HTML.

The issues listed in the following have other, different reasons:

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>`}

This is another symptom of #70

Also not working for me. I need this line to be ignored because of unwanted spaces from the new lines.

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

prettier-ignore does not work this way. It only ignores the next node, not the next line. So it will only keep the first {@html... node unformatted. To achieve what you desire, but the prettier-ignore comment above the node that contains the code. Example:

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

Note that svelte files listed in .prettierignore are also not ignored.

I created #131 for that

@DhyeyMoliya
Copy link

<!-- prettier-ignore --> does not work in .svelte files for <script src="..."> and <style src="...">.

@dummdidumm
Copy link
Member

#130 will fix this

@codingwithchris
Copy link

<!-- 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.

@dummdidumm
Copy link
Member

Please open a new issue with a detailed reproduction (can't reproduce this given your code snippet) instead of posting in 3 closed ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests