简体   繁体   中英

add newline for each chaining statement in visual studio code

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();
}


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM