You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
If all that was considered was the entire file having at least 3/4 semi colons on each statement
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.
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
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?
I'm not doubting that you have experience working in React, but some of the most popular OSS libraries for their domain follow this convention so that is a little bit weird... Perhaps you had seen it and not noticed? I've been using React since v0.3.x and remember literally > half of the libraries that I was importing at one point used this convention, and many very popular and upcoming repos still follow it to some extent... though I can recognize it's gaining popularity to use semis since VSCode is now becoming a very good ES7 IDE -- thanks partly to TS.
There is also an option for this in ESLint and Prettier -- ironically what causes many to be give up is strong adoption of VSCode which thanks to TS has defaults which are not quite as accommodating for the entire community (though I do have to say I am very impressed with it's rapid improvement/progress).
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.
For a list of some of the soms popular libraries in off of the top of my head:
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.
well, I put some links there? Seems you did not click them if you are making this statement. I mean obviously in terms of that, check the React code and not the webpack code or course.
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:
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.
Andrew Branch (@andrewbranch) - Thanks for working on the issue, I'm testing latest version to see if this issue was solved in PrinterOptions which has a property exactly for this which was working in the past so we developers can have control . Will update with results here. Left some questions / opinions #31801 (comment) thanks
Sebastián Gurin (@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.
Ryan Cavanaugh (@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)
Reacted by Dmitri, Enteleform, Eric Haynes and Pedr Browne
Activity
mhegazy commentedon Nov 9, 2017
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.
Lxxyx commentedon Nov 13, 2017
I like ts importer. You can configure semicon, space by youself.
https://github.com/pmneo/ts-importer
phra commentedon Nov 13, 2017
yep, i think that updating the formatter can be the best option too.
timc13 commentedon Jan 19, 2018
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:
43 remaining items
rob2d commentedon Aug 4, 2019
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.
andrewbranch commentedon Aug 5, 2019
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?
rob2d commentedon Aug 5, 2019
Andrew Branch (@andrewbranch) thanks for explanation on first part 🙃
I'm not doubting that you have experience working in React, but some of the most popular OSS libraries for their domain follow this convention so that is a little bit weird... Perhaps you had seen it and not noticed? I've been using React since v0.3.x and remember literally > half of the libraries that I was importing at one point used this convention, and many very popular and upcoming repos still follow it to some extent... though I can recognize it's gaining popularity to use semis since VSCode is now becoming a very good ES7 IDE -- thanks partly to TS.There is also an option for this in ESLint and Prettier -- ironically what causes many to be give up is strong adoption of VSCode which thanks to TS has defaults which are not quite as accommodating for the entire community (though I do have to say I am very impressed with it's rapid improvement/progress).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.
For a list of some of the soms popular libraries in off of the top of my head:Redux:https://github.com/reduxjs/reduxReact Redux:https://github.com/reduxjs/react-redux/tree/master/testCSSinJS:https://github.com/cssinjs/jssReact Router (not currently but for most of its life):https://github.com/ReactTraining/react-router/blob/v3/modules/IndexRedirect.jsEdit: crossing out terrible misinformation.
andrewbranch commentedon Aug 5, 2019
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.
rob2d commentedon Aug 5, 2019
well, I put some links there? Seems you did not click them if you are making this statement. I mean obviously in terms of that, check the React code and not the webpack code or course.Edit: no, you definitely clicked.
andrewbranch commentedon Aug 5, 2019
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:
blikblum commentedon Aug 5, 2019
I clicked on the links and they are not using semicolons at all
rob2d commentedon Aug 5, 2019
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.
cancerberoSgx commentedon Aug 6, 2019
Andrew Branch (@andrewbranch) - Thanks for working on the issue, I'm testing latest version to see if this issue was solved in
PrinterOptionswhich has a property exactly for this which was working in the past so we developers can have control . Will update with results here. Left some questions / opinions #31801 (comment) thanksmjomble commentedon Aug 6, 2019
It might make more sense to have this discussion on #31801
RyanCavanaugh commentedon Aug 6, 2019
Sebastián Gurin (@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.
cancerberoSgx commentedon Aug 6, 2019
Ryan Cavanaugh (@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)
finscn commentedon Nov 22, 2021
any news?