TypeScript: Incorrect (potentially) indentation of function arguments spanning multiple lines
From @nomaed on October 14, 2016 10:40
- VSCode Version: 1.6.1
- OS Version: macOS Sierra 10.12
Steps to Reproduce:
- Write a function (or a method) with several arguments (I did it with JavaScript and TypeScript files, but I believe any would work).
function myFunc(arg1, arg2, arg3, ...args) {
}
- Split arguments to several lines by hitting Enter before arguments
function myFunc(arg1,
arg2,
arg3,
...args) {
}
Auto-formatting produces this result:
function myFunc(arg1,
arg2,
arg3,
...args) {
}
I would expect to see this result instead though:
function myFunc(arg1,
arg2,
arg3,
...args) {
}
Also, when manually formatting the arguments to appear in the same column (note: this is also the default/recommended setting in tslint and maybe other linters), then further lines will start with wrong indentation:
function myFunc(arg1,
arg2,
arg3,
...args) {
console.log('huh...');
}

Copied from original issue: Microsoft/vscode#13748
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 33
- Comments: 25
Commits related to this issue
- chore(tslint): turn off align rule due to conflict the tslint rule for aligning blocks of code and typescript-formatter are in conflict because the formatter doesn't like aligning parameters of a fun... — committed to anler/sheikah by deleted user 6 years ago
- chore(tslint): turn off align rule due to conflict the tslint rule for aligning blocks of code and typescript-formatter are in conflict because the formatter doesn't like aligning parameters of a fun... — committed to anler/sheikah by deleted user 6 years ago
- refactor(file name): implement project layout defined in #126 (#160) * refactor(file name): implement project layout defined in #126 BREAKING CHANGE: everyone need to update what they are working ... — committed to witnet/sheikah by anler 6 years ago
- Add .editorconfig file, standardize formatting I see quite a of bit of inconsistency in the formatting. Let's add a .editorconfig file, so the code we write uses the right whitespacing regardless of... — committed to simark/cdt-gdb-adapter by deleted user 6 years ago
- Add .editorconfig file, standardize formatting I see quite a of bit of inconsistency in the formatting. Let's add a .editorconfig file, so the code we write uses the right whitespacing regardless of... — committed to simark/cdt-gdb-adapter by deleted user 6 years ago
- Add .editorconfig file, standardize formatting I see quite a of bit of inconsistency in the formatting. Let's add a .editorconfig file, so the code we write uses the right whitespacing regardless of... — committed to simark/cdt-gdb-adapter by deleted user 6 years ago
- Add .editorconfig file, standardize formatting I see quite a of bit of inconsistency in the formatting. Let's add a .editorconfig file, so the code we write uses the right whitespacing regardless of... — committed to simark/cdt-gdb-adapter by deleted user 6 years ago
- Add .editorconfig file, standardize formatting I see quite a of bit of inconsistency in the formatting. Let's add a .editorconfig file, so the code we write uses the right whitespacing regardless of... — committed to eclipse-cdt-cloud/cdt-gdb-adapter by deleted user 6 years ago
My prefered style for large
method/functionsignatures:It would be best to provide a configuration so a user can choose which way to go.
This is still an open issue in VS code 1.30.1 - the TS autoformatter removes leading whitespace, even if the tslint config is:
The comments above RE “I prefer a single tab indent when continuing the parameter list on a newline” aren’t particularly useful - this is still a bug.
Maybe I am missing something, but my project has the following
tslint.jsonfile:And TSLint does complain about parameters not being aligned after I auto format (using default settings, I am pretty sure since I am not overriding anything with
typescript.format). I know I can turn off TSLint’s rule, but I would prefer to control settings for this… I find what seems the default to not be the most readable option:I’d like to add that the current indentation rule appear to work incorrectly when combined wth multiple nesting levels. In a naked VSCode install, auto format produces this:
instead of:
FWIW, we have been using prettier now for a couple of years. Really helped with this and other code formatting consistency issues across our teams/products.
In case no. 3, the return type indent once is decreasing readability. So I prefer my option no. 2 but it’s sensitive to function rename - we have to indent all again.
@19majkel94 Option no. 2 probably. Return type (at last the semicolon) is immediately following the args closing parenthesis, so to make it appear in a new line, the closing parenthesis should be moved down too.
I think that these should all be valid:
The reason why I don’t like the way it is now is that the argument aren’t aligned and it’s decreasing readability.