Skip to content

autoimport should care about semicolons #19882

Description

@mjbvz

From Francesco Soncina (@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.

  • VSCode Version: 1.18
  • OS Version: Linux

Steps to Reproduce:

  1. use new autoimport feature
  2. imports are always with semicolons

Copied from original issue: microsoft/vscode#37991

Activity

  1. removed their assignment
    on Nov 9, 2017
  2. mhegazy commented on Nov 9, 2017

    @mhegazy
    Contributor

    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.

  3. Lxxyx commented on Nov 13, 2017

    @Lxxyx

    I like ts importer. You can configure semicon, space by youself.

    https://github.com/pmneo/ts-importer

    image

  4. phra commented on Nov 13, 2017

    @phra

    yep, i think that updating the formatter can be the best option too.

  5. timc13 commented on Jan 19, 2018

    @timc13

    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:

  6. 43 remaining items

  7. rob2d commented on Aug 4, 2019

    @rob2d

    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.

  8. andrewbranch commented on Aug 5, 2019

    @andrewbranch
    Member

    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?

  9. rob2d commented on Aug 5, 2019

    @rob2d

    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/redux

    React Redux:
    https://github.com/reduxjs/react-redux/tree/master/test

    CSSinJS:
    https://github.com/cssinjs/jss

    React Router (not currently but for most of its life):
    https://github.com/ReactTraining/react-router/blob/v3/modules/IndexRedirect.js

    Edit: crossing out terrible misinformation.

  10. andrewbranch commented on Aug 5, 2019

    @andrewbranch
    Member

    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.

  11. rob2d commented on Aug 5, 2019

    @rob2d

    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.

  12. blikblum commented on Aug 5, 2019

    @blikblum

    Seems you did not click them if you are making this statement.

    I clicked on the links and they are not using semicolons at all

  13. rob2d commented on Aug 5, 2019

    @rob2d

    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.

  14. cancerberoSgx commented on Aug 6, 2019

    @cancerberoSgx

    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

  15. mjomble commented on Aug 6, 2019

    @mjomble

    It might make more sense to have this discussion on #31801

  16. RyanCavanaugh commented on Aug 6, 2019

    @RyanCavanaugh
    Member

    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.

  17. cancerberoSgx commented on Aug 6, 2019

    @cancerberoSgx

    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)

  18. finscn commented on Nov 22, 2021

    @finscn

    any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScriptVS Code TrackedThere is a VS Code equivalent to this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions