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

tsconfig.json compiler option: indent #4042

Closed
jednano opened this issue Jul 27, 2015 · 15 comments
Closed

tsconfig.json compiler option: indent #4042

jednano opened this issue Jul 27, 2015 · 15 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript

Comments

@jednano
Copy link
Contributor

jednano commented Jul 27, 2015

I would just love an indent option for the tsconfig.json file, not only for the obvious reason of preserving indentation, but also to prevent issues like the following, where I have TypeScript code with template strings compiling into an ES6 target:

ts-compiled

I would imagine as long as it supports 4 spaces, 2 spaces and tabs, that should fulfill most everyone's needs; however, flexibility would probably be best.

@jednano
Copy link
Contributor Author

jednano commented Jul 27, 2015

Of course, if my editor displayed tabs in a different width, this would look even more horrible.

@danquirk
Copy link
Member

This seems like a setting better suited to .editorconfig?

@jednano
Copy link
Contributor Author

jednano commented Jul 27, 2015

@danquirk I use EditorConfig religiously and belong to the organization; however, this is definitely a compiler option. The only way I could see EditorConfig coming into the mix is if the compiler actually ran each file path against EditorConfig to see which settings should be applied per file. I really don't want to incur the performance hit of doing this in the TypeScript compiler, so I feel this is much better suited as a compiler option.

Besides, your source files are likely all the same indentation anyway. EditorConfig is great for targeting files in different locations, usually.

@jednano
Copy link
Contributor Author

jednano commented Jul 27, 2015

We already have a configuration option to control the newline character, why not the indentation as well?

@mhegazy
Copy link
Contributor

mhegazy commented Jul 28, 2015

We already have a configuration option to control the newline character, why not the indentation as well?

The new line is used for the generated .js not as an editor configuration. here you are talking about editor configuration.

Having said that, now there is a different way to set these options in different editors. maybe we should put formatting options in tsconfig.json and use it in all editors. @jrieken and @billti what do you think?

@jednano
Copy link
Contributor Author

jednano commented Jul 28, 2015

@mhegazy I am absolutely NOT talking about the editor setting. My screenshot shows the original source on the top half and the compiled output on the bottom half.

@jednano
Copy link
Contributor Author

jednano commented Jul 28, 2015

The TS compiler replaces leading-tab indentation with 4 spaces is my point. I'd like to control that!

@mhegazy
Copy link
Contributor

mhegazy commented Jul 28, 2015

Ah.. Sorry my bad. In this case, if output formatting is important to you, we suggest you add a JS beautifier to your build. There are many formatting parameters like where to place curlies, spaces before and after keywords, etc.. And trying to do all adds a lot of complexity for small value.

@mhegazy mhegazy added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints labels Jul 28, 2015
@mhegazy mhegazy closed this as completed Jul 28, 2015
@ghost
Copy link

ghost commented Apr 12, 2016

Allthough closed, will you please reconsider this issue. I was looking for an indent setting in the tsconfig.json file as well to met my companies styling guidelines for javascript (despite the suggestion for an extra JS beautifier run). If output formatting is no issue for you guys you may omit the line-ending setting as well

@S-YOU
Copy link

S-YOU commented May 7, 2016

Although it is closed, and I don't care about generated javascript, which I use uglify later. But I do care about the file size, which is 30~40% bigger with 4 spaces than single tab.

Only supporting to specify tab or space and tabSize options should not be a complex issue, because you already writing 4 spaces there.

Also adding another JS beautifier to just do that is too much to the build pipeline, and Typescript itself is already huge.

@NathanSweet
Copy link

I agree if you have a line ending setting, you might as well have a tab setting. No one is asking for full formatting options, just these two very common settings. That said, we have to do this to get tabs:

ls *.js | awk '{print "unexpand -t 4 ", $0, " > /tmp/e; mv /tmp/e ", $0}' | sh

@RWOverdijk
Copy link

Is there an option available for this? I too prefer two spaces over three (for reasons).

@zbjornson
Copy link

If I'm not mistaken, a PR to add configurable indentation was rejected:
#2768

I would appreciate this option for the sake of keeping the diff between TS and emitted JS files minimal. (tsc could even detect source indentation.)

@S-YOU
Copy link

S-YOU commented Oct 20, 2016

Rejecting this is just because typescript authors want everyone to use four spaces.

For those who just want to change the output to tab, you can patch typescript.js after you install.

sed -i 's/"    "/"\\t"/g' node_modules/typescript/lib/typescript.js
% grep "indentStrings =" node_modules/typescript -R
node_modules/typescript/lib/typescriptServices.js:    var indentStrings = ["", "    "];
node_modules/typescript/lib/typescript.js:    var indentStrings = ["", "\t"];
node_modules/typescript/lib/tsserverlibrary.js:    var indentStrings = ["", "    "];
node_modules/typescript/lib/tsserver.js:    var indentStrings = ["", "    "];
node_modules/typescript/lib/tsc.js:    var indentStrings = ["", "    "];

That saved 25% of total file sizes in my project with tabs, less disk read/write is better for most cases, especially if you have live reload or watch to compile continuously.

@RWOverdijk
Copy link

@S-YOU S you, too! .. But thank you, that helps.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Out of Scope This idea sits outside of the TypeScript language design constraints Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

7 participants