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

plugin inserts prettier:content when using webstorm #242

Open
theweekendgeek opened this issue Aug 7, 2021 · 18 comments
Open

plugin inserts prettier:content when using webstorm #242

theweekendgeek opened this issue Aug 7, 2021 · 18 comments
Labels
bug Something isn't working

Comments

@theweekendgeek
Copy link

theweekendgeek commented Aug 7, 2021

example svelte project using the default template: https://github.com/theweekendgeek/svelte-prettier-example)

This s happening in WebStorm, I could not yet reproduce this in Visual Studio Code. I would assume that other IDEs from Jetbrains behave the same. Not sure If I might need to be raising this issue with them, because of the way the IDE calls Prettier for example.

How to reproduce:

  1. open project in webstorm
  2. in Settings -> Prettier: make sure prettier package is selected, add svelte extension to Run for files. Check On 'Reformat Code' action and On save
  3. open App.svelte
  4. select onMount
  5. type opening curly brace to surround with curly braces
  6. prettier:content is inserted instead of reformatted code

What I have found out so far:

  • In General I can call the Reformat with Prettier action without problems. I will format the code as expected, except when I have just done the sequence above and pressed undo. In this case the same result as above will shown.

  • I can workaround the issue by disabling the On 'Reformat Code' action option in the Prettier Settings.

@dummdidumm
Copy link
Member

I can't reproduce because I don't have these IDEs at hand now, but there's a open issue about prettier-plugin-svelte not being able to deal with formatting ranges (#233). When you press undo, is the code selected somehow? If so, this might boil down to fixing #233 in order to solve this.

@theweekendgeek
Copy link
Author

I tested this and when I hit undo, the part that I had seleced before is selected again.

I think it could very well be related or the same issue as #233, I could imagine some ranged formatting being triggered when surrounding a selection with curly braces.

regarding reproduction: I think you could probably try with the Intellij Community Edition. the javascript plugin should be based on the same code as Webstorm.

@TheOnlyTails
Copy link

@theweekendgeek The JavaScript plugin for IntelliJ IDEA is only available for the Ultimate edition (which has it pre-installed, making it practically equivalent to WebStorm).

@dmwyatt
Copy link

dmwyatt commented Oct 2, 2021

Also getting this but I'm using PyCharm Pro (which is basically a superset of WebStorm).

@dummdidumm JetBrains provides free licenses to open source projects: https://www.jetbrains.com/community/opensource/#support

@freeform99
Copy link

freeform99 commented Feb 11, 2022

Same problem here, with Webstorm. Unfortunately, entire script tag content got lost, which I only noticed some hours later, so lots of work to restore original file ...

@dustsucker
Copy link

I have the same Problem it never worked for me, I tested it a few times over the last year, but it never worked. In my experience, you don't need anything selected, it just cuts out the script part. It works for the JS files, though.

@staticglitch
Copy link

staticglitch commented Apr 19, 2022

Experiencing the same issue on PhpStorm. Triggers on selecting something, then wrapping with {}. This is too complex for me to solve...

Workaround is: turn OFF prettier for "on reformat code" actions, and turn ON "on save." Then simply use save shortcut instead of reformat.

@NyxCode
Copy link

NyxCode commented Jul 31, 2022

@staticglitch that worked for me, thanks!

@Lootwig
Copy link

Lootwig commented Jun 12, 2023

Experiencing the same issue on PhpStorm. Triggers on selecting something, then wrapping with {}. This is too complex for me to solve...

Workaround is: turn OFF prettier for "on reformat code" actions, and turn ON "on save." Then simply use save shortcut instead of reformat.

Using "optimize imports" action still inserts this prettier:content block. Is there a workaround as well for achieving the same outcome?

@Lootwig
Copy link

Lootwig commented Jun 12, 2023

Executing the action "remove braces around function body" somewhere on an on:click callback in the HTML also breaks the script block.

@mpellerin42
Copy link

This problem is still happening on a lot of actions (on save, on reformat, when trying usual refactoring trick like surrounding something with curly brackets…). It's a nightmare and prevent the proper usage of prettier + svelte in webstorm. I tried several things but nothing worked properly.

@Lootwig
Copy link

Lootwig commented Jul 1, 2023

I found a workaround, which consists of disabling prettier entirely, and configuring the IDE formatter to apply prettier's rules instead. You can do this by navigating to .prettierrc, and selecting "apply prettier code style rules" from the file's context menu. You can then use the IDE's "reformat code" action (includes also running on save, for example) for everything.

However, this change is lost upon restarting the IDE, which I have created a bug ticket for and would appreciate everyone thumbs-upping it for prioritization as long as it's the only way to prevent the prettier:content bug from messing up your files.

@allofapiece
Copy link

allofapiece commented Jul 25, 2023

+1

P.S.

Same problem here, with Webstorm. Unfortunately, entire script tag content got lost, which I only noticed some hours later, so lots of work to restore original file ...

for those who lost their original file content due to this error: this prettier:content is base64 string, just decode it.

@sjunepark
Copy link

+1

This is really annoying

@abdelfattahradwan
Copy link

Do you have any updates on this matter? In my opinion, this is a serious issue that needs to be addressed. If someone could provide information on what needs to be done, I would be more than willing to help fix this annoying and show-stopping bug.

@dummdidumm
Copy link
Member

This is an upstream bug/limitation. We need a way to hook into prettier's "format range" option: prettier/prettier#7639
Until then, we can't fix this bug. Related: #233

@dummdidumm dummdidumm added the bug Something isn't working label Jan 29, 2024
@falkomerr
Copy link

Turn off all actions on save except prettier works for me

image

@Lootwig
Copy link

Lootwig commented Feb 13, 2024

@falkomerr manually configuring the prettier version to whatever package resides under node_modules made this work for me - before, I had "automatic configuration" selected, the dialog looks like the screenshot and the bug occurs no matter if other options are selected or not

image

Note: bug still occurs when "run on reformat" is selected, independent of what's enabled in "run on save"
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests