Skip to content

TypeScript should use double quotes for string in import snippet.#22255

Merged
mjbvz merged 1 commit intomicrosoft:masterfrom
adyavanapalli:master
Mar 8, 2017
Merged

TypeScript should use double quotes for string in import snippet.#22255
mjbvz merged 1 commit intomicrosoft:masterfrom
adyavanapalli:master

Conversation

@adyavanapalli
Copy link
Contributor

@msftclas
Copy link

msftclas commented Mar 8, 2017

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. We will now review your pull request.
Thanks,
Microsoft Pull Request Bot

@adyavanapalli adyavanapalli changed the title TypeScript should use double quotes for string. TypeScript should use double quotes for string in import snippet. Mar 8, 2017
@mjbvz mjbvz added this to the March 2017 milestone Mar 8, 2017
@mjbvz mjbvz merged commit 8948a20 into microsoft:master Mar 8, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Mar 8, 2017

Thanks @adyavanapalli! This will be in the next insiders build

@tmcgannon
Copy link

Why can't this be configurable like tslint: https://palantir.github.io/tslint/rules/quotemark/ ?

@mjbvz
Copy link
Collaborator

mjbvz commented Mar 9, 2017

@tmcgannon This change only applies to the snippet and makes our behavior more consistent with TypeScript. Use the TSlint extension to autofix the snippet after insertion if you prefer single quotes (or just type of the import statement directly instead of using the snippet)

@mikehaas763
Copy link

I just wanna gather some context. This change was introduced because other similar vscode snippets use double quote? Or what?

@mjbvz
Copy link
Collaborator

mjbvz commented Apr 7, 2017

@mikehaas763 as noted, this PR was was to bring the snippet inline with the TS style guide

@mikehaas763
Copy link

Oh jeez not sure how I glossed over that. Makes sense. Although, I didn't see anywhere in the guide where it says double over single quotes. I'm sure it's in there though!

@adyavanapalli
Copy link
Contributor Author

@mikehaas763 Look here

@jmaronge
Copy link

jmaronge commented Apr 8, 2017

I agree with @tmcgannon why can't this be configurable. While the TS style guide says one thing lots of people use single quotes for strings instead of double quotes. To say just "Use the TSlint extension to autofix the snippet after insertion if you prefer single quotes (or just type of the import statement directly instead of using the snippet)" defeats the purpose of the feature and requires a lot of extra work. The idea of the snippet is to be a faster way to inserting the text but now you have made it virtually unusable for those who use single quotes for strings.

@adyavanapalli
Copy link
Contributor Author

adyavanapalli commented Apr 8, 2017

@jmaronge This can be still configured by editing the typescript snippet file (Preferences > User Snippets > Typescript) and inserting the following configuration code:

"Import external module.": {
	"prefix": "import statement",
	"body": [
		"import { $0 } from '${1:module}';"
	],
	"description": "Import external module."
}

After, for the user-defined snippet to appear first in the list of available snippets (as now two snippet entries appear when you type import) , you must add the following configuration code to your settings.json:

"editor.snippetSuggestions": "top"

As for why double quotes are configured by default: it is simply because vscode follows what is recommended by the typescript coding guidelines available here.

If this truly bothers you and makes the snippet virtually unusable for those who use single quotes for strings, you can edit the system default snippet file, which is available (on Windows) at the following location: C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\typescript\snippets\typescript.json

Cheers! XD

@linusbrolin
Copy link

@adyavanapalli so instead of providing a simple settings line where the default is double quotes, but that could be overridden in the user settings, you instead propose editing a local json file that cannot be included in my project source code repository?

My tslint is configured to suggest single quotes.
The reasons for this are simple:

  1. It was the default when I first started the project, and I'm not going to replace every single single quote in my entire project now, just because the default has changed.
  2. If I want a string to contain double quotes within the string, then using single quotes for the string itself is way better than having to escape the double quotes within the string.
    One example where this would occur is when the string contains html.

There is no reason to not provide a setting for this.
Infact, other editors have settings for it, like WebStorm: https://stackoverflow.com/questions/39779272/webstorm-phpstorm-double-quotes-in-typescript-auto-import/39779498

@adyavanapalli
Copy link
Contributor Author

@linusbrolin I have provided two solutions. One in which the default double-quotes snippet can be overridden with a single-quotes snippet and these configuration files can be placed within your project's repo. This is all done from within vscode. The second solution is for those seeking a permanent change in the default setting. Please re-read my above response.

@daniborgs
Copy link

daniborgs commented May 18, 2017

As @adyavanapalli very well mentioned, you can edit the typescript.json file to get around this issue on /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript/snippets/ for MacOS and C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\typescript\snippets\ for Windows.

Thx buddy.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants