简体   繁体   English

更漂亮的设置以在函数声明正下方保留空间

[英]Prettier setting to preserve space directly below function declaration

For example if we have this in a .ts file:例如,如果我们在 .ts 文件中有这个:

export const handleHMRMessages = (cache: any, store: CPReduxStore, conn: WebSocket) => {

  conn.onclose = () => {
    store.dispatch(actions.dev.hmrDisconnected());
  };
}

prettier will remove all carriage returns above the first line of code in the func body: prettier 将删除 func 主体中第一行代码上方的所有回车:

export const handleHMRMessages = (cache: any, store: CPReduxStore, conn: WebSocket) => {
  conn.onclose = () => {
    store.dispatch(actions.dev.hmrDisconnected());
  };
}

so I have been resorting to adding a comment above the declaration to preserve the space:所以我一直在声明上方添加注释以保留空间:

export const handleHMRMessages = (cache: any, store: CPReduxStore, conn: WebSocket) => {
  // add comment here as needed
  conn.onclose = () => {
    store.dispatch(actions.dev.hmrDisconnected());
  };
}

is there a prettier setting that can always have no more and no less space below a function declaration?是否有一个更漂亮的设置,在函数声明下方总是不能有更多或更少的空间?

No. Prettier is an opinionated formatter with limited configurability and is designed this way on purpose.不。Prettier 是一种固执的格式化程序,可配置性有限,并且是故意这样设计的。 The available options are listed here .此处列出可用选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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