-
Notifications
You must be signed in to change notification settings - Fork 5
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
Formatting imports jumps between prettier formatting #91
Comments
Thanks for the feedback! You can set line wrapping style to be compatible with Prettier. More details: https://github.com/daidodo/format-imports/wiki/Line-Wrapping-Style#prettier-compatibility Please tell me if you still have questions. |
I already have this setting enabled: |
The correct output should be having those imports split across several lines. If I disable this extension and let prettier handle formatting, the code is formatted properly. If I disable prettier and let this extension format the code, the output is incorrect with all of the imports on a single line, even with Disabling |
I had the "jumping around on every save" issue, and setting |
In the above, I already have this setting and it hasn't fixed the issue. |
The real fix here would be to remove formatting responsibilities from this extension and have it purely handle sorting. |
I'm having this issue too and it's very frustrating.
@Nxt3 How? |
I don't have an answer to that. Someone needs to submit a PR with those changes. There isn't a fix for this currently. |
Sorry for the late response! The long-term solution is to migrate the extension to a Prettier plugin. But I don't have time ATM. I'd appreciate if anyone want to help. Another workaround is to add the following settings with help of this extension:
|
Unfortunately that doesn't solve the problem as it just makes TS Importer/Sorter the formatter for imports; if someone else working in your project doesn't have this VS Code extension, their Prettier will undo the formatting changes causing an unnecessary diff. |
Did you try to swap the code actions so prettier can prevail? |
"editor.codeActionsOnSave": [
"source.addMissingImports",
"source.organizeImports.sortImports",
"source.formatDocument", // prettier
"source.fixAll.eslint"
] It still causes the imports to change formatting on every save. |
I think I fixed this by adding another prettier call: "editor.codeActionsOnSave": [
"source.addMissingImports",
"source.organizeImports.sortImports",
"source.formatDocument",
"source.formatDocument",
"source.fixAll.eslint"
], I not longer have the jump in formatting. |
It's frustrating. Thinking of uninstalling this extension, I'm afraid. |
I think I came up with a better solution when compared to running Download this extension: It allows us to add delays to code actions run on save so you can "waterfall" the commands. Add this to your "run-commands-as-code-actions.jsTsFormatAndLint": [
{
"command": "tsImportSorter.command.sortImports",
"delay": 100
},
{
"command": "prettier.forceFormatDocument",
"delay": 150
},
{
"command": "eslint.executeAutofix",
"delay": 200
},
{
"command": "workbench.action.files.saveWithoutFormatting",
"delay": 250
}
],
"[typescript]": {
// here's the magic
"editor.codeActionsOnSave": ["source.addMissingImports", "source.runCommandsAsCodeActions.jsTsFormatAndLint"],
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
}, This will add missing imports, then run the actions defined under |
Thanks for sharing, still a problem with the delays of 100, 150 or 200 - how will you know the previous action did really complete before starting the next one? Especially in large code bases. |
The extension author could probably answer that better. |
After months of working fine, I got this again (after moving some eslint config files around). Very frustrating. But then I restarted VSCode and it worked again. Shrug. |
....and it happened again. I had to restart a couple of times before it worked correctly. My guess is that every time you start VS Code, the 'order' of extensions that can format-on-save changes, and you just have to keep restarting until Prettier beats this (or vv, which ever you prefer) |
Describe the bug
Auto Imports seems to be interfering with prettier formatting still. Might be related to #39
To Reproduce
Format this file:
with following VS Code settings:
Expected behavior
TS Import sorter should allow prettier to handle the formatting for line length.
Actual behavior
Formatting for long lines jumps between formatted an unformatted.
Screenshots
OS (please complete the following information):
v7.5.1
VS Code (please complete the following information):
Installed VS Code extensions
.prettier.yml
.eslintrc.json
The text was updated successfully, but these errors were encountered: