Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
belav opened this issue Jan 16, 2025 · 1 comment
Milestone

Comments

@belav
Copy link
Owner

belav commented Jan 16, 2025

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 belav modified the milestones: 1.0.0, 0.31.0 Jan 16, 2025
@belav
Copy link
Owner Author

belav commented Jan 21, 2025

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_______________________________;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant