From bb0bfb82748e99e1380c386fb93c6aeb3d2ac25c Mon Sep 17 00:00:00 2001
From: m-nash <64171366+m-nash@users.noreply.github.com>
Date: Tue, 18 Jun 2024 12:59:42 -0700
Subject: [PATCH] use azure-sdk-for-net ruleset (#3608)
Fixes https://github.com/microsoft/typespec/issues/3368
---
.../eng/CodeAnalysis.ruleset | 617 ++++++++++++------
.../Providers/MrwSerializationTypeProvider.cs | 1 -
.../src/InputTypes/OperationKinds.cs | 3 +-
.../src/Configuration.cs | 1 -
.../FormattableStringExpression.cs | 1 -
.../src/Providers/ArgumentProvider.cs | 1 -
.../src/Shared/StringExtensions.cs | 1 -
.../src/Snippets/Snippet.JsonSerializer.cs | 1 -
.../src/Snippets/Snippet.cs | 4 +-
.../src/SourceInput/SourceInputModel.cs | 1 -
10 files changed, 405 insertions(+), 226 deletions(-)
diff --git a/packages/http-client-csharp/eng/CodeAnalysis.ruleset b/packages/http-client-csharp/eng/CodeAnalysis.ruleset
index dc1f30e37c..63952ce525 100644
--- a/packages/http-client-csharp/eng/CodeAnalysis.ruleset
+++ b/packages/http-client-csharp/eng/CodeAnalysis.ruleset
@@ -1,217 +1,404 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeProvider.cs
index b0c51c8160..68d3eee89e 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeProvider.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeProvider.cs
@@ -85,7 +85,6 @@ protected override MethodProvider[] BuildConstructors()
ctorWithNoParamsExist = true;
}
-
if (!serializationCtorParamsMatch)
{
// Check if the model constructor parameters match the serialization constructor parameters
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.Input/src/InputTypes/OperationKinds.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.Input/src/InputTypes/OperationKinds.cs
index f76abba61b..359e2a37bd 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.Input/src/InputTypes/OperationKinds.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.Input/src/InputTypes/OperationKinds.cs
@@ -1,7 +1,6 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
+// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-
using System;
using System.ComponentModel;
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Configuration.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Configuration.cs
index 38cfd97c18..1f63fb8eac 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Configuration.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Configuration.cs
@@ -168,7 +168,6 @@ private static string ReadRequiredStringOption(JsonElement root, string option)
return ReadStringOption(root, option) ?? throw new InvalidOperationException($"Unable to parse required option {option} from configuration.");
}
-
private static string? ReadStringOption(JsonElement root, string option)
{
if (root.TryGetProperty(option, out JsonElement value))
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Expressions/FormattableStringExpression.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Expressions/FormattableStringExpression.cs
index fab355473a..f33202003f 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Expressions/FormattableStringExpression.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Expressions/FormattableStringExpression.cs
@@ -23,7 +23,6 @@ public FormattableStringExpression(string format, IReadOnlyList
Args = args;
}
-
private string Format { get; init; }
private IReadOnlyList Args { get; init; }
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ArgumentProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ArgumentProvider.cs
index 0f6c1d7795..9873592d6a 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ArgumentProvider.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ArgumentProvider.cs
@@ -81,7 +81,6 @@ protected override MethodProvider[] BuildMethods()
];
}
-
private MethodProvider BuildAssertNull()
{
var valueParam = new ParameterProvider("value", $"The value.", _t);
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Shared/StringExtensions.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Shared/StringExtensions.cs
index a400db4e5b..65b7683c0c 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Shared/StringExtensions.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Shared/StringExtensions.cs
@@ -84,7 +84,6 @@ public static string ToCleanName(this string name, bool isCamelCase = true)
[return: NotNullIfNotNull(nameof(name))]
public static string ToVariableName(this string name) => ToCleanName(name, isCamelCase: false);
-
public static GetPathPartsEnumerator GetPathParts(string? path) => new GetPathPartsEnumerator(path);
public ref struct GetPathPartsEnumerator
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.JsonSerializer.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.JsonSerializer.cs
index a3dea28d30..3e2a9cf234 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.JsonSerializer.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.JsonSerializer.cs
@@ -8,7 +8,6 @@ namespace Microsoft.Generator.CSharp.Snippets
{
public static partial class Snippet
{
-
public static class JsonSerializer
{
public static InvokeStaticMethodExpression Serialize(ValueExpression writer, ValueExpression value, ValueExpression? options = null)
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.cs
index d3f9854baf..524b5f46bd 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Snippets/Snippet.cs
@@ -19,8 +19,8 @@ internal override void Write(CodeWriter writer)
}
}
- public readonly static MethodBodyStatement EmptyStatement = new();
- public readonly static MethodBodyStatement EmptyLineStatement = new PrivateEmptyLineStatement();
+ public static readonly MethodBodyStatement EmptyStatement = new();
+ public static readonly MethodBodyStatement EmptyLineStatement = new PrivateEmptyLineStatement();
public static ExtensibleSnippets Extensible => CodeModelPlugin.Instance.ExtensibleSnippets;
public static MethodBodyStatement AsStatement(this IEnumerable statements) => statements.ToArray();
diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/SourceInput/SourceInputModel.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/SourceInput/SourceInputModel.cs
index 327e56c017..eeb4f81b36 100644
--- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/SourceInput/SourceInputModel.cs
+++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/SourceInput/SourceInputModel.cs
@@ -146,7 +146,6 @@ private bool TryGetName(ISymbol symbol, [NotNullWhen(true)] out string? name)
private async Task LoadBaselineContract()
{
-
string fullPath;
string projectFilePath = Path.GetFullPath(Path.Combine(CodeModelPlugin.Instance.Configuration.ProjectDirectory, $"{CodeModelPlugin.Instance.Configuration.Namespace}.csproj"));
if (!File.Exists(projectFilePath))