Prettier: Odd formatting with directly nested arrow functions and block

Created on 21 Mar 2017  路  3Comments  路  Source: prettier/prettier

Hi! I'm starting to use prettier, and noticed some odd formatting with regards to arrow functions when they are nested like in the following examples.

const fn = b => c => d => 3; // This stays the same, which is good.

// but this one
const fn = b => c => d => {
  return 3
};
// gets formatted to this
const fn = b =>
  c =>
    d => {
      return 3;
    };

My sentiment is that this is not very pretty, but let me know if this was done on purpose.

// FYI
const fn = fooooooooooooooooooooooooooooo => baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar => baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz => 3;
// when args get very long, it gets formatted to
const fn = fooooooooooooooooooooooooooooo => // <linebreak>
  baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar => baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz => 3;
// which is fine

(And obviously, thanks for the tool :heart:)

locked-due-to-inactivity bug

Most helpful comment

Just sent https://github.com/prettier/prettier/pull/1066 to fix this issue, thanks for reporting it!

All 3 comments

I was literally about to make this exact issue. Was working on a redux middleware:

// in:
const mw = store => next => action => {
  return next(action)
}
// out:
const mw = store =>
  next =>
    action => {
      return next(action)
    };

Interesting, looks like we need to do some special handling of arrow functions used in a curried way

Just sent https://github.com/prettier/prettier/pull/1066 to fix this issue, thanks for reporting it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tjvr picture tjvr  路  3Comments

nfriedly picture nfriedly  路  3Comments

thezanke picture thezanke  路  3Comments

jamiebuilds picture jamiebuilds  路  3Comments

mafredri picture mafredri  路  3Comments