Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option not to inline a single-line functions #673

Open
farwayer opened this issue Sep 22, 2024 · 1 comment
Open

Add option not to inline a single-line functions #673

farwayer opened this issue Sep 22, 2024 · 1 comment

Comments

@farwayer
Copy link

It would be great to have an option not to inline a single-line function, even if the line length allows it.

This will be useful, for example, when a single-line arrow functions are not used in place, but are moved to a separate file. You want to keep it visually clean (no braces and returns), but at the same time keep a uniform style for all exported functions for quick visual search (the signature and body of the function on different lines).

export let type = (app: AppState, id: MediaId) =>
  app.medias.get(id)?.type

export let status = (app: AppState, id: MediaId) =>
  app.medias.get(id)?.status

export let videoIds = (app: AppState) =>
  map
    .values(app.medias)
    .filter(media => media.type === 'video')
    .map(media => media.id)

export let audio = (app: AppState, id: MediaId) => {
  let media = app.medias.get(id)
  if (!media) return
  ...
  return media
}

The first two functions will become one-line functions, which I would like to avoid:

export let type = (app: AppState, id: MediaId) => app.medias.get(id)?.type

export let status = (app: AppState, id: MediaId) => app.medias.get(id)?.status

It can be singleBodyPosition.arrowFunction option or maybe something else

@farwayer
Copy link
Author

Found many issues about the position of the body of a single-line arrow function. If you look at the usage, it becomes clear that in some cases it is better to move the function body to the next line, and in some cases it is not. So the maintain parameter will be very useful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant