Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Datadog.Trace.Minimal.slnf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"solution": {
"path": "Datadog.Trace.sln",
"projects": [
Expand All @@ -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"]
}
Expand Down
7 changes: 7 additions & 0 deletions Datadog.Trace.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Content Include="..\Datadog.Trace\Vendors\MessagePack\Formatters\ForceSizePrimitiveFormatter.tt">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +20,7 @@
namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;

/// <summary>
/// A CodeFixProvider for the <see cref="ThreadAbortAnalyzer"/>
/// A CodeFixProvider for the BeforeAfterAspectCodeFixProvider
/// </summary>
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(BeforeAfterAspectCodeFixProvider))]
[Shared]
Expand All @@ -30,7 +29,7 @@ public class BeforeAfterAspectCodeFixProvider : CodeFixProvider
/// <inheritdoc />
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get => ImmutableArray.Create(BeforeAfterAspectAnalyzer.DiagnosticId);
get => ImmutableArray.Create(Diagnostics.BeforeAfterAspectDiagnosticId);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +19,7 @@
namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;

/// <summary>
/// A CodeFixProvider for the <see cref="ThreadAbortAnalyzer"/>
/// A CodeFixProvider for the ReplaceAspectCodeFixProvider
/// </summary>
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ReplaceAspectCodeFixProvider))]
[Shared]
Expand All @@ -29,7 +28,7 @@ public class ReplaceAspectCodeFixProvider : CodeFixProvider
/// <inheritdoc />
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get => ImmutableArray.Create(ReplaceAspectAnalyzer.DiagnosticId);
get => ImmutableArray.Create(Diagnostics.ReplaceAspectDiagnosticId);
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsPackable>false</IsPackable>
<EnforceExtendedAnalyzerRules>false</EnforceExtendedAnalyzerRules>
<NoWarn>RS2008</NoWarn>
<RootNamespace>Datadog.Trace.Tools.Analyzers</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Datadog.Trace.Tools.Analyzers\AspectAnalyzers\Diagnostics.cs" Link="AspectAnalyzers\Diagnostics.cs" />
<Compile Include="..\Datadog.Trace.Tools.Analyzers\DuckTypeAnalyzer\DuckDiagnostics.cs" Link="DuckTypeAnalyzer\DuckDiagnostics.cs" />
<Compile Include="..\Datadog.Trace.Tools.Analyzers\Helpers\RoslynHelper.cs" Link="Helpers\RoslynHelper.cs" />
<Compile Include="..\Datadog.Trace.Tools.Analyzers\LogAnalyzer\Diagnostics.cs" Link="LogAnalyzer\Diagnostics.cs" />
<Compile Include="..\Datadog.Trace.Tools.Analyzers\ThreadAbortAnalyzer\Diagnostics.cs" Link="ThreadAbortAnalyzer\Diagnostics.cs" />
<Compile Include="..\Datadog.Trace\Util\System.Diagnostics.CodeAnalysis.Attributes.cs" Link="Helpers\System.Diagnostics.CodeAnalysis.Attributes.cs" />
<Compile Include="..\Datadog.Trace\Util\System.Runtime.CompilerServices.Attributes.cs" Link="Helpers\System.Runtime.CompilerServices.Attributes.cs" />
<Compile Update="LogAnalyzer\ConstantMessageTemplateCodeFixProvider.*.cs">
<DependentUpon>ConstantMessageTemplateCodeFixProvider.cs</DependentUpon>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Project>
<!-- Deliberately skipping parent directory props, note the "../../" -->
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../../'))" />
</Project>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are all just moving from the analyzer project to the code fix project

File renamed without changes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a public type provided in the analyzers package, so just basically vendoring the minimum amount needed here

Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// <copyright file="ObjectDisplay.cs" company="Datadog">
// 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.
// </copyright>

#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
/// <summary>
/// Displays a value in the C# style.
/// </summary>
/// <remarks>
/// Separate from <see cref="T:Microsoft.CodeAnalysis.CSharp.SymbolDisplay"/> because we want to link this functionality into
/// the Formatter project and we don't want it to be public there.
/// </remarks>
/// <seealso cref="T:Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay.ObjectDisplay"/>
#pragma warning restore CA1200 // Avoid using cref tags with a prefix
internal static class ObjectDisplay
{
/// <summary>
/// Returns a C# string literal with the given value.
/// </summary>
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;
}

/// <summary>
/// Returns true if the character should be replaced and sets
/// <paramref name="replaceWith"/> to the replacement text.
/// </summary>
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ThreadAbortCodeFixProvider : CodeFixProvider
/// <inheritdoc />
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(ThreadAbortAnalyzer.DiagnosticId); }
get { return ImmutableArray.Create(Diagnostics.ThreadAbortDiagnosticId); }
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class BeforeAfterAspectAnalyzer : DiagnosticAnalyzer
{
/// <summary>
/// The diagnostic ID displayed in error messages
/// </summary>
public const string DiagnosticId = "DD0004";

/// <summary>
/// The severity of the diagnostic
/// </summary>
public const DiagnosticSeverity Severity = DiagnosticSeverity.Error;

#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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <copyright file="Diagnostics.cs" company="Datadog">
// 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.
// </copyright>

namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;

/// <summary>
/// Helper class for holding various diagnostics.
/// </summary>
public class Diagnostics
{
/// <summary>
/// The diagnostic ID displayed in error messages
/// </summary>
public const string BeforeAfterAspectDiagnosticId = "DD0004";

/// <summary>
/// The diagnostic ID displayed in error messages
/// </summary>
public const string ReplaceAspectDiagnosticId = "DD0005";
}
Loading
Loading