How to disable reformat for JS empty bracket ?

Hi, is is possible to keep empty JS object in a single lline ?

I have:

showModal: () => {},

After format:

showModal: () => {
},

Is there an option to NOT reformat in such case ?

Thank you

2
7 comments

Try enabling  Keep when reformatting | Simple methods in one line in Settings | Editor | Code Style | JavaScript | Wrapping and Braces - does it help?

1

The problem with your option is that this line below is not formatted anymore: 

AudioPlayerWidget.defaultProps = {a: "a", b: "b", c: "c"};


I think this would be acceptable only for one property key, but not more.

0

can't reproduce - similar code doesn't seem to be affected by Simple methods in one line option. Props are wrapped if the Objects wrapping is configured in Settings | Editor | Code Style | JavaScript | Wrapping and Braces 

1

Ok you are right, but I don't really understand. Now, whatever the option you mention is enabled or not the code below does not change when formatted.

A.defaultProps = {};
B.defaultProps = {a: "a"};
C.defaultProps = {a: "a", b: "b", c: "c"};

I have the same behaviour in JSON, JS, and JSX, that is very strange. Yesterday, the shortcut "ctrl + alt +l" has added me a break line at an empty bracket expression, maybe it was not this exact situation, I am not sure anymore.

My problem is solved then, but as we are here, do you think we could configure Intellij to format the code like that :

A.defaultProps = {};
B.defaultProps = {
a: "a"
};
C.defaultProps = {
a: "a",
b: "b",
c: "c"
};

Thank you

0

Setting Objects to Wrap Always in in Settings | Editor | Code Style | JavaScript | Wrapping and Braces should do the thing...

 

1

Objects > Wrap always and Keep when reformatting > Simple methods in one line give "almost" what I wanted but the result makes sense, I will keep that behaviour :)

Thank you !!

let a = {};
let b = {a: "a"};
let c = {a: "a", b: "b"};
let d = () => {};
let e = () => {{ a: "a"}};
let f = () => ({ a: "a", b: "b"});

is formatted as:

let a = {};
let b = {a: "a"};
let c = {
a: "a",
b: "b"
};
let d = () => {};
let e = () => {{ a: "a"}};
let f = () => ({
a: "a",
b: "b"
});

 

0

I was looking for the same thing in Java.

0

Please sign in to leave a comment.