Javascript code indentation when passing an object literal to a function call.
When writing a function call that takes an object literal as an argument, I would like the code to be formatted like this:
var faz = bar({
foo: 1,
bar: 2,
baz: 3
});
However, at my current settings, RM wants to format it like this:
var faz = bar({
foo: 1,
bar: 2,
baz: 3
});
This seems to be following the method call indentation rules, where arguments are aligned if wrapped. I've fiddled a great deal with the Javascript code styling rules, but to no avail. Is it possible to set up RM so that it formats as the first example?
Please sign in to leave a comment.
Formatting with default settings do the thing. Do you have 'Align when multiline' in 'Function call arguments' checked?
Yes! That was it. Thank you very much Konstantin.
However, I realised that this change also applies to non-object literal arguments in a function call. So with the option off I get the following formatting:
var x = Foo(alpha,
beta,
gamma);
In the above case I would like to have the align behavior like previously:
var x = Foo(alpha,
beta,
gamma);
But I guess I can't have both, hmm.
You can have them both! I got it configure on my work computer somehow and I can't figure out what is to make it work on my personal computer. I even exported all setting and imported and it didn't work.
Please someone tell us how to fix this.
You can't have function call arguments aligned if 'Align when multiline' in 'Function call arguments' is disabled. This option affects all function calls, there is no way to make this work differently for objects passed as arguments. If you miss it, please file a feature request to youtrack, https://youtrack.jetbrains.com/issues/WEB
Related ticket: https://youtrack.jetbrains.com/issue/WEB-25968
Perhaps there is another way to accomplish this - but I am convinced that in my work computer it works like that. (btw the option 'align when multiline' is disabled). That's also a common practice in angular - to list dependencies in a constructor each in a new line and aligned, but when creating a decorator with an object parameter in it align it to the left... like this:
```
constructor(service1: Service1,
service2: Service2) {
}
@ngModule({
imports: [
ImportedModule
...
],
providers: [
SomethingService,
...
]
...
})
```
Is there a way to accomplish something similar to this?
Alignment in constructor declaration is controlled by 'Align when multiline' in 'Function declaration parameters', decorator arguments - by 'Align when multiline' in 'Function call arguments'. So there is a way to accomplish this by enabling the first option and disabling the latter: