Search code examples
visual-studio-codetslintprettier

How to avoid VsCode Prettier to break chain functions in new lines.?


I'm working with VSCode, Prettier and TSLint.

When I do have chained functions call with more than 2 calls like

let m = moment().startOf("day").subtract(30, "days");

Prettier breaks into

let m = moment()
    .startOf("day")
    .subtract(30, "days")

I already set the TSLint rule

{
  "defaultSeverity": "warning",
  "extends": ["tslint:recommended"],
  "linterOptions": {
    "exclude": ["node_modules/**"]
  },
  "rules": {
    // ...
    "newline-per-chained-call": false
  }
}

and the fallowing settings

"prettier.tslintIntegration": true

But the chained functions still breking into new lines.

What can I do to avoid the line breaking but still using the TSLint?


Solution

  • Note that in Prettier v2.0.4 this issue is fixed. Now, as long as your line of code is within the length specified in your config or the default 80, it will be left in one line. Otherwise, it will be wrapped to multiple lines.

    I had to upgrade my prettier in order for these changes to be put into affect.

    $ yarn upgrade -g prettier --latest