-
Notifications
You must be signed in to change notification settings - Fork 12.8k
make the quote symbol configurable for import codefix #13270
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
Comments
Yes please, this is very frustrating. |
the temporary fix is rather trivial if you go |
It'd be great if this was just inferred in cases where the option isn't explicitly listed. |
yeah, just look around and do it as in 90% cases (you can collect the statistics which quotes are used around the code, can't you?) |
another thing to consider is that since codefixes emit typescript (not javascript, i beg you), the emitter should comply to some standards namely the quote mark should be configured at the top level of the codefix emitter configuration, so that any codefix out there uses it for emitting properly formatted string literals with the right quote symbol |
Great point. This is the way that Roslyn C# code fixes are starting to work, they emit code based on style preferences which are now more configurable and enforceable as well. |
A related thing to consider are quick fixes of missing interface implementations. The array type declarations should also be configurable. For example |
do you have any idea when it is going to be fixed? |
@mhegazy Marking as high-property for VSCode since we've seen a fair number of reports of this. We could add a workaround on our side to replace the quotes but other consumers of TypeScript would also benefit from this. Can we please target 2.3 with a fix? |
Where should the configuration for this be stored? I like the idea of inferring from the current file, though. It seems fine to make the user fix the first one themselves then the remainder are "correct" |
Inferring from the current file would be great. If there is nothing to infer from yet, it would be awesome if the tool could try to find a configuration for the tslint quotemark rule. Currently in VS Code I use auto import code fix, followed by the tslint code fix to change from double to single quote. |
Making it configurable is overkill. Just find the first quote character used the file and use that. |
I agree with pgrm. The tslint.json quotemark rule is the perfect place to infer from. |
Reading from the file (and optionally in cases where there are no quotes, reading from tslint.json) would work for me. Is there any precedent for TypeScript reading directly from tslint configuration though? |
@vivainio prettier has a |
This was never a bug. This is a feature request. Also, it works correctly in the nightly builds. It's been fixed for a while.
Why would I want another formatter operating on my |
Today I've found out that the bug came back. While using However, when I switch to my project's version (Typescript Is there a way to force VSCode to use single quotes while runing Typescript Note: I can't upgrade to use Typescript |
@Maximaximum This is only fixed in TS 2.5+. There is no way to fix this with older TS versions |
@mjbvz Ok, thanks for letting me know |
I'm using 2.6.2 and I'm getting double quotes :s |
yep, double quotes are used in 2.6.2 |
@PlugaruT Thanks. So if I've understood correctly it was double, then at some point single and now double again but still not configurable? |
I don't really know, I just started to write typescript so for me are just double quotes. |
The original behavior was always double quotes. That was modified in #17750 to infer from the imports in the current file the quote style; this means that if this is the first import in the file there is no place to infer the style from and couple quotes will be used. |
How do I disable semicolons in auto imports? |
tracked by #19882 |
@mhegazy Hey thanks, I did that, but still the same, do I need to specify to use ts importer somehow? I still get a ; with auto imports |
the suggestion of having semicolons being configurable is tracked by #19882. I did not say it was implemented. |
@mhegazy Oh, still, any idea? xd |
@filipef101 line numbers are a general text editor feature. How are they related to TypeScript? |
Comented in microsoft/vscode#23559 (comment):
Resuming:
Look for "Import external module.": {
"prefix": "import statement",
"body": [
"import { $0 } from '${1:module}';"
],
"description": "Import external module."
}, |
On VS Code 1.21.1 you can correct this editing /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-basics/snippets/typescript.json |
On Ubuntu Linux (VS Code 1.21.1), you need to edit In the 'Import external module' section of that file make the body array property to be the value
|
Since VSCode 1.24 (June 2018) there is an option for configuring this. https://code.visualstudio.com/updates/v1_24#_preferences-for-auto-imports-and-generated-code |
But the |
@imcotton only works with TypeScript 2.9 and higher from what I can find |
@MurhafSousli https://code.visualstudio.com/updates/v1_24#_preferences-for-auto-imports-and-generated-code If you are still getting the double quote then your preferences.quoteStyle are probably either set to "double" or "auto". If it is set to "auto" (the default) then it infers the import style from existing imports. If there are no existing imports, then I believe it defaults to double quote. You can change preferences.quoteStyle (see above link) to "single" if you always want single quotes. |
Recent update, the auto generated import is working as expected with single quotes. As for auto generated snipets these are still double quoted. |
VSCode settings.json{
"typescript.preferences.quoteStyle": "single"
} No semis if you're cool: {
"typescript.preferences.quoteStyle": "single",
"typescript.format.semicolons": "remove"
} Example: import Hello from 'components/Hello'
export default () => (
<>
<Hello />
<h1>app</h1>
</>
) This issue can be locked. |
currently the import codefix uses double quotes for the module path string literal which makes our linter unhappy, i wish the choice of a quote was configurable
The text was updated successfully, but these errors were encountered: