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

Determine optimal formatting for ternary arguments #38588

Open
sharwell opened this issue Sep 9, 2019 · 2 comments
Open

Determine optimal formatting for ternary arguments #38588

sharwell opened this issue Sep 9, 2019 · 2 comments

Comments

@sharwell
Copy link
Member

sharwell commented Sep 9, 2019

The formatter doesn't produce readable code from the following expression:

CheckValidNullableMethodOverride(overridingMethod.DeclaringCompilation, overriddenMethod, overridingMethod, diagnostics,
checkReturnType ?
(diagnostics, overriddenMethod, overridingMethod, location) => diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInReturnTypeOnOverride, location) :
(Action<DiagnosticBag, MethodSymbol, MethodSymbol, Location>)null,
checkParameters ?
(diagnostics, overriddenMethod, overridingMethod, overridingParameter, location) =>
{
diagnostics.Add(
ErrorCode.WRN_NullabilityMismatchInParameterTypeOnOverride,
location,
new FormattedSymbol(overridingParameter, SymbolDisplayFormat.ShortFormat));
}
:
(Action<DiagnosticBag, MethodSymbol, MethodSymbol, ParameterSymbol, Location>)null,
overridingMemberLocation);

However, it's not clear how this code should be formatted such that the result is readable.

@JoeRobich
Copy link
Member

If we could convince the world to insert newlines before the ternary operator...

 CheckValidNullableMethodOverride(overridingMethod.DeclaringCompilation, overriddenMethod, overridingMethod, diagnostics, 
                                  checkReturnType
                                      ? (diagnostics, overriddenMethod, overridingMethod, location) => diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInReturnTypeOnOverride, location)
                                      : (Action<DiagnosticBag, MethodSymbol, MethodSymbol, Location>)null, 
                                  checkParameters
                                      ? (diagnostics, overriddenMethod, overridingMethod, overridingParameter, location) => 
                                      { 
                                          diagnostics.Add( 
                                              ErrorCode.WRN_NullabilityMismatchInParameterTypeOnOverride, 
                                              location, 
                                              new FormattedSymbol(overridingParameter, SymbolDisplayFormat.ShortFormat)); 
                                      } 
                                      : (Action<DiagnosticBag, MethodSymbol, MethodSymbol, ParameterSymbol, Location>)null, 
                                  overridingMemberLocation);

or to extract locals when code get too complex (for some definition of complex).

📎 "Hi, it looks like you are trying to do too much. Would you like some help extracting locals?"

@sharwell
Copy link
Member Author

sharwell commented Sep 9, 2019

The current formatter implementation won't allow the : to be indented after the }. That seems like an oversight.

@jinujoseph jinujoseph added this to the Backlog milestone Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants