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

Double comma conflict with Prettier on ES6 imports when auto-importing #107057

Closed
tonix-tuft opened this issue Sep 19, 2020 · 8 comments
Closed
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s)

Comments

@tonix-tuft
Copy link

  • VSCode Version:
    Version: 1.49.1
    Commit: 58bb7b2
    Date: 2020-09-16T23:21:17.533Z (2 days ago)
    Electron: 9.2.1
    Chrome: 83.0.4103.122
    Node.js: 12.14.1
    V8: 8.3.110.13-electron.0
    OS: Darwin x64 17.7.0

  • OS Version: macOS High Sierra 10.13.6

Since Prettier version ^2.0.0, the default value for the Prettier: Trailing Comma (trailingComma) option of the Prettier VS Code extension (https://github.com/prettier/prettier-vscode) is es5:

Screen Shot 2020-09-19 at 10 52 38

This makes Prettier to add a trailing comma to ES6 imports as well, e.g. given this code (unsaved):

import {
  Tag1,
  Tag2,
  Tag3
} from "./some-module";

// ...

When saved (Cmd+S/Ctrl+S):

import {
  Tag1,
  Tag2,
  Tag3,
} from "./some-module";

// ...

Now, when I reference another component (let's say Tag4) in the same file containing the code above, VS Code prompts me to auto import this component too:

Screen Shot 2020-09-19 at 10 57 59

And when I type Enter to auto import the component this is what I end up with:

import {
  Tag1,
  Tag2,
  Tag3,, Tag4
} from "./some-module";

Tag4

// ...

VS Code adds another trailing comma after Tag3, before adding Tag4, leading to two subsequent commas and of course causing a parse error.

The expected behaviour would be for VS Code to check if the import statement already has a trailing comma, and add it only if it's missing.

For now, the only way to fix this would be to add the following config option to a .prettierrc file in the project:

{
  "trailingComma": "none"
}

This makes Prettier to not add trailing commas at all. But again, I think it would be great if VS Code would check for that trailing comma on its own before auto importing a component.

Thank you for your attention and for this IDE, I feel very comfortable to work with it!

@vscodebot
Copy link

vscodebot bot commented Sep 19, 2020

(Experimental duplicate detection)
Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

@mjbvz
Copy link
Contributor

mjbvz commented Sep 19, 2020

Duplicate of microsoft/TypeScript#40561. Should be fixed in VS Code insiders

@mjbvz mjbvz closed this as completed Sep 19, 2020
@mjbvz mjbvz added the *duplicate Issue identified as a duplicate of another issue(s) label Sep 19, 2020
@tonix-tuft
Copy link
Author

tonix-tuft commented Sep 19, 2020

Duplicate of microsoft/TypeScript#40561. Should be fixed in VS Code insiders

Thank you for your reply.

Should be fixed in VS Code insiders

What do you mean? Will it be fixed in the next patch/minor version of VS Code > 1.49.1? Thank you.

@mjbvz
Copy link
Contributor

mjbvz commented Sep 21, 2020

VS Code insiders always tracks the next VS Code version, so 1.50

@tonix-tuft
Copy link
Author

Thank you for your reply! Will wait for the 1.50 update on VS Code.

tonix-tuft added a commit to tonix-tuft/aopla that referenced this issue Sep 21, 2020
…s for trailing commas because of VS Code's issue #107057 (microsoft/vscode#107057)
tonix-tuft added a commit to tonix-tuft/aopla that referenced this issue Sep 21, 2020
@landonalder
Copy link

I'm still having this same issue with vscode 1.50.1 and typescript 4.0.2

@mjbvz
Copy link
Contributor

mjbvz commented Oct 26, 2020

This was fixed in TypeScript 4.0.3 (which is the default for VS Code 1.50)

@landonalder
Copy link

landonalder commented Oct 27, 2020 via email

@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s)
Projects
None yet
Development

No branches or pull requests

3 participants