1

How can i force Visual Studio to maintain curly braces in the same line when auto format is done?

Example: I write this code:

$('#details-modal').on('change', '#Foo1', function (e) { var bar = $('#Foo2 option:selected').text(); }) 

When i add ; the code gets formatted like this:

$('#details-modal').on('change', '#Foo1', function (e) { var bar = $('#Foo2 option:selected').text(); }); 

How can i avoid this behaviour and maintain the first code style?

Thank you

1

2 Answers 2

2

I had this same problem in Visual Studio 2022. I'm not using Resharper so the previous solution didn't work for me. What did work was going to Tools -> Options -> Text Editor -> JavaScript/TypeScript -> Tabs, and changing the Indenting option from Smart to Block.

enter image description here

Before:

enter image description here

After:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

I post this in case anyone has the same problem.

In my case, it was not visual studio 2022 the tool which was causing the line breaks, it was Resharper.

I have disabled the wrapping options in Javascript inside Resharper and now it is working as desired.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.