csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Operators expressions: keep 1st operand on 1st line?

Open jods4 opened this issue 1 year ago • 1 comments

Input:

bool isGlobal = some_random_condition_that_is_not_so_short()
  || or_else_some_other_condition_that_makes_this_line_long________;

int total = lets_do_a_long_sum__________
  + 42_000_000
  + another_summand____________________
  + last_one;


int total = lets_do_a_long_sum__________
  + 42_000_000
  + another_summand____________________
  + last_one_that_makes_this_excessive;

Output:

// Formatted by 0.27.2

bool isGlobal =
    some_random_condition_that_is_not_so_short()
    || or_else_some_other_condition_that_makes_this_line_long________;

int total =
    lets_do_a_long_sum__________ + 42_000_000 + another_summand____________________ + last_one;

int total =
    lets_do_a_long_sum__________
    + 42_000_000
    + another_summand____________________
    + last_one_that_makes_this_excessive;

Expected behavior: I tend to prefer the input, but that could be debatable?

With current format I don't like how:

  • the first line remains almost empty
  • the first operand visually seems dedented with respect to operators on following lines

I realise that, once more, this would break the Rectangle Rule.

jods4 avatar Jan 31 '24 20:01 jods4

FWIW Prettier matches the current behavior of CSharpier, which is probably how things ended up this way.

Making this change would get things consistent with how method calls work.

int total = CallMethod(
    lets_do_a_long_sum_____________________________________
      + 42_000_000
      + another_summand________________________________________
      + last_one
);

Initializers should also be changed, I don't recall if they use the same code as an assignment.

var x =
{
    Y =
        lets_do_a_long_sum_____________________________________
        + 42_000_000
        + another_summand________________________________________
        + last_one
};

belav avatar Feb 11 '24 23:02 belav