add newline for each chaining statement in visual studio code

Viewed 2096

anyone knows what is setting to add newline on chaining statement for prettier extension at visual studio code? I have code as following in typescript

export function myfunction(myString: string) {
  cy.get(myString).find('.aaa').click();
}

I want to make sure it turn into

export function myfunction(myString: string) {
  cy.get(myString)
    .find('.aaa')
    .click();
}


1 Answers

Use newline-per-chained-call rule from eslint: https://eslint.org/docs/rules/newline-per-chained-call

Add this in your aslant config (.eslintrc.json, for example):

{
  //... 
  "rules": {
    //...
    "newline-per-chained-call": "error"
  }
}

To make it work in VS Code, install eslint ext and follow instructions how to "Auto Fix on Save" from ext page.

"editor.codeActionsOnSave": {
  "source.fixAll": true
}

for example.

Related