lexmag / elixir-style-guide

An opinionated Elixir style guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi-line struct assignment

rgreenjr opened this issue · comments

I'd appreciate verification on the preferred way to wrap multi-line struct assignments. The three possible scenarios are depicted below.

Thanks in advance!

  1. Left hand side fits, but right doesn't:
datetime =
  %NaiveDateTime{calendar: Calendar.ISO, day: 1, month: 12, year: 2017}
  1. Right hand side fits, but left doesn't:
%NaiveDateTime{calendar: calendar, day: day, month: month, year: year} =
  datetime_struct
  1. Neither right nor left hand side fits:
%NaiveDateTime{
  calendar: calendar,
  day: day,
  hour: hour,
  microsecond: microsecond,
  minute: minute,
  month: month,
  second: second,
  year: year} = 
  %NaiveDateTime{
    calendar: Calendar.ISO,
    day: 1,
    hour: 23,
    microsecond: {0, 0},
    minute: 59,
    month: 1,
    second: 59,
    year: 2017
  }

Any preference here? I'm thinking this:

Left hand side fits, but right doesn't:

datetime = %NaiveDateTime{
  calendar: Calendar.ISO, 
  day: 1, 
  month: 12, 
  year: 2017,
}

Right hand side fits, but left doesn't:

%NaiveDateTime{calendar: calendar, day: day, month: month, year: year} =
  datetime_struct

Neither right nor left hand side fits:

%NaiveDateTime{
  calendar: calendar,
  day: day,
  hour: hour,
  microsecond: microsecond,
  minute: minute,
  month: month,
  second: second,
  year: year,
} = %NaiveDateTime{
  calendar: Calendar.ISO,
  day: 1,
  hour: 23,
  microsecond: {0, 0},
  minute: 59,
  month: 1,
  second: 59,
  year: 2017,
}

Closing now that the code formatter has been released in Elixir v1.6.