Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 115a216

Browse files
committed
C#: Format nested ternary operators
1 parent c38bf5e commit 115a216

9 files changed

Lines changed: 46 additions & 27 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ public ExtractionProgress(ILogger output)
107107
public void Analysed(int item, int total, string source, string output, TimeSpan time, AnalysisAction action)
108108
{
109109
logger.Log(Severity.Info, "[{0}/{1}] {2} ({3})", item, total, source,
110-
action == AnalysisAction.Extracted ? time.ToString() : action == AnalysisAction.Excluded ? "excluded" : "up to date");
110+
action == AnalysisAction.Extracted
111+
? time.ToString()
112+
: action == AnalysisAction.Excluded
113+
? "excluded"
114+
: "up to date");
111115
}
112116

113117
public void MissingType(string type)

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ void DoExtractTree(SyntaxTree tree)
381381
}
382382
}
383383

384-
ReportProgress(sourcePath, trapPath, stopwatch.Elapsed, excluded ? AnalysisAction.Excluded : upToDate ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
384+
ReportProgress(sourcePath, trapPath, stopwatch.Elapsed, excluded
385+
? AnalysisAction.Excluded
386+
: upToDate
387+
? AnalysisAction.UpToDate
388+
: AnalysisAction.Extracted);
385389
}
386390
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
387391
{

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ protected sealed override void Populate(TextWriter trapFile)
7878
/// <returns>The string representation.</returns>
7979
public static string ValueAsString(object value)
8080
{
81-
return value == null ? "null" : value is bool ? ((bool)value ? "true" : "false") : value.ToString();
81+
return value == null
82+
? "null"
83+
: value is bool b
84+
? b
85+
? "true"
86+
: "false"
87+
: value.ToString();
8288
}
8389

8490
/// <summary>

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/ElementAccess.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ static ExprKind GetKind(Context cx, ExpressionSyntax qualifier)
6161
return ExprKind.POINTER_INDIRECTION;
6262
}
6363

64-
return IsDynamic(cx, qualifier) ?
65-
ExprKind.DYNAMIC_ELEMENT_ACCESS :
66-
qualifierType.Symbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array ?
67-
ExprKind.ARRAY_ACCESS :
68-
ExprKind.INDEXER_ACCESS;
64+
return IsDynamic(cx, qualifier)
65+
? ExprKind.DYNAMIC_ELEMENT_ACCESS
66+
: qualifierType.Symbol.TypeKind == Microsoft.CodeAnalysis.TypeKind.Array
67+
? ExprKind.ARRAY_ACCESS
68+
: ExprKind.INDEXER_ACCESS;
6969
}
7070
}
7171

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/Invocation.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ static bool IsLocalFunctionInvocation(ExpressionNodeInfo info)
161161

162162
static ExprKind GetKind(ExpressionNodeInfo info)
163163
{
164-
return IsNameof((InvocationExpressionSyntax)info.Node) ?
165-
ExprKind.NAMEOF :
166-
IsDelegateCall(info) ?
167-
ExprKind.DELEGATE_INVOCATION :
168-
IsLocalFunctionInvocation(info) ?
169-
ExprKind.LOCAL_FUNCTION_INVOCATION :
170-
ExprKind.METHOD_INVOCATION;
164+
return IsNameof((InvocationExpressionSyntax)info.Node)
165+
? ExprKind.NAMEOF
166+
: IsDelegateCall(info)
167+
? ExprKind.DELEGATE_INVOCATION
168+
: IsLocalFunctionInvocation(info)
169+
? ExprKind.LOCAL_FUNCTION_INVOCATION
170+
: ExprKind.METHOD_INVOCATION;
171171
}
172172

173173
static bool IsNameof(InvocationExpressionSyntax syntax)

csharp/extractor/Semmle.Extraction.CSharp/Entities/LocalVariable.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ public override void Populate(TextWriter trapFile) { }
2323
public void PopulateManual(Expression parent, bool isVar)
2424
{
2525
var trapFile = Context.TrapWriter.Writer;
26-
var (kind, type) =
27-
symbol is ILocalSymbol l ?
28-
(l.IsRef ? 3 : l.IsConst ? 2 : 1, Type.Create(Context, l.GetAnnotatedType())) :
29-
(1, parent.Type);
26+
var (kind, type) = symbol is ILocalSymbol l
27+
? (l.IsRef ? 3 : l.IsConst ? 2 : 1, Type.Create(Context, l.GetAnnotatedType()))
28+
: (1, parent.Type);
3029
trapFile.localvars(this, kind, symbol.Name, isVar ? 1 : 0, type.Type.TypeRef, parent);
3130

3231
if (symbol is ILocalSymbol local)

csharp/extractor/Semmle.Extraction.CSharp/Entities/Types/NamedType.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ static AnnotatedTypeSymbol GetElementType(Context cx, INamedTypeSymbol type)
164164

165165
static AnnotatedTypeSymbol GetEnumerableType(Context cx, INamedTypeSymbol type)
166166
{
167-
return type.SpecialType == SpecialType.System_Collections_IEnumerable ?
168-
cx.Compilation.ObjectType.WithAnnotation(NullableAnnotation.NotAnnotated) :
169-
type.OriginalDefinition.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T ?
170-
type.GetAnnotatedTypeArguments().First() :
171-
default(AnnotatedTypeSymbol);
167+
return type.SpecialType == SpecialType.System_Collections_IEnumerable
168+
? cx.Compilation.ObjectType.WithAnnotation(NullableAnnotation.NotAnnotated)
169+
: type.OriginalDefinition.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T
170+
? type.GetAnnotatedTypeArguments().First()
171+
: default(AnnotatedTypeSymbol);
172172
}
173173

174174
public override AnnotatedType ElementType => Type.Create(Context, GetElementType(Context, symbol));

csharp/extractor/Semmle.Extraction.CSharp/Extractor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ public void Analysed(int item, int total, string source, string output, TimeSpan
3737
if (action != AnalysisAction.UpToDate)
3838
{
3939
Logger.Log(Severity.Info, " {0} ({1})", source,
40-
action == AnalysisAction.Extracted ? time.ToString() : action == AnalysisAction.Excluded ? "excluded" : "up to date");
40+
action == AnalysisAction.Extracted
41+
? time.ToString()
42+
: action == AnalysisAction.Excluded
43+
? "excluded"
44+
: "up to date");
4145
}
4246
}
4347

csharp/extractor/Semmle.Extraction/Entities/Location.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ protected Location(Context cx, Microsoft.CodeAnalysis.Location? init)
77
: base(cx, init) { }
88

99
public static Location Create(Context cx, Microsoft.CodeAnalysis.Location? loc) =>
10-
(loc == null || loc.Kind == Microsoft.CodeAnalysis.LocationKind.None) ? GeneratedLocation.Create(cx)
11-
: loc.IsInSource ? NonGeneratedSourceLocation.Create(cx, loc)
10+
(loc == null || loc.Kind == Microsoft.CodeAnalysis.LocationKind.None)
11+
? GeneratedLocation.Create(cx)
12+
: loc.IsInSource
13+
? NonGeneratedSourceLocation.Create(cx, loc)
1214
: Assembly.Create(cx, loc);
1315

1416
public override Microsoft.CodeAnalysis.Location? ReportingLocation => symbol;

0 commit comments

Comments
 (0)