From 4e72ac0b55d35a9badd8d8050a8cd7b1112e7bd0 Mon Sep 17 00:00:00 2001 From: Sebastien Lebreton Date: Thu, 29 Aug 2024 17:49:07 +0200 Subject: [PATCH] Re-format codebase (#345) --- .../VectorMathTests.cs | 12 +++++----- .../AssetOperationInLoadAttributeMethod.cs | 6 ++--- .../BaseGetPositionAndRotationContext.cs | 6 ++--- .../BasePositionAndRotation.cs | 8 +++---- .../BaseVectorConversion.cs | 8 +++---- .../LoadAttributeMethod.cs | 4 ++-- .../MethodDeclarationExtensions.cs | 2 +- .../NullableReferenceTypesSuppressor.cs | 2 +- .../TagComparison.cs | 4 ++-- .../TryGetComponent.cs | 24 +++++++++---------- .../TypeSymbolExtensions.cs | 2 +- src/Microsoft.Unity.Analyzers/UnityStubs.cs | 13 +++++----- src/Microsoft.Unity.Analyzers/VectorMath.cs | 8 +++---- 13 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/Microsoft.Unity.Analyzers.Tests/VectorMathTests.cs b/src/Microsoft.Unity.Analyzers.Tests/VectorMathTests.cs index b9f6a579..737c8f0d 100644 --- a/src/Microsoft.Unity.Analyzers.Tests/VectorMathTests.cs +++ b/src/Microsoft.Unity.Analyzers.Tests/VectorMathTests.cs @@ -10,12 +10,12 @@ namespace Microsoft.Unity.Analyzers.Tests; -public class Vector2MathTests: VectorMathTests; -public class Vector3MathTests: VectorMathTests; -public class Vector4MathTests: VectorMathTests; -public class Float2MathTests: VectorMathTests; -public class Float3MathTests: VectorMathTests; -public class Float4MathTests: VectorMathTests; +public class Vector2MathTests : VectorMathTests; +public class Vector3MathTests : VectorMathTests; +public class Vector4MathTests : VectorMathTests; +public class Float2MathTests : VectorMathTests; +public class Float3MathTests : VectorMathTests; +public class Float4MathTests : VectorMathTests; public abstract class VectorMathTests : BaseCodeFixVerifierTest { diff --git a/src/Microsoft.Unity.Analyzers/AssetOperationInLoadAttributeMethod.cs b/src/Microsoft.Unity.Analyzers/AssetOperationInLoadAttributeMethod.cs index 439fe16a..3ad17566 100644 --- a/src/Microsoft.Unity.Analyzers/AssetOperationInLoadAttributeMethod.cs +++ b/src/Microsoft.Unity.Analyzers/AssetOperationInLoadAttributeMethod.cs @@ -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; @@ -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); } diff --git a/src/Microsoft.Unity.Analyzers/BaseGetPositionAndRotationContext.cs b/src/Microsoft.Unity.Analyzers/BaseGetPositionAndRotationContext.cs index 7d245c7a..ad81c414 100644 --- a/src/Microsoft.Unity.Analyzers/BaseGetPositionAndRotationContext.cs +++ b/src/Microsoft.Unity.Analyzers/BaseGetPositionAndRotationContext.cs @@ -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) diff --git a/src/Microsoft.Unity.Analyzers/BasePositionAndRotation.cs b/src/Microsoft.Unity.Analyzers/BasePositionAndRotation.cs index 30aebc6f..5e76ecfb 100644 --- a/src/Microsoft.Unity.Analyzers/BasePositionAndRotation.cs +++ b/src/Microsoft.Unity.Analyzers/BasePositionAndRotation.cs @@ -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; @@ -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; @@ -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(); diff --git a/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs b/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs index 0e309616..7f733bba 100644 --- a/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs +++ b/src/Microsoft.Unity.Analyzers/BaseVectorConversion.cs @@ -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; @@ -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) @@ -159,7 +159,7 @@ private async Task 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; diff --git a/src/Microsoft.Unity.Analyzers/LoadAttributeMethod.cs b/src/Microsoft.Unity.Analyzers/LoadAttributeMethod.cs index b241e169..e5243c1f 100644 --- a/src/Microsoft.Unity.Analyzers/LoadAttributeMethod.cs +++ b/src/Microsoft.Unity.Analyzers/LoadAttributeMethod.cs @@ -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); } diff --git a/src/Microsoft.Unity.Analyzers/MethodDeclarationExtensions.cs b/src/Microsoft.Unity.Analyzers/MethodDeclarationExtensions.cs index 3817b418..dd1de4b7 100644 --- a/src/Microsoft.Unity.Analyzers/MethodDeclarationExtensions.cs +++ b/src/Microsoft.Unity.Analyzers/MethodDeclarationExtensions.cs @@ -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; diff --git a/src/Microsoft.Unity.Analyzers/NullableReferenceTypesSuppressor.cs b/src/Microsoft.Unity.Analyzers/NullableReferenceTypesSuppressor.cs index f9ee6467..7a5e40e2 100644 --- a/src/Microsoft.Unity.Analyzers/NullableReferenceTypesSuppressor.cs +++ b/src/Microsoft.Unity.Analyzers/NullableReferenceTypesSuppressor.cs @@ -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; diff --git a/src/Microsoft.Unity.Analyzers/TagComparison.cs b/src/Microsoft.Unity.Analyzers/TagComparison.cs index f2275573..298bd2e6 100644 --- a/src/Microsoft.Unity.Analyzers/TagComparison.cs +++ b/src/Microsoft.Unity.Analyzers/TagComparison.cs @@ -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())); } @@ -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))); } } diff --git a/src/Microsoft.Unity.Analyzers/TryGetComponent.cs b/src/Microsoft.Unity.Analyzers/TryGetComponent.cs index 58ad790d..950cfe9e 100644 --- a/src/Microsoft.Unity.Analyzers/TryGetComponent.cs +++ b/src/Microsoft.Unity.Analyzers/TryGetComponent.cs @@ -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 @@ -240,18 +240,18 @@ private static async Task 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; } diff --git a/src/Microsoft.Unity.Analyzers/TypeSymbolExtensions.cs b/src/Microsoft.Unity.Analyzers/TypeSymbolExtensions.cs index b63d774c..240c10a5 100644 --- a/src/Microsoft.Unity.Analyzers/TypeSymbolExtensions.cs +++ b/src/Microsoft.Unity.Analyzers/TypeSymbolExtensions.cs @@ -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; } } diff --git a/src/Microsoft.Unity.Analyzers/UnityStubs.cs b/src/Microsoft.Unity.Analyzers/UnityStubs.cs index 05cb5d27..9bf6be68 100644 --- a/src/Microsoft.Unity.Analyzers/UnityStubs.cs +++ b/src/Microsoft.Unity.Analyzers/UnityStubs.cs @@ -9,7 +9,7 @@ using System.Collections.Generic; using Microsoft.Unity.Analyzers; -#pragma warning disable +#pragma warning disable namespace UnityEngine { @@ -50,7 +50,7 @@ class Sprite { } enum CubemapFace { } struct Color { } - + public struct Vector2 { } public struct Vector3 { } public struct Vector4 { } @@ -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) @@ -660,7 +661,7 @@ class VisualElement { } namespace UnityEngine.Scripting { - class PreserveAttribute : Attribute { } + class PreserveAttribute : Attribute { } } namespace UnityEditor.AssetImporters @@ -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 { diff --git a/src/Microsoft.Unity.Analyzers/VectorMath.cs b/src/Microsoft.Unity.Analyzers/VectorMath.cs index a7eafc0a..022ee2d8 100644 --- a/src/Microsoft.Unity.Analyzers/VectorMath.cs +++ b/src/Microsoft.Unity.Analyzers/VectorMath.cs @@ -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) @@ -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)