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

Switch expressions should be broken if one line is too long #1302

Open
Nixxen opened this issue Jul 11, 2024 · 0 comments
Open

Switch expressions should be broken if one line is too long #1302

Nixxen opened this issue Jul 11, 2024 · 0 comments

Comments

@Nixxen
Copy link
Contributor

Nixxen commented Jul 11, 2024

Switch expressions (as with functions) should be broken if one line is too long to maintain readability.
This is an example of a switch expression return.
We have the line width set to 120 characters.

Input:

            return operation switch
            {
                GenericOperationEnum.OperationA => await GetOperationATimelineAsync(timelineRequest),
                GenericOperationEnum.OperationB => await GetOperationBTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationC => await GetOperationCTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationDLongerNameHere => await GetOperationDLongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationELongerNameHere => await GetOperationELongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationFLongerNameHere => await GetOperationFLongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationG => await GetOperationGTimelineAsync(timelineRequest),
                _ => new() { await GetGenericTimelineDataSeriesAsync(timelineRequest) },
            };

Output:

            return operation switch
            {
                GenericOperationEnum.OperationA => await GetOperationATimelineAsync(timelineRequest),
                GenericOperationEnum.OperationB => await GetOperationBTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationC => await GetOperationCTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationDLongerNameHere
                    => await GetOperationDLongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationELongerNameHere
                    => await GetOperationELongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationFLongerNameHere
                    => await GetOperationFLongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationG => await GetOperationGTimelineAsync(timelineRequest),
                _ => new() { await GetGenericTimelineDataSeriesAsync(timelineRequest) },
            };

Expected behavior:

            return operation switch
            {
                GenericOperationEnum.OperationA
                    => await GetOperationATimelineAsync(timelineRequest),
                GenericOperationEnum.OperationB
                    => await GetOperationBTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationC
                    => await GetOperationCTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationDLongerNameHere
                    => await GetOperationDLongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationELongerNameHere
                    => await GetOperationELongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationFLongerNameHere
                    => await GetOperationFLongerNameHereTimelineAsync(timelineRequest),
                GenericOperationEnum.OperationG
                    => await GetOperationGTimelineAsync(timelineRequest),
                _ 
                    => new() { await GetGenericTimelineDataSeriesAsync(timelineRequest) },
            };
@Nixxen Nixxen changed the title Switching expressions should be broken if one line is too long Switch expressions should be broken if one line is too long Jul 11, 2024
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