Skip to content

Commit

Permalink
Re-format codebase (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
sailro authored Aug 29, 2024
1 parent 35890b3 commit 4e72ac0
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 49 deletions.
12 changes: 6 additions & 6 deletions src/Microsoft.Unity.Analyzers.Tests/VectorMathTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace Microsoft.Unity.Analyzers.Tests;

public class Vector2MathTests: VectorMathTests<Vector2>;
public class Vector3MathTests: VectorMathTests<Vector3>;
public class Vector4MathTests: VectorMathTests<Vector4>;
public class Float2MathTests: VectorMathTests<float2>;
public class Float3MathTests: VectorMathTests<float3>;
public class Float4MathTests: VectorMathTests<float4>;
public class Vector2MathTests : VectorMathTests<Vector2>;
public class Vector3MathTests : VectorMathTests<Vector3>;
public class Vector4MathTests : VectorMathTests<Vector4>;
public class Float2MathTests : VectorMathTests<float2>;
public class Float3MathTests : VectorMathTests<float3>;
public class Float4MathTests : VectorMathTests<float4>;

public abstract class VectorMathTests<T> : BaseCodeFixVerifierTest<VectorMathAnalyzer, VectorMathCodeFix>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);

context.RegisterSyntaxNodeAction(AnalyzeMemberAccess, SyntaxKind.SimpleMemberAccessExpression);
}

private static void AnalyzeMemberAccess(SyntaxNodeAnalysisContext context)
{
if (context.Node is not MemberAccessExpressionSyntax {Expression: IdentifierNameSyntax ins})
if (context.Node is not MemberAccessExpressionSyntax { Expression: IdentifierNameSyntax ins })
return;

var text = ins.Identifier.Text;
Expand All @@ -63,7 +63,7 @@ private static void AnalyzeMemberAccess(SyntaxNodeAnalysisContext context)
}

private static bool IsStaticCtorInDecoratedType(IMethodSymbol methodSymbol, INamedTypeSymbol typeSymbol) => typeSymbol.StaticConstructors.Contains(methodSymbol)
&& InitializeOnLoadStaticCtorAnalyzer.IsDecorated(typeSymbol);
&& InitializeOnLoadStaticCtorAnalyzer.IsDecorated(typeSymbol);

private static bool IsDecoratedMethod(IMethodSymbol methodSymbol) => LoadAttributeMethodAnalyzer.IsDecorated(methodSymbol, onlyEditorAttributes: true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ public override bool TryGetPropertyExpression(SemanticModel model, ExpressionSyn
private static bool IsOutRefCompatible(SemanticModel model, ExpressionSyntax expression)
{
return model.GetSymbolInfo(expression).Symbol is ILocalSymbol symbol
&& IsOutRefCompatible(symbol.Type);
&& IsOutRefCompatible(symbol.Type);
}

private static bool IsOutRefCompatible(SemanticModel model, TypeSyntax type)
{
return model.GetSymbolInfo(type).Symbol is ITypeSymbol symbol
&& IsOutRefCompatible(symbol);
&& IsOutRefCompatible(symbol);
}

private static bool IsOutRefCompatible(ITypeSymbol type)
{
return type.Matches(typeof(Vector3))
|| type.Matches(typeof(Quaternion));
|| type.Matches(typeof(Quaternion));
}

public override bool TryGetArgumentExpression(SemanticModel model, ExpressionSyntax expression, [NotNullWhen(true)] out ArgumentSyntax? result)
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Unity.Analyzers/BasePositionAndRotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private bool IsPositionOrRotationCandidate(SemanticModel model, ExpressionSyntax
var symbolInfo = model.GetSymbolInfo(syntax);
if (symbolInfo.Symbol is not IPropertySymbol)
return false;

var expressionTypeInfo = model.GetTypeInfo(syntax.Expression);
if (expressionTypeInfo.Type == null)
return false;
Expand Down Expand Up @@ -139,7 +139,7 @@ protected void AnalyzeExpression(SyntaxNodeAnalysisContext context)

if (!ExpressionContext.TryGetPropertyExpression(model, nextExpression, out var nextSyntax))
return;

if (syntax.Expression.ToString() != nextSyntax.Expression.ToString())
return;

Expand Down Expand Up @@ -168,8 +168,8 @@ public abstract class BasePositionAndRotationCodeFix(BasePositionAndRotationCont

private BasePositionAndRotationContext ExpressionContext { get; } = expressionContext;

protected abstract string CodeFixTitle { get;}
protected abstract string CodeFixTitle { get; }

public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
var statement = await context.GetFixableNodeAsync<StatementSyntax>();
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
Expand Down Expand Up @@ -95,8 +95,8 @@ protected virtual bool CheckArguments(IObjectCreationOperation ocOperation)
private bool ArgumentMatches(IArgumentOperation argumentOperation, string name)
{
return argumentOperation.Value is IFieldReferenceOperation fieldOperation
&& fieldOperation.Field.Name == name
&& fieldOperation.Field.ContainingType.Matches(FromType);
&& fieldOperation.Field.Name == name
&& fieldOperation.Field.ContainingType.Matches(FromType);
}

internal static IdentifierNameSyntax? GetIdentifierNameSyntax(IArgumentOperation argumentOperation)
Expand Down Expand Up @@ -159,7 +159,7 @@ private async Task<Document> SimplifyObjectCreationAsync(Document document, Obje

var typeSyntax = SyntaxFactory.ParseTypeName(CastType.Name);
SyntaxNode castedSyntax = IsCastRequired(ocOperation) ? SyntaxFactory.CastExpression(typeSyntax, identifierNameSyntax) : identifierNameSyntax;

var newRoot = root?.ReplaceNode(ocSyntax, castedSyntax);
if (newRoot == null)
return document;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Unity.Analyzers/LoadAttributeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ internal static bool IsDecorated(IMethodSymbol symbol, bool onlyEditorAttributes
private static bool IsLoadAttributeType(ITypeSymbol type, bool onlyEditorAttributes)
{
return type.Matches(typeof(UnityEditor.InitializeOnLoadMethodAttribute))
|| type.Matches(typeof(UnityEditor.Callbacks.DidReloadScripts))
|| (type.Matches(typeof(UnityEngine.RuntimeInitializeOnLoadMethodAttribute)) && !onlyEditorAttributes);
|| type.Matches(typeof(UnityEditor.Callbacks.DidReloadScripts))
|| (type.Matches(typeof(UnityEngine.RuntimeInitializeOnLoadMethodAttribute)) && !onlyEditorAttributes);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Licensed under the MIT License. See LICENSE in the project root for license information.
*-------------------------------------------------------------------------------------------*/

using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Microsoft.Unity.Analyzers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static void AnalyzeFields(VariableDeclaratorSyntax declarator, Diagnosti

//suppress for fields that are not private and not static => statics cannot be set in editor and are not shown in the inspector and cannot be set there
if (!declarationSyntax.Modifiers.Any(modifier => modifier.IsKind(SyntaxKind.PrivateKeyword) || modifier.IsKind(SyntaxKind.StaticKeyword))
&& !declarationSyntax.AttributeLists.Any(attributeList => attributeList.Attributes.Any(attribute => attribute.Name.ToString() == nameof(UnityEngine.HideInInspector))))
&& !declarationSyntax.AttributeLists.Any(attributeList => attributeList.Attributes.Any(attribute => attribute.Name.ToString() == nameof(UnityEngine.HideInInspector))))
{
context.ReportSuppression(Suppression.Create(Rule, diagnostic));
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Unity.Analyzers/TagComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static void AnalyzeBinaryExpression(SyntaxNodeAnalysisContext context)
return;

if (IsReportableExpression(context, expr.Left)
|| IsReportableExpression(context, expr.Right))
|| IsReportableExpression(context, expr.Right))
context.ReportDiagnostic(Diagnostic.Create(Rule, expr.GetLocation()));
}

Expand Down Expand Up @@ -122,7 +122,7 @@ private static bool IsReportableSymbol(ISymbol symbol)

var containingType = propertySymbol.ContainingType;
return propertySymbol.Name == nameof(UnityEngine.Component.tag)
&& (containingType.Matches(typeof(UnityEngine.GameObject)) || containingType.Matches(typeof(UnityEngine.Component)));
&& (containingType.Matches(typeof(UnityEngine.GameObject)) || containingType.Matches(typeof(UnityEngine.Component)));
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/Microsoft.Unity.Analyzers/TryGetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ private static bool TryGetConditionIdentifier(SyntaxNode ifNode, [NotNullWhen(tr

// We want an Equals/NotEquals condition
if (!binaryExpression.IsKind(SyntaxKind.EqualsExpression) &&
!binaryExpression.IsKind(SyntaxKind.NotEqualsExpression))
!binaryExpression.IsKind(SyntaxKind.NotEqualsExpression))
return false;

// We want IdentifierNameSyntax and null as operands
Expand Down Expand Up @@ -240,18 +240,18 @@ private static async Task<Document> ReplaceWithTryGetComponentAsync(Document doc
switch (invocation.Expression)
{
case GenericNameSyntax directNameSyntax:
{
var newNameSyntax = directNameSyntax.WithIdentifier(identifier);
newInvocation = invocation.WithExpression(newNameSyntax);
break;
}
{
var newNameSyntax = directNameSyntax.WithIdentifier(identifier);
newInvocation = invocation.WithExpression(newNameSyntax);
break;
}
case MemberAccessExpressionSyntax { Name: GenericNameSyntax indirectNameSyntax } memberAccessExpression:
{
var newNameSyntax = indirectNameSyntax.WithIdentifier(identifier);
var newMemberAccessExpression = memberAccessExpression.WithName(newNameSyntax);
newInvocation = invocation.WithExpression(newMemberAccessExpression);
break;
}
{
var newNameSyntax = indirectNameSyntax.WithIdentifier(identifier);
var newMemberAccessExpression = memberAccessExpression.WithName(newNameSyntax);
newInvocation = invocation.WithExpression(newMemberAccessExpression);
break;
}
default:
return document;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Unity.Analyzers/TypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ public static bool Matches(this ITypeSymbol symbol, Type type)
}

return named.Name == type.Name
&& named.ContainingNamespace?.ToDisplayString() == type.Namespace;
&& named.ContainingNamespace?.ToDisplayString() == type.Namespace;
}
}
13 changes: 7 additions & 6 deletions src/Microsoft.Unity.Analyzers/UnityStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Collections.Generic;
using Microsoft.Unity.Analyzers;

#pragma warning disable
#pragma warning disable

namespace UnityEngine
{
Expand Down Expand Up @@ -50,7 +50,7 @@ class Sprite { }
enum CubemapFace { }

struct Color { }

public struct Vector2 { }
public struct Vector3 { }
public struct Vector4 { }
Expand Down Expand Up @@ -215,7 +215,8 @@ class Input
public static bool GetKeyDown(string name) { return false; }
}

internal class KeyTextAttribute : Attribute {
internal class KeyTextAttribute : Attribute
{
public string? Text { get; set; }

public KeyTextAttribute(string? text)
Expand Down Expand Up @@ -660,7 +661,7 @@ class VisualElement { }

namespace UnityEngine.Scripting
{
class PreserveAttribute : Attribute { }
class PreserveAttribute : Attribute { }
}

namespace UnityEditor.AssetImporters
Expand All @@ -684,11 +685,11 @@ class DidReloadScripts : Attribute { }

namespace UnityEditor
{
using AssetImporters;
using UnityEngine;
using UnityEngine.UIElements;
using AssetImporters;

class AssetDatabase {}
class AssetDatabase { }

class Editor : ScriptableObject
{
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Unity.Analyzers/VectorMath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static bool IsReportableExpression(SyntaxNodeAnalysisContext context, Sy
return false;

return IsSupportedExpression(context, node, vectorType)
&& NeedsOrdering(context, (ExpressionSyntax)node);
&& NeedsOrdering(context, (ExpressionSyntax)node);
}

private static bool NeedsOrdering(SyntaxNodeAnalysisContext context, ExpressionSyntax node)
Expand Down Expand Up @@ -106,9 +106,9 @@ private static bool NeedsOrdering(SyntaxNodeAnalysisContext context, ExpressionS
}

return firstVectorIndex != -1
&& lastScalarIndex != -1
&& firstVectorIndex < lastScalarIndex
&& scalarCount >= 2;
&& lastScalarIndex != -1
&& firstVectorIndex < lastScalarIndex
&& scalarCount >= 2;
}

internal static bool IsFloatType(TypeInfo typeInfo)
Expand Down

0 comments on commit 4e72ac0

Please sign in to comment.