Skip to content

Commit 64849a5

Browse files
committed
nit: Extract diagnostics to separate files (needed for subsequent update)
1 parent 67c35ae commit 64849a5

File tree

11 files changed

+48
-24
lines changed

11 files changed

+48
-24
lines changed

tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectAnalyzer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,14 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;
2121
[DiagnosticAnalyzer(LanguageNames.CSharp)]
2222
public class BeforeAfterAspectAnalyzer : DiagnosticAnalyzer
2323
{
24-
/// <summary>
25-
/// The diagnostic ID displayed in error messages
26-
/// </summary>
27-
public const string DiagnosticId = "DD0004";
28-
2924
/// <summary>
3025
/// The severity of the diagnostic
3126
/// </summary>
3227
public const DiagnosticSeverity Severity = DiagnosticSeverity.Error;
3328

3429
#pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project
3530
private static readonly DiagnosticDescriptor MissingTryCatchRule = new(
36-
DiagnosticId,
31+
Diagnostics.BeforeAfterAspectDiagnosticId,
3732
title: "Aspect is missing try-catch block",
3833
messageFormat: "Aspect method bodies should contain a try-catch block at the top level",
3934
category: "Reliability",

tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/BeforeAfterAspectCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class BeforeAfterAspectCodeFixProvider : CodeFixProvider
3030
/// <inheritdoc />
3131
public sealed override ImmutableArray<string> FixableDiagnosticIds
3232
{
33-
get => ImmutableArray.Create(BeforeAfterAspectAnalyzer.DiagnosticId);
33+
get => ImmutableArray.Create(Diagnostics.BeforeAfterAspectDiagnosticId);
3434
}
3535

3636
/// <inheritdoc />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// <copyright file="Diagnostics.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;
7+
8+
/// <summary>
9+
/// Helper class for holding various diagnostics.
10+
/// </summary>
11+
public class Diagnostics
12+
{
13+
/// <summary>
14+
/// The diagnostic ID displayed in error messages
15+
/// </summary>
16+
public const string BeforeAfterAspectDiagnosticId = "DD0004";
17+
18+
/// <summary>
19+
/// The diagnostic ID displayed in error messages
20+
/// </summary>
21+
public const string ReplaceAspectDiagnosticId = "DD0005";
22+
}

tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectAnalyzer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,14 @@ namespace Datadog.Trace.Tools.Analyzers.AspectAnalyzers;
2020
[DiagnosticAnalyzer(LanguageNames.CSharp)]
2121
public class ReplaceAspectAnalyzer : DiagnosticAnalyzer
2222
{
23-
/// <summary>
24-
/// The diagnostic ID displayed in error messages
25-
/// </summary>
26-
public const string DiagnosticId = "DD0005";
27-
2823
/// <summary>
2924
/// The severity of the diagnostic
3025
/// </summary>
3126
public const DiagnosticSeverity Severity = DiagnosticSeverity.Error;
3227

3328
#pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project
3429
private static readonly DiagnosticDescriptor MissingTryCatchRule = new(
35-
DiagnosticId,
30+
Diagnostics.ReplaceAspectDiagnosticId,
3631
title: "Aspect is in incorrect format",
3732
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",
3833
category: "Reliability",

tracer/src/Datadog.Trace.Tools.Analyzers/AspectAnalyzers/ReplaceAspectCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ReplaceAspectCodeFixProvider : CodeFixProvider
2929
/// <inheritdoc />
3030
public sealed override ImmutableArray<string> FixableDiagnosticIds
3131
{
32-
get => ImmutableArray.Create(ReplaceAspectAnalyzer.DiagnosticId);
32+
get => ImmutableArray.Create(Diagnostics.ReplaceAspectDiagnosticId);
3333
}
3434

3535
/// <inheritdoc />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// <copyright file="Diagnostics.cs" company="Datadog">
2+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
4+
// </copyright>
5+
6+
namespace Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer;
7+
8+
/// <summary>
9+
/// Helper class for holding various diagnostics.
10+
/// </summary>
11+
public class Diagnostics
12+
{
13+
/// <summary>
14+
/// The diagnostic ID displayed in error messages
15+
/// </summary>
16+
public const string ThreadAbortDiagnosticId = "DD0001";
17+
}

tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortAnalyzer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ namespace Datadog.Trace.Tools.Analyzers.ThreadAbortAnalyzer
4545
[DiagnosticAnalyzer(LanguageNames.CSharp)]
4646
public class ThreadAbortAnalyzer : DiagnosticAnalyzer
4747
{
48-
/// <summary>
49-
/// The diagnostic ID displayed in error messages
50-
/// </summary>
51-
public const string DiagnosticId = "DD0001";
52-
5348
#pragma warning disable RS2008 // Enable analyzer release tracking for the analyzer project
5449
private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
55-
DiagnosticId,
50+
Diagnostics.ThreadAbortDiagnosticId,
5651
title: "Potential infinite loop on ThreadAbortException",
5752
messageFormat: "Potential infinite loop - you should rethrow Exception in catch block",
5853
category: "Reliability",

tracer/src/Datadog.Trace.Tools.Analyzers/ThreadAbortAnalyzer/ThreadAbortCodeFixProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ThreadAbortCodeFixProvider : CodeFixProvider
2626
/// <inheritdoc />
2727
public sealed override ImmutableArray<string> FixableDiagnosticIds
2828
{
29-
get { return ImmutableArray.Create(ThreadAbortAnalyzer.DiagnosticId); }
29+
get { return ImmutableArray.Create(Diagnostics.ThreadAbortDiagnosticId); }
3030
}
3131

3232
/// <inheritdoc />

tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/BeforeAfterAspectAnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Datadog.Trace.Tools.Analyzers.Tests.AspectAnalyzers;
1717

1818
public class BeforeAfterAspectAnalyzerTests
1919
{
20-
private const string DiagnosticId = BeforeAfterAspectAnalyzer.DiagnosticId;
20+
private const string DiagnosticId = Diagnostics.BeforeAfterAspectDiagnosticId;
2121
private const DiagnosticSeverity Severity = BeforeAfterAspectAnalyzer.Severity;
2222

2323
// No diagnostics expected to show up

tracer/test/Datadog.Trace.Tools.Analyzers.Tests/AspectAnalyzers/ReplaceAspectAnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Datadog.Trace.Tools.Analyzers.Tests.AspectAnalyzers;
1717

1818
public class ReplaceAspectAnalyzerTests
1919
{
20-
private const string DiagnosticId = ReplaceAspectAnalyzer.DiagnosticId;
20+
private const string DiagnosticId = Diagnostics.ReplaceAspectDiagnosticId;
2121
private const DiagnosticSeverity Severity = ReplaceAspectAnalyzer.Severity;
2222

2323
// No diagnostics expected to show up

0 commit comments

Comments
 (0)