Plugin has a conflict with the built-in organize imports
See original GitHub issueAs soon as VScode was updated to 1.31.0, it appears that this prettier extensions conflicts with the the built-in organize imports setting, when organize imports on save is enabled.
prettier: "prettier": "^1.16.4",
(was initially on 1.13.7
, tried to update)
vscode: Version 1.31.0 (1.31.0)
extension: 1.8.0
I first opened a ticket with vscode core, but was referred to the extension as the source of the problem: https://github.com/Microsoft/vscode/issues/68193
Steps to reproduce
- Add setting for
editor.codeActionsOnSave.source.organizeImports = true
(see below for example json) - Ensure prettier is configured to format on save
- create a ts file (may also work with js) that has an import that exceeds the configured line length, which should be turned into a multi-line import
- Save file
Expected behavior:
- imports should be organized
- imports should be formatted to multi-line import
- file should be saved
Actual behavior:
- imports are organized
- imports remain on a single line
- file remains “dirty” - with the little white dot in the tab-bar
Note: I can format the document manually using the command menu and the import is correctly formatted, but then on save it is unformatted and the file shows as modified by the file system.
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
Initial file
Format file manually, just to show that it works
After Save (cmd+s)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:69
- Comments:38 (6 by maintainers)
Top Results From Across the Web
prettier-plugin-organize-imports - npm
A plugin that makes Prettier organize your imports (i. e. sorts, combines and removes unused ones) using the organizeImports feature of the ...
Read more >How to use tsserver's organize imports with nvim built-in LSP ...
Been doing with ALE and an eslint plugin. But I am getting hooked more on the LSP way :).
Read more >Supported hooks - pre-commit
cheetah-reorder-imports - This hook reorders imports in cheetah files. cheetah-flake - Lint cheetah code using flake8 and some other checks.
Read more >Sorting your imports correctly in React - DEV Community
eslint-plugin-import is a plugin that extends the ESLint import rules. It doesn't have properties only to organize and to sort; also, ...
Read more >Imports - checkstyle
Checks that there are no static import statements. Rationale: Importing static members can lead to naming conflicts between class' members. It ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After playing with some of the VSCode settings a bit more, you can make the editor behave in a REALLY strange way:
And look at what happens if you repeatedly save the file:
Yep, either Prettier or VSCode’s
organizeImports
breaks code - looks like a race condition. I’d stay away fromorganizeImports
for now.Can this be solved in some way? I would like to help if I can to implement this.