Code Style for Objects?

Hello,

for Code Style settings:

Can I indent the ternary signs?

Why is the "backgroundColor" object not wrapped? (Objects: Wrap always is enabled)

Can I fix the wrong intentation of the closing bracket of the "textDecoration" object?

 

Thank you.

 

This is from a .ts file after formatting:


function rowStyle(reference) {
return reference.isVisible
? {backgroundColor: 'dd'}
: {
textDecoration: 'line-through',
color: 'gray'
};
}
0
3 comments

>Can I indent the ternary signs?

not sure I follow you.. aren't they indented?

>Why is the "backgroundColor" object not wrapped?

how is it expected to be wrapped? it is a simple object with a single key only

>Can I fix the wrong intentation of the closing bracket of the "textDecoration" object?

it's correctly indented for me - aligned with `?` and `:` (I'm using default settings + Objects: Wrap always):

function rowStyle(reference) {
return reference.isVisible
? {backgroundColor: "dd"}
: {
textDecoration: "line-through",
color: "gray"
};
}

 

0

sorry bad example.

 

take

function rowStyle(reference) {
const fooFooFoolabalalalala = reference.isVisible ? {backgroundColor: 'd'} : {textDecoration: 'line-through',color: 'gray'};
}

now enable always wrap objects and ternaries, align ternaries  when multiline, and align ? and :

I get this

function rowStyle(reference) {
const fooFooFoolabalalalala = reference.isVisible
? {backgroundColor: 'd'}
: {
textDecoration: 'line-through',
color: 'gray'
};
}

but that is what I would expect:

function rowStyle(reference) {
const fooFooFoolabalalalala = reference.isVisible
? {
backgroundColor: 'd'
}
: {
textDecoration: 'line-through',
color: 'gray'
};
}

When it says "wrap always" for Objects I would expect this also for single lines objects (like with single line ifs in brackets).

0

Try disabling Align when multiline for ternary operators - formatting results look better for me when it's off:

   

 

function rowStyle(reference) {
const fooFooFoolabalalalala = reference.isVisible
? {
backgroundColor: 'd'
}
: {
textDecoration: 'line-through',
color: 'gray'
};
}

 

As for wrapping single line objects, there should be a separate option for putting braces on new lines, https://youtrack.jetbrains.com/issue/WEB-7122

1

Please sign in to leave a comment.