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 !

 

0

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)

0

Thanx for your answer, but I already tried that, and unfortunately it's not this option.

0

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).

0

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 :

export function Test(editor) {
    console.log('Plugin has been registered');

    editor.model.schema.extend('$text', {
       allowAttributes: 'test'
    });

    editor.conversion.attributeToElement({
                                   model: 'testModel',
                                   view: 'testViex'
                                });
}

But I would like the second block to be formatted like the first one, this way (more readable) :

export function Test(editor) {
    console.log('Plugin has been registered');

    editor.model.schema.extend('$text', {
       allowAttributes: 'test'
    });

    editor.conversion.attributeToElement({
       model: 'testModel',
       view: 'testViex'
    });
}

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 ]

export function Test(editor) {
    console.log('Plugin has been registered');

    editor.model.schema.extend('$text', {
       allowAttributes: 'test'
    });

    editor.conversion.attributeToElement(
       {
          model: 'testModel',
          view: 'testViex'
       }
    );
}

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…

0

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.

0

请先登录再写评论。