Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop new lines when formatting code

EDIT: It is Beautify that is adding the new lines. Not sure which rule though.

Is there a way to stop parameter lists and import lists from adding new lines per each list item when formatting code with?

E.g stop this:

function view(state$) {
  return state$.map(({weight,height,bmi}) =>
    div([
      renderWeightSlider(weight),
      renderHeightSlider(height),
      h2('BMI is ' + bmi)
    ])
  );
}

from becoming this:

function view(state$) {
  return state$.map(({
      weight,
      height,
      bmi
    }) =>
    div([
      renderWeightSlider(weight),
      renderHeightSlider(height),
      h2('BMI is ' + bmi)
    ])
  );
}

When right-clicking and selecting "format document"?

It also does it with imports like so:

import {
  makeDOMDriver,
  h1,
  a
} from '@cycle/dom';

However it is unwanted.

like image 683
BeniaminoBaggins Avatar asked Mar 01 '17 04:03

BeniaminoBaggins


People also ask

How do you stop a line break in VS Code?

You can toggle word wrap for the VS Code session with Alt + Z (macOS: Option (or Alt) ⌥ + Z ) or select View > Word Wrap from Menu.

How can you prevent VS Code from breaking up long HTML lines into multiple lines?

How can you prevent VS Code from breaking up long HTML lines into multiple lines? My solution: Select the SVG you want to convert to single line. Then press F1 and type Join Lines and hit enter.


2 Answers

create or edit .jsbeautifyrc file in your root from you vscode project and put in to the file this json property

{
    "brace_style": "collapse,preserve-inline"
}

this will also prevent to format all JavaScript object

like image 147
Isaac Weingarten Avatar answered Oct 25 '22 14:10

Isaac Weingarten


Include "brace_style": "collapse,preserve-inline" as Yitzchak said inside the .json settings file located here:

C:\Users\***\AppData\Roaming\Code\User\settings.json
like image 27
Eze_82 Avatar answered Oct 25 '22 14:10

Eze_82