-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add extension method to create Diagnostic (#126)
Borrowing a technique from the roslyn-analyzers repo. Creating a set of extension methods to create a Diagnostic given a `SyntaxNode` or a `Location`. Simplifies reading the code slightly.
- Loading branch information
1 parent
2dcad69
commit 9b41015
Showing
6 changed files
with
28 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 @@ | ||
namespace Moq.Analyzers; | ||
|
||
internal static class DiagnosticExtensions | ||
{ | ||
/// <summary> | ||
/// Create a <see cref="Diagnostic"/> with the given <paramref name="descriptor"/> at the <paramref name="node"/>'s location. | ||
/// </summary> | ||
/// <param name="node">The <see cref="SyntaxNode"/> to use for a <see cref="Location"/> for a diagnostic.</param> | ||
/// <param name="descriptor">The <see cref="DiagnosticDescriptor"/> to use when creating the diagnostic.</param> | ||
/// <returns>A <see cref="Diagnostic"/> with the given <paramref name="descriptor"/> at the <paramref name="node"/>'s location.</returns> | ||
public static Diagnostic CreateDiagnostic(this SyntaxNode? node, DiagnosticDescriptor descriptor) => | ||
Diagnostic.Create(descriptor, node?.GetLocation()); | ||
|
||
/// <summary> | ||
/// Create a <see cref="Diagnostic"/> with the given <paramref name="descriptor"/> at the <paramref name="location"/>. | ||
/// </summary> | ||
/// <param name="location">The <see cref="Location"/> to use for a diagnostic.</param> | ||
/// <param name="descriptor">The <see cref="DiagnosticDescriptor"/> to use when creating the diagnostic.</param> | ||
/// <returns>A <see cref="Diagnostic"/> with the given <paramref name="descriptor"/> at the <paramref name="location"/>.</returns> | ||
public static Diagnostic CreateDiagnostic(this Location? location, DiagnosticDescriptor descriptor) => | ||
Diagnostic.Create(descriptor, location); | ||
} |
This file contains 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 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