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
Svelte formatter suddenly do not respect formatting rules #2273
Comments
Can you check if you have any .prettierrc or prettier.config.js files? If there is a prettier config file, it takes priority over VSCode config. And maybe also check if there is any error logged. It might be that your config file is no longer valid in prettier v3 and throws an error. You can check it with the |
Hi @jasonlyu123 , thanks for the reply. I don't have prettier config files. I just tried to nuke /node_modules/ just to exclude some corruptions there, but nothing. I tried another repo, much smaller, and it works correctly, so I exclude machine problem.
Any other idea? Does the svelte VS Code extension scan all the files at startup, or only when a file is opened? |
Prettier will load config files outside your workspace and files that aren't at the root level, You may need to check the directory tree. If there isn't, we'll need a reproduction to determine the problem. |
I'm 100% sure there is no prettier config in my repo, can you please explain better |
If your file is at |
I checked the tree, no prettier configs found. The VS Code extension uses a prettier config, right? could I use that and check if an explicit prettier config is loaded? In this way I could also "bypass" the problem while I'm trying to close a task. |
I'm also wondering if the vs code extension try to load only the .svelte files opened in the editor, or if at startup it scans the full tree. I'm asking because I have some "weird" huge .svelte files that maybe could cause the problem, and it will explain why it happened suddenly while coding. |
@jasonlyu123 I found the problem 🥳 I attach it here so it should help to reproduce the issue? Thank you |
I found the offending lines in
it looks like the problem appears if it least one of those 3 settings are enabled. I don't have a |
Yes. We also take editorconfig into account, and it also takes priority over vscode config. The way it takes priority isn't per setting. If there is a config file, all the vscode config will not be used. |
Ok, thanks for the explanation. |
I think I found a way to solve this my issue. It's possible to bypass .editorconfig via
But this conflicts with what you said:
Instead it looks it's working for me. Can you confirm this please? or maybe it's just a coincidence? BTW it started to happen "suddenly" because a colleague of mine did push a commit changing that file, adding the offending lines and - I don't remember how - VS Code did pick up the new configs. |
If this can stop it, it probably is because it'll only take priority if there is any config in editorconfig that can be translated to prettier. It's handled by Prettier. I went through their code, and it does seem so. What we do is if the prettier config file result is falsy, we use the vscode config. Prettier VSCode has a config to disable the editorconfig loading. I think it does make sense to add the support for that config on our side. |
I agree. It can be solved like how I did, but it's kind of fragile, as new configs add in editorconfig/prettier can trigger the same situation as well, that is pretty hard to diagnose, as it's not well documented which file, which attributes, and which priority. |
Hi, I'm not sure this is the correct repo to post this issue. My problem is that suddenly VS Code has started to format the svelte files without respecting my settings. I haven't changed anything. I did not install any new extensions or packages. It just happened while I was working. Tried to restart VS Code many times.
The most evident - and annoying - is the single/double-quotes in imports. My config says it should be single quotes, but - on save - it change them to double quotes. Ineed every time to use Eslint autofixer to get them back correct.
I double checked all my settings, and they are correct (I mean
Svelte › Plugin › Svelte › Format › Config: Single Quote
"svelte.plugin.svelte.format.config.singleQuote": true
)I don't have Prettier installed.
I have installed
Svelte for VS Code v108.2.1
.Anyone else experienced the same? I don't know where to look to get back my sanity.
Thank you
The text was updated successfully, but these errors were encountered: