# Current formatting
results = if conn.is_a?(DB::Database)
conn.query(query_string, params)
else
conn.connection.query(query_string, params)
end
# Better IMO
results = if conn.is_a?(DB::Database)
conn.query(query_string, params)
else
conn.connection.query(query_string, params)
end
Just for reference, the Ruby style guide recommends the former.
Another alternative suggested there is to move the conditional to a new line:
results =
if conn.is_a?(DB::Database)
conn.query(query_string, params)
else
conn.connection.query(query_string, params)
end
The cleanest way to do it is
if conn.is_a?(DB::Database)
results = conn.query(query_string, params)
else
results = conn.connection.query(query_string, params)
end
which is perfectly valid in crystal.
I don't think we'll be changing this behaviour in the formatter though. If you want it flat use the assignments in the if blocks.
Alright; community opinion matters! :ok:
Most helpful comment
Just for reference, the Ruby style guide recommends the former.
Another alternative suggested there is to move the conditional to a new line: