Javascript object alignment when reformating
Hello,
when I format javascript code with objects, I get something like this :
but I'd prefer it to be formatted like this:
How can I adjust the editor's code style to get this?
Thanx !
Please sign in to leave a comment.
Hi there,
At quick glance this sounds like it's “Align when multiline” code style option, probably the one under “Function call arguments” (Settings/Preferences | Editor | Code Style | JavaScript | Wrapping and Braces)
Thanx for your answer, but I already tried that, and unfortunately it's not this option.
1. Please export your current Code Style as XML file and share it via some file sharing service (e.g., Google Drive or alike)
2. Provide a simple JS code that can be used for the test (so we both have the same code to test on)
That's assuming that it is caused by the built-in formatted and not an external one (e.g. Prettier or alike).
I don't use external formatter like Prettier.
Here's my codestyle as XML export : https://drive.google.com/file/d/1bi9ECVu2RG0pl8B7ZKRKpiLUMEHH52lZ/view?usp=sharing
And here's a sample JS file : https://drive.google.com/file/d/19HvIB8dctpUCTlOfQ3Petx28eiPNmPEf/view?usp=sharing
After formatting
CTRL+ALT+L
:But I would like the second block to be formatted like the first one, this way (more readable) :
I should add, if I place the braces on a new line like below, the block is correctly formatted, but it adds two unnecessary lines, and I didn't succeed to make it like that automatically (I tried everything in [ Wrapping and Braces / Function calls ]
And If I format two times (
CTRL+ALT+L
x 2), it removes the extra custom linebreaks and returns to the first version.Thanx if you have a solution…
Anyway, I just tested Prettier in PhpStorm, it works exactly as I intended.
I think I'll use it now, instead of the internal formatter, with the “Run on ‘Reformat code’ action” option.