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

Improve semicolon detection experience for new files #32831

Closed
mjbvz opened this issue Aug 12, 2019 · 1 comment · Fixed by #33402
Closed

Improve semicolon detection experience for new files #32831

mjbvz opened this issue Aug 12, 2019 · 1 comment · Fixed by #33402
Assignees
Labels
Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Aug 12, 2019

TypeScript Version: 3.6.0-dev.20190810

Search Terms:

  • semicolon
  • format
  • auto import

Repo

For a very simple project:

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es2016",
        "jsx": "preserve"
    },
    "exclude": [
        "node_modules",
    ]
}

constants.ts

export const a = 1
export const b = 1
export const c = 1
export const d = 1
export const e = 1
export const f = 1

main.ts

console.log(a)
  1. Trigger auto import quick fix in main.ts on a

Expected behavior:
Since constants.js does not use semicolons, the import should not have a semi colon

Actual behavior:
The added import has a semi colon

I believe this is because the current semicolon detection logic (#31801) requires some number of examples in the current file to learn from. For new files, this means we always default to using semicolons even if the rest of the project is semicolonless

I can understand why we do this, but as a user I found it frustrating that TS would still insert semicolons until I added a certain number of imports (or other statements that are also used by the detection code). I don't know if looking at the rest of your project code is feasible or not for semicolon detection but we should discuss if we can improve the experience for new files

/cc @andrewbranch

Related Issues:

@mjbvz
Copy link
Contributor Author

mjbvz commented Aug 15, 2019

The better solution may be to add an explicit preference for semicolons, similar to one we already have for quotes. Trying to infer if semicolons should be used or not from other files in the project could be messy and prone to errors

@RyanCavanaugh RyanCavanaugh added Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript labels Aug 16, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.0 milestone Aug 16, 2019
@andrewbranch andrewbranch added the Fix Available A PR has been opened for this issue label Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants