csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

Return with ternary that contains a BinaryExpression ends up aligning everything on the left.

Open belav opened this issue 1 year ago • 1 comments

public class ClassName
{
    private string GetShopperReference(string customerNumber)
    {
        return
            adyenSettings.UseShipToNumberForVault
            && SiteContext.Current.ShipTo.CustomerSequence.IsNotBlank()
            ? SiteContext.Current.ShipTo.CustomerSequence
            : customerNumber;
    }
}

Should probably be something like

public class ClassName
{
    private string GetShopperReference(string customerNumber)
    {
        return
            adyenSettings.UseShipToNumberForVault
                && SiteContext.Current.ShipTo.CustomerSequence.IsNotBlank()
            ? SiteContext.Current.ShipTo.CustomerSequence
            : customerNumber;
    }
}

belav avatar Jan 16 '25 15:01 belav

There doesn't seem to be a good way of dealing with this. These are some related cases.

Auto adding the ( ) would make it more readable, but we don't auto add them anywhere else right now.

Indenting the && someOther..... doesn't work well with the 2nd case below, because then == and && are aligned.

return
    someLongBoolean________________________________________
    && someOtherLongBoolean____________________________________
    ? ifTrue
    : ifFalse;

return
    someLongCondition_________________________________________
        == someThingElse______________________
    && someOtherLongCondition____________________________________
    ? trueValue________________________________
    : falseValue_______________________________;

return (
    someLongCondition____________________________________
    && someOtherLongCondition____________________________________
)
    ? trueValue________________________________
    : falseValue_______________________________;

Although.... maybe this is feasible?

return someLongBoolean________________________________________
        && someOtherLongBoolean____________________________________
    ? ifTrue
    : ifFalse;

return someLongCondition_________________________________________
            == someThingElse______________________
        && someOtherLongCondition____________________________________
    ? trueValue________________________________
    : falseValue_______________________________;

return (
    someLongCondition____________________________________
    && someOtherLongCondition____________________________________
)
    ? trueValue________________________________
    : falseValue_______________________________;

belav avatar Jan 21 '25 01:01 belav