-
Notifications
You must be signed in to change notification settings - Fork 151
Bump the version of Microsoft.CodeAnalysis.CSharp and others used in our internal analyzers
#7860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+325
−52
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
15b9055
nit: Extract diagnostics to separate files (needed for subsequent upd…
andrewlock 6dbfece
Update source generator and analyzer package references to latest
andrewlock a08e2f9
Create separate "CodeFixes" project and add as default
andrewlock f659a0f
Fix test project
andrewlock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...rc/Datadog.Trace.Tools.Analyzers.CodeFixes/Datadog.Trace.Tools.Analyzers.CodeFixes.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
4 changes: 4 additions & 0 deletions
4
tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Directory.Build.props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
File renamed without changes.
195 changes: 195 additions & 0 deletions
195
tracer/src/Datadog.Trace.Tools.Analyzers.CodeFixes/Helpers/ObjectDisplay.cs
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/Diagnostics.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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