Prettier setting to preserve space directly below function declaration
Asked Answered
I

1

6

For example if we have this in a .ts file:

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:

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?

Incontestable answered 7/3, 2020 at 0:40 Comment(0)
D
2

No. Prettier is an opinionated formatter with limited configurability and is designed this way on purpose. The available options are listed here.

Diu answered 7/3, 2020 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.