diff --git a/Datadog.Trace.Minimal.slnf b/Datadog.Trace.Minimal.slnf index 368a56d08428..d57cfc1be8a0 100644 --- a/Datadog.Trace.Minimal.slnf +++ b/Datadog.Trace.Minimal.slnf @@ -1,4 +1,4 @@ -{ +{ "solution": { "path": "Datadog.Trace.sln", "projects": [ @@ -7,6 +7,7 @@ "tracer\\src\\Datadog.Tracer.Native\\Datadog.Tracer.Native.vcxproj", "tracer\\src\\Datadog.Trace.MSBuild\\Datadog.Trace.MSBuild.csproj", "tracer\\src\\Datadog.Trace.Tools.Analyzers\\Datadog.Trace.Tools.Analyzers.csproj", + "tracer\\src\\Datadog.Trace.Tools.Analyzers.CodeFixes\\Datadog.Trace.Tools.Analyzers.CodeFixes.csproj", "tracer\\src\\Datadog.Trace\\Datadog.Trace.csproj", "tracer\\src\\Datadog.Trace.SourceGenerators\\Datadog.Trace.SourceGenerators.csproj"] } diff --git a/Datadog.Trace.sln b/Datadog.Trace.sln index 5285b115a52f..221af2bd7c2d 100644 --- a/Datadog.Trace.sln +++ b/Datadog.Trace.sln @@ -623,6 +623,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.Quartz", "tracer\te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.AzureFunctions.V4Isolated.HostLogsDisabled", "tracer\test\test-applications\azure-functions\Samples.AzureFunctions.V4Isolated.HostLogsDisabled\Samples.AzureFunctions.V4Isolated.HostLogsDisabled.csproj", "{C770F9F8-0430-587D-EB7A-8BEC2FE9B61C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Datadog.Trace.Tools.Analyzers.CodeFixes", "tracer\src\Datadog.Trace.Tools.Analyzers.CodeFixes\Datadog.Trace.Tools.Analyzers.CodeFixes.csproj", "{32521F0A-D52D-4DB1-86C4-3D72DEDA6E55}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1499,6 +1501,10 @@ Global {C770F9F8-0430-587D-EB7A-8BEC2FE9B61C}.Debug|Any CPU.Build.0 = Debug|Any CPU {C770F9F8-0430-587D-EB7A-8BEC2FE9B61C}.Release|Any CPU.ActiveCfg = Release|Any CPU {C770F9F8-0430-587D-EB7A-8BEC2FE9B61C}.Release|Any CPU.Build.0 = Release|Any CPU + {32521F0A-D52D-4DB1-86C4-3D72DEDA6E55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32521F0A-D52D-4DB1-86C4-3D72DEDA6E55}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32521F0A-D52D-4DB1-86C4-3D72DEDA6E55}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32521F0A-D52D-4DB1-86C4-3D72DEDA6E55}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1744,6 +1750,7 @@ Global {BB073E40-F46D-E52B-662E-395EED834111} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB} {CF69BC17-1527-425A-9B02-8E223BC31DB8} = {BAF8F246-3645-42AD-B1D0-0F7EAFBAB34A} {C770F9F8-0430-587D-EB7A-8BEC2FE9B61C} = {C4C1E313-C7C1-4490-AECE-0DD0062380A4} + {32521F0A-D52D-4DB1-86C4-3D72DEDA6E55} = {9E5F0022-0A50-40BF-AC6A-C3078585ECAB} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {160A1D00-1F5B-40F8-A155-621B4459D78F} diff --git a/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj b/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj index 4fb4bbab1c86..2e141f8141ce 100644 --- a/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj +++ b/tracer/src/Datadog.Trace.SourceGenerators/Datadog.Trace.SourceGenerators.csproj @@ -249,8 +249,8 @@ - - + + diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs similarity index 96% rename from tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs index b1197bbf4172..076d6ca73f03 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs @@ -10,7 +10,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -21,7 +20,7 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers; /// -/// A CodeFixProvider for the +/// A CodeFixProvider for the BeforeAfterAspectCodeFixProvider /// [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(BeforeAfterAspectCodeFixProvider))] [Shared] @@ -30,7 +29,7 @@ public class BeforeAfterAspectCodeFixProvider : CodeFixProvider /// public sealed override ImmutableArray FixableDiagnosticIds { - get => ImmutableArray.Create(BeforeAfterAspectAnalyzer.DiagnosticId); + get => ImmutableArray.Create(Diagnostics.BeforeAfterAspectDiagnosticId); } /// diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs similarity index 96% rename from tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs index d43a0a418329..8726c7bd4e59 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs @@ -9,7 +9,6 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -using Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; @@ -20,7 +19,7 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers; /// -/// A CodeFixProvider for the +/// A CodeFixProvider for the ReplaceAspectCodeFixProvider /// [ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ReplaceAspectCodeFixProvider))] [Shared] @@ -29,7 +28,7 @@ public class ReplaceAspectCodeFixProvider : CodeFixProvider /// public sealed override ImmutableArray FixableDiagnosticIds { - get => ImmutableArray.Create(ReplaceAspectAnalyzer.DiagnosticId); + get => ImmutableArray.Create(Diagnostics.ReplaceAspectDiagnosticId); } /// diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Datadog.Trace.Tools.Analyzers.CodeFixes.csproj b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Datadog.Trace.Tools.Analyzers.CodeFixes.csproj new file mode 100644 index 000000000000..26b3700a5235 --- /dev/null +++ b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Datadog.Trace.Tools.Analyzers.CodeFixes.csproj @@ -0,0 +1,29 @@ + + + + netstandard2.0 + false + false + RS2008 + Datadog.Trace.Tools.Analyzers + + + + + + + + + + + + + + + + + ConstantMessageTemplateCodeFixProvider.cs + + + + diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Directory.Build.props b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Directory.Build.props new file mode 100644 index 000000000000..3b5dcf35f636 --- /dev/null +++ b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Directory.Build.props @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/DuckTypeAnalyzer/DuckTypeNullCheckCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/DuckTypeAnalyzer/DuckTypeNullCheckCodeFixProvider.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/DuckTypeAnalyzer/DuckTypeNullCheckCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/DuckTypeAnalyzer/DuckTypeNullCheckCodeFixProvider.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Helpers/ObjectDisplay.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Helpers/ObjectDisplay.cs new file mode 100644 index 000000000000..9e7a59b58af9 --- /dev/null +++ b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Helpers/ObjectDisplay.cs @@ -0,0 +1,195 @@ +// +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. +// + +#nullable enable + +// This is essentially a vendoring of the ObjectDisplay helper (seeing as we can't reference the library directly + +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Text; +using Microsoft.CodeAnalysis.CSharp; + +namespace Datadog.Trace.Tools.Analyzers.Helpers; + +#pragma warning disable CA1200 // Avoid using cref tags with a prefix +/// +/// Displays a value in the C# style. +/// +/// +/// Separate from because we want to link this functionality into +/// the Formatter project and we don't want it to be public there. +/// +/// +#pragma warning restore CA1200 // Avoid using cref tags with a prefix +internal static class ObjectDisplay +{ + /// + /// Returns a C# string literal with the given value. + /// + public static string FormatLiteral(string value, bool useQuotes, bool escapeNonPrintable) + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + const char quote = '"'; + + var builder = new StringBuilder(); + + var isVerbatim = useQuotes && !escapeNonPrintable && ContainsNewLine(value); + + if (useQuotes) + { + if (isVerbatim) + { + builder.Append('@'); + } + + builder.Append(quote); + } + + for (int i = 0; i < value.Length; i++) + { + char c = value[i]; + if (escapeNonPrintable && CharUnicodeInfo.GetUnicodeCategory(c) == UnicodeCategory.Surrogate) + { + var category = CharUnicodeInfo.GetUnicodeCategory(value, i); + if (category == UnicodeCategory.Surrogate) + { + // an unpaired surrogate + builder.Append("\\u" + ((int)c).ToString("x4")); + } + else if (NeedsEscaping(category)) + { + // a surrogate pair that needs to be escaped + var unicode = char.ConvertToUtf32(value, i); + builder.Append("\\U" + unicode.ToString("x8")); + i++; // skip the already-encoded second surrogate of the pair + } + else + { + // copy a printable surrogate pair directly + builder.Append(c); + builder.Append(value[++i]); + } + } + else if (escapeNonPrintable && TryReplaceChar(c, out var replaceWith)) + { + builder.Append(replaceWith); + } + else if (useQuotes && c == quote) + { + if (isVerbatim) + { + builder.Append(quote); + builder.Append(quote); + } + else + { + builder.Append('\\'); + builder.Append(quote); + } + } + else + { + builder.Append(c); + } + } + + if (useQuotes) + { + builder.Append(quote); + } + + return builder.ToString(); + } + + private static bool ContainsNewLine(string s) + { + foreach (char c in s) + { + if (SyntaxFacts.IsNewLine(c)) + { + return true; + } + } + + return false; + } + + /// + /// Returns true if the character should be replaced and sets + /// to the replacement text. + /// + private static bool TryReplaceChar(char c, [NotNullWhen(returnValue: true)] out string? replaceWith) + { + replaceWith = null; + switch (c) + { + case '\\': + replaceWith = "\\\\"; + break; + case '\0': + replaceWith = "\\0"; + break; + case '\a': + replaceWith = "\\a"; + break; + case '\b': + replaceWith = "\\b"; + break; + case '\f': + replaceWith = "\\f"; + break; + case '\n': + replaceWith = "\\n"; + break; + case '\r': + replaceWith = "\\r"; + break; + case '\t': + replaceWith = "\\t"; + break; + case '\v': + replaceWith = "\\v"; + break; + } + + if (replaceWith != null) + { + return true; + } + + if (NeedsEscaping(CharUnicodeInfo.GetUnicodeCategory(c))) + { + replaceWith = "\\u" + ((int)c).ToString("x4"); + return true; + } + + return false; + } + + private static bool NeedsEscaping(UnicodeCategory category) + { + switch (category) + { + case UnicodeCategory.Control: + case UnicodeCategory.OtherNotAssigned: + case UnicodeCategory.ParagraphSeparator: + case UnicodeCategory.LineSeparator: + case UnicodeCategory.Surrogate: + return true; + default: + return false; + } + } +} diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringConcat.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringConcat.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringConcat.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringConcat.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringFormat.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringFormat.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringFormat.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringFormat.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringInterpolation.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringInterpolation.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringInterpolation.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.StringInterpolation.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ConstantMessageTemplateCodeFixProvider.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/CorrectContextCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/CorrectContextCodeFixProvider.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/CorrectContextCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/CorrectContextCodeFixProvider.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/DestructuringHintCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/DestructuringHintCodeFixProvider.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/DestructuringHintCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/DestructuringHintCodeFixProvider.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ExceptionPositionCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ExceptionPositionCodeFixProvider.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/ExceptionPositionCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/ExceptionPositionCodeFixProvider.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/PascalCaseCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/PascalCaseCodeFixProvider.cs similarity index 100% rename from tracer/src/Datadog.Trace.Tools.Analyzers/LogAnalyzer/PascalCaseCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/LogAnalyzer/PascalCaseCodeFixProvider.cs diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs similarity index 97% rename from tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs rename to tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs index ebea99470ba2..eb50f97ab705 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs @@ -26,7 +26,7 @@ public class ThreadAbortCodeFixProvider : CodeFixProvider /// public sealed override ImmutableArray FixableDiagnosticIds { - get { return ImmutableArray.Create(ThreadAbortAnalyzer.DiagnosticId); } + get { return ImmutableArray.Create(Diagnostics.ThreadAbortDiagnosticId); } } /// diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectAnalyzer.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectAnalyzer.cs index 661de1a4c1b3..1b0d66516254 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectAnalyzer.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectAnalyzer.cs @@ -21,11 +21,6 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers; [DiagnosticAnalyzer(LanguageNames.CSharp)] public class BeforeAfterAspectAnalyzer : DiagnosticAnalyzer { - /// - /// The diagnostic ID displayed in error messages - /// - public const string DiagnosticId = "DD0004"; - /// /// The severity of the diagnostic /// @@ -33,7 +28,7 @@ public class BeforeAfterAspectAnalyzer : DiagnosticAnalyzer #pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project private static readonly DiagnosticDescriptor MissingTryCatchRule = new( - DiagnosticId, + Diagnostics.BeforeAfterAspectDiagnosticId, title: "Aspect is missing try-catch block", messageFormat: "Aspect method bodies should contain a try-catch block at the top level", category: "Reliability", diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/Diagnostics.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/Diagnostics.cs new file mode 100644 index 000000000000..34a88123ad97 --- /dev/null +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/Diagnostics.cs @@ -0,0 +1,22 @@ +// +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. +// + +namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers; + +/// +/// Helper class for holding various diagnostics. +/// +public class Diagnostics +{ + /// + /// The diagnostic ID displayed in error messages + /// + public const string BeforeAfterAspectDiagnosticId = "DD0004"; + + /// + /// The diagnostic ID displayed in error messages + /// + public const string ReplaceAspectDiagnosticId = "DD0005"; +} diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs index 9f2ad3a0c2fe..c375bade4d9b 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs @@ -20,11 +20,6 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers; [DiagnosticAnalyzer(LanguageNames.CSharp)] public class ReplaceAspectAnalyzer : DiagnosticAnalyzer { - /// - /// The diagnostic ID displayed in error messages - /// - public const string DiagnosticId = "DD0005"; - /// /// The severity of the diagnostic /// @@ -32,7 +27,7 @@ public class ReplaceAspectAnalyzer : DiagnosticAnalyzer #pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project private static readonly DiagnosticDescriptor MissingTryCatchRule = new( - DiagnosticId, + Diagnostics.ReplaceAspectDiagnosticId, title: "Aspect is in incorrect format", messageFormat: "Aspect method bodies should contain a single expression to set the result variable, and then have a try-catch block, and then return the created variable", category: "Reliability", diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj b/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj index c1906dbfbe82..cb5299e8c72e 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/Datadog.Trace.Tools.Analyzers.csproj @@ -8,9 +8,8 @@ - - - + + @@ -20,9 +19,6 @@ Helpers\System.Runtime.CompilerServices.Attributes.cs - - ConstantMessageTemplateCodeFixProvider.cs - diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/Diagnostics.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/Diagnostics.cs new file mode 100644 index 000000000000..d114a6297ca1 --- /dev/null +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/Diagnostics.cs @@ -0,0 +1,17 @@ +// +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. +// + +namespace Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer; + +/// +/// Helper class for holding various diagnostics. +/// +public class Diagnostics +{ + /// + /// The diagnostic ID displayed in error messages + /// + public const string ThreadAbortDiagnosticId = "DD0001"; +} diff --git a/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortAnalyzer.cs b/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortAnalyzer.cs index 7ab24fcbfd94..3e7cda8d566f 100644 --- a/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortAnalyzer.cs +++ b/tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortAnalyzer.cs @@ -45,14 +45,9 @@ namespace Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer [DiagnosticAnalyzer(LanguageNames.CSharp)] public class ThreadAbortAnalyzer : DiagnosticAnalyzer { - /// - /// The diagnostic ID displayed in error messages - /// - public const string DiagnosticId = "DD0001"; - #pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor( - DiagnosticId, + Diagnostics.ThreadAbortDiagnosticId, title: "Potential infinite loop on ThreadAbortException", messageFormat: "Potential infinite loop - you should rethrow Exception in catch block", category: "Reliability", diff --git a/tracer/src/Datadog.Trace.Tools.dd_dotnet.SourceGenerators/Datadog.Trace.Tools.dd_dotnet.SourceGenerators.csproj b/tracer/src/Datadog.Trace.Tools.dd_dotnet.SourceGenerators/Datadog.Trace.Tools.dd_dotnet.SourceGenerators.csproj index b449fc0605bc..aec070c27411 100644 --- a/tracer/src/Datadog.Trace.Tools.dd_dotnet.SourceGenerators/Datadog.Trace.Tools.dd_dotnet.SourceGenerators.csproj +++ b/tracer/src/Datadog.Trace.Tools.dd_dotnet.SourceGenerators/Datadog.Trace.Tools.dd_dotnet.SourceGenerators.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/tracer/src/Directory.Build.props b/tracer/src/Directory.Build.props index 4cbecfac6740..80340c0e369d 100644 --- a/tracer/src/Directory.Build.props +++ b/tracer/src/Directory.Build.props @@ -44,6 +44,7 @@ + diff --git a/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj b/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj index 5a8b90f8e1a4..4b07c88298db 100644 --- a/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj +++ b/tracer/test/Datadog.Trace.SourceGenerators.Tests/Datadog.Trace.SourceGenerators.Tests.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/BeforeAfterAspectAnalyzerTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/BeforeAfterAspectAnalyzerTests.cs index d92e8d7c00c2..51e527a7a9d1 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/BeforeAfterAspectAnalyzerTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/BeforeAfterAspectAnalyzerTests.cs @@ -2,6 +2,7 @@ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; using System.Threading.Tasks; using Datadog.Trace.Tools.Analyzers.AspectAnalyzers; @@ -10,14 +11,14 @@ using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.AspectAnalyzers.BeforeAfterAspectAnalyzer, - Datadog.Trace.Tools.Analyzers.AspectAnalyzers.BeforeAfterAspectCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.AspectAnalyzers.BeforeAfterAspectCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.AspectAnalyzers; public class BeforeAfterAspectAnalyzerTests { - private const string DiagnosticId = BeforeAfterAspectAnalyzer.DiagnosticId; + private const string DiagnosticId = Diagnostics.BeforeAfterAspectDiagnosticId; private const DiagnosticSeverity Severity = BeforeAfterAspectAnalyzer.Severity; // No diagnostics expected to show up diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/ReplaceAspectAnalyzerTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/ReplaceAspectAnalyzerTests.cs index 320c5778a6e4..427c35d77210 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/ReplaceAspectAnalyzerTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/ReplaceAspectAnalyzerTests.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; + using System.Threading.Tasks; using Datadog.Trace.Tools.Analyzers.AspectAnalyzers; using Microsoft.CodeAnalysis; @@ -10,14 +12,14 @@ using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.AspectAnalyzers.ReplaceAspectAnalyzer, - Datadog.Trace.Tools.Analyzers.AspectAnalyzers.ReplaceAspectCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.AspectAnalyzers.ReplaceAspectCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.AspectAnalyzers; public class ReplaceAspectAnalyzerTests { - private const string DiagnosticId = ReplaceAspectAnalyzer.DiagnosticId; + private const string DiagnosticId = Diagnostics.ReplaceAspectDiagnosticId; private const DiagnosticSeverity Severity = ReplaceAspectAnalyzer.Severity; // No diagnostics expected to show up diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj index 307d2375d740..d4074785a4c8 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/Datadog.Trace.Tools.Analyzers.Tests.csproj @@ -6,13 +6,15 @@ - + + diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/DuckTypeAnalyzers/DuckTypeNullCheckAnalyzerTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/DuckTypeAnalyzers/DuckTypeNullCheckAnalyzerTests.cs index 174947d190f0..d2def79ac573 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/DuckTypeAnalyzers/DuckTypeNullCheckAnalyzerTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/DuckTypeAnalyzers/DuckTypeNullCheckAnalyzerTests.cs @@ -2,6 +2,7 @@ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; using System.Threading.Tasks; using Datadog.Trace.Tools.Analyzers.DuckTypeAnalyzer; @@ -10,7 +11,7 @@ using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.DuckTypeAnalyzer.DuckTypeNullCheckAnalyzer, - Datadog.Trace.Tools.Analyzers.DuckTypeAnalyzer.DuckTypeNullCheckCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.DuckTypeAnalyzer.DuckTypeNullCheckCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.DuckTypeAnalyzers; diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/ConstantMessageTemplateDiagnosticTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/ConstantMessageTemplateDiagnosticTests.cs index 7d0941c526db..7241a1dc64e2 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/ConstantMessageTemplateDiagnosticTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/ConstantMessageTemplateDiagnosticTests.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; + using System; using System.Threading; using System.Threading.Tasks; @@ -11,7 +13,7 @@ using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.LogAnalyzer.LogAnalyzer, - Datadog.Trace.Tools.Analyzers.LogAnalyzer.ConstantMessageTemplateCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.ConstantMessageTemplateCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.LogAnalyzer; @@ -1026,7 +1028,7 @@ private static async Task VerifyWithExpectedCompileError(string src, string fix, await Helpers.VerifyWithExpectedCompileError< Datadog.Trace.Tools.Analyzers.LogAnalyzer.LogAnalyzer, - Datadog.Trace.Tools.Analyzers.LogAnalyzer.ConstantMessageTemplateCodeFixProvider>( + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.ConstantMessageTemplateCodeFixProvider>( src, expected, fix, expectedInFix); } } diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectContextDiagnosticTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectContextDiagnosticTests.cs index 1f7719255aa8..da13f677c767 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectContextDiagnosticTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/CorrectContextDiagnosticTests.cs @@ -2,6 +2,7 @@ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License. // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -9,7 +10,7 @@ using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.LogAnalyzer.LogAnalyzer, - Datadog.Trace.Tools.Analyzers.LogAnalyzer.CorrectContextCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.CorrectContextCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.LogAnalyzer; diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/DestructureAnonymousObjectsDiagnosticTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/DestructureAnonymousObjectsDiagnosticTests.cs index 55f4923f9555..7258a673b876 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/DestructureAnonymousObjectsDiagnosticTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/DestructureAnonymousObjectsDiagnosticTests.cs @@ -3,13 +3,15 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; + using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Testing; using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.LogAnalyzer.LogAnalyzer, - Datadog.Trace.Tools.Analyzers.LogAnalyzer.DestructuringHintCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.DestructuringHintCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.LogAnalyzer; diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PascalPropertyNameDiagnosticTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PascalPropertyNameDiagnosticTests.cs index eba82ef18cd7..5244266ab243 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PascalPropertyNameDiagnosticTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PascalPropertyNameDiagnosticTests.cs @@ -3,6 +3,8 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; + using System; using System.Threading.Tasks; using Microsoft.CodeAnalysis; @@ -10,7 +12,7 @@ using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.LogAnalyzer.LogAnalyzer, - Datadog.Trace.Tools.Analyzers.LogAnalyzer.PascalCaseCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.PascalCaseCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.LogAnalyzer; diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs index 062a0f8167fc..648771b9cf68 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/LogAnalyzer/PropertyDiagnosticTests.cs @@ -3,15 +3,18 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; + using System; using System.Threading.Tasks; using Datadog.Trace.Tools.Analyzers.LogAnalyzer; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Testing; using Xunit; +using ExceptionPositionCodeFixProvider = AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.ExceptionPositionCodeFixProvider; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.LogAnalyzer.LogAnalyzer, - Datadog.Trace.Tools.Analyzers.LogAnalyzer.ExceptionPositionCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.LogAnalyzer.ExceptionPositionCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests.LogAnalyzer; diff --git a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/ThreadAbortAnalyzerTests.cs b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/ThreadAbortAnalyzerTests.cs index 5ebb78f5c06c..9052e39a8a75 100644 --- a/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/ThreadAbortAnalyzerTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Analyzers.Tests/ThreadAbortAnalyzerTests.cs @@ -3,20 +3,22 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +extern alias AnalyzerCodeFixes; + using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Testing; using Xunit; using Verifier = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer.ThreadAbortAnalyzer, - Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer.ThreadAbortCodeFixProvider, + AnalyzerCodeFixes::Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer.ThreadAbortCodeFixProvider, Microsoft.CodeAnalysis.Testing.DefaultVerifier>; namespace Datadog.Trace.Tools.Analyzers.Tests { public class ThreadAbortAnalyzerTests { - private const string DiagnosticId = ThreadAbortAnalyzer.ThreadAbortAnalyzer.DiagnosticId; + private const string DiagnosticId = ThreadAbortAnalyzer.Diagnostics.ThreadAbortDiagnosticId; public static TheoryData GetExceptions() => new() { "Exception", "SystemException", "ThreadAbortException" };