-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
autoimport should care about semicolons #19882
Comments
It looks like |
We could add a new set of CodeFixSettings that include semicolon and quotes as well as any other things that would be needed by code fixes.. alternatively, we can teach the formatter about semi colons. |
It's probably better to keep all of those settings in one place. So your second suggestion sounds best. |
I like ts importer. You can configure semicon, space by youself. |
yep, i think that updating the formatter can be the best option too. |
just to add my 2 cents, a few lint rules can probably fixed at the same time. Here are the rules that are breaking for me when I auto fix an import: |
Why doesn't the TS AutoImport just respect TS Lint settings? |
any news? |
With #22236 added, we can add a configuration option for this feature. we would be happy to take a PR for this. |
I'd be happy to work on this, can anyone point me to the general direction of where I should look? |
I'm trying to find this piece of code and set it up in a PR, however it is a bit foggy for my about in what project is this problem related to. It'd be nice to have a VSCode setting about this, however this seems to be in the TS server. |
@khaosdoctor we should probably first add a new settings for it in the TS server (this repo) and then make a change in the VS Code repo that would use this setting. More thoughts and suggestions in this comment |
Yeah, I just talked to some people here and they have explained me this. We need to add the logic to read this setting in the TS server and another PR to VSCode to create this setting altogether. |
I keep cleaning our projects files' import as VSCode is adding semicolon automatically and we always forget some. Any plan to do this? |
I use VSCode for more than 2 years (and really enjoy it, btw). One of the first bugs I've noticed was this: when you use autoimport it always adds a semicolon in the end of the line. Even if you don't want it and have all kinds of settings for it. I thought "Ok, it's a pretty obvious and simple thing, they gotta fix it really soon". I was waiting for ages. And today I finally decided to find out what's going on. Is it so complicated? Does somebody work on this issue? Is there any way to help? |
@mlshv It's pretty tricky since you have to add two settings, one in the TS Language Server, to allow the use of semicolons, and another one in the VSCode to read the previous one. We discuss this in some previous comments |
There's a milestone and an assignee now → It ✨ should ✨ get done for 3.6 🙂 |
as @mjomble said, |
I noticed that there was an algorithm for detecting semi colons, but in this fix (that has been closed), does it only apply this to import checks? the reason I ask is I have seen it very common in certain codebases (especially React) not to include semi colons for import/export, but to do so for all other code. If all that was considered was the entire file having at least 3/4 semi colons on each statement, it would not detect this sort of scenario properly or intelligently. |
@rob2d no, the fix considers any statements that normally have semicolons but don’t require them.
That said, it starts looking from the top of the file and quits once it sees a handful of examples to work with, so if you had a bunch of semicolon-less imports at the top of your file, it should infer that you don’t want semicolons. So in that case, auto-imports will do what you want, and other code insertions won’t.
Before joining TypeScript, I worked heavily in React for several years, and I’ve never heard of such a thing. Can you send some examples? |
@andrewbranch thanks for explanation on first part 🙃
Just to emphasize I'm not simply stubborn or something: the main reason I do not use semis on imports personally is because it is a bit noisy to look at in the top of my files -- have a bit of OCD about clutter with imports and can justify mentally separating it as the only statically linked part of an ES7 app. Obviously though, in codebases I am touching that do not share this view, "when in Rome" and all. Either way I don't knock using semis in your imports since everyone is different but just explaining that it's a normal thing for some devs and not exactly violating the spec.
Edit: crossing out terrible misinformation. |
@rob2d Unless I’m really missing something, every example you just sent doesn’t use semicolons at all. In my memory, eslint-config-standard, which prefers no semicolons, was really popular with many React folks in the early days, and more recently eslint-config-react-app I think has become a de-facto choice. To be clear, I have absolutely zero judgement on how people format their code—I want you to put semicolons wherever they make you happy, no more and no less—it’s just that I feel like we’re unlikely to add additional heuristics to TypeScript to support preferences that are atypical and/or more work to test for. That’s why I asked for examples—not because I don’t believe you or think that’s a weird preference to have, but rather because I want to try to form an idea of how common this is by looking at the size of projects that adopt such a convention. |
Edit: no, you definitely clicked. |
I went into each repo you linked and found a random JS file, so possibly we’re looking at different files. Can you send a specific file where you see this convention? Here’s what I looked at:
|
I clicked on the links and they are not using semicolons at all |
Edit: upon further reflection, I hadn't noticed that they were either all or nothing, and I am an idiot 🙃 my whole life has just changed a bit thanks to this thread. TLDR: you all have a very good point. Sorry about that. |
@andrewbranch - Thanks for working on the issue, I'm testing latest version to see if this issue was solved in |
It might make more sense to have this discussion on #31801 |
@cancerberoSgx replying to your pre-edit content, our belief was that implementing this as a heuristic would actually be the best behavior, since the tool would just "do the right thing" with no necessary configuration from the user. It seems it'd be better if TS simply inserted semicolons in files that seemed to use semicolons so that users didn't have to go find the configuration option. |
@RyanCavanaugh I give my feedback #31801 so there's less noise, thanks - ("do the right thing" sounds strange particularly if in a platform extendible by third parties with their own opinions- I think "the right thing" is to consistently support any code style that the JavaScript language specification allows any user to write their code with (since there's no standard for that and I don't think airbnb style guide or any other is even a defacto standard on this regard.Currently semicolons behavior and settings API is inconsistent with the rest of code format related semantics) |
any news? |
From @phra on November 9, 2017 20:11
i usually write my ts/js code without semicolons and there is now way to configure vscode to avoid adding semicolons to auto imports. it would be nice an automatic parsing of the tslint config or at least a configurable option in the settings.
Steps to Reproduce:
Copied from original issue: microsoft/vscode#37991
The text was updated successfully, but these errors were encountered: