| | | 1 | | using Microsoft.CodeAnalysis; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.Logging.Analyzers; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Diagnostic descriptors for logging-specific Needlr analyzers. |
| | | 7 | | /// </summary> |
| | | 8 | | public static class DiagnosticDescriptors |
| | | 9 | | { |
| | | 10 | | private const string Category = "NexusLabs.Needlr.Logging"; |
| | | 11 | | private const string HelpLinkBase = "https://github.com/nexus-labs/needlr/blob/main/docs/analyzers/"; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// NDLRLOG001: a <c>[NeedlrLoggerMessage]</c> method must be <c>partial</c>. |
| | | 15 | | /// </summary> |
| | 1 | 16 | | public static readonly DiagnosticDescriptor MustBePartial = new( |
| | 1 | 17 | | id: DiagnosticIds.MustBePartial, |
| | 1 | 18 | | title: "NeedlrLoggerMessage method must be partial", |
| | 1 | 19 | | messageFormat: "Logging method '{0}' must be partial so its body can be generated", |
| | 1 | 20 | | category: Category, |
| | 1 | 21 | | defaultSeverity: DiagnosticSeverity.Error, |
| | 1 | 22 | | isEnabledByDefault: true, |
| | 1 | 23 | | description: "A method marked with [NeedlrLoggerMessage] must be declared partial so the source generator can su |
| | 1 | 24 | | helpLinkUri: HelpLinkBase + "NDLRLOG001.md"); |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// NDLRLOG002: a <c>[NeedlrLoggerMessage]</c> method must return <c>void</c>. |
| | | 28 | | /// </summary> |
| | 1 | 29 | | public static readonly DiagnosticDescriptor MustReturnVoid = new( |
| | 1 | 30 | | id: DiagnosticIds.MustReturnVoid, |
| | 1 | 31 | | title: "NeedlrLoggerMessage method must return void", |
| | 1 | 32 | | messageFormat: "Logging method '{0}' must return void", |
| | 1 | 33 | | category: Category, |
| | 1 | 34 | | defaultSeverity: DiagnosticSeverity.Error, |
| | 1 | 35 | | isEnabledByDefault: true, |
| | 1 | 36 | | description: "A method marked with [NeedlrLoggerMessage] must return void.", |
| | 1 | 37 | | helpLinkUri: HelpLinkBase + "NDLRLOG002.md"); |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// NDLRLOG003: a <c>[NeedlrLoggerMessage]</c> method must not be generic. |
| | | 41 | | /// </summary> |
| | 1 | 42 | | public static readonly DiagnosticDescriptor MustNotBeGeneric = new( |
| | 1 | 43 | | id: DiagnosticIds.MustNotBeGeneric, |
| | 1 | 44 | | title: "NeedlrLoggerMessage method must not be generic", |
| | 1 | 45 | | messageFormat: "Logging method '{0}' must not declare type parameters", |
| | 1 | 46 | | category: Category, |
| | 1 | 47 | | defaultSeverity: DiagnosticSeverity.Error, |
| | 1 | 48 | | isEnabledByDefault: true, |
| | 1 | 49 | | description: "A method marked with [NeedlrLoggerMessage] must not be generic.", |
| | 1 | 50 | | helpLinkUri: HelpLinkBase + "NDLRLOG003.md"); |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// NDLRLOG004: the type containing a <c>[NeedlrLoggerMessage]</c> method must be <c>partial</c>. |
| | | 54 | | /// </summary> |
| | 1 | 55 | | public static readonly DiagnosticDescriptor ContainingTypeMustBePartial = new( |
| | 1 | 56 | | id: DiagnosticIds.ContainingTypeMustBePartial, |
| | 1 | 57 | | title: "Type containing a NeedlrLoggerMessage method must be partial", |
| | 1 | 58 | | messageFormat: "Type '{0}' must be partial because it contains a [NeedlrLoggerMessage] method", |
| | 1 | 59 | | category: Category, |
| | 1 | 60 | | defaultSeverity: DiagnosticSeverity.Error, |
| | 1 | 61 | | isEnabledByDefault: true, |
| | 1 | 62 | | description: "The type containing a [NeedlrLoggerMessage] method must be declared partial so the generated imple |
| | 1 | 63 | | helpLinkUri: HelpLinkBase + "NDLRLOG004.md"); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// NDLRLOG005: a <c>[NeedlrLoggerMessage]</c> method has no accessible <c>ILogger</c>. |
| | | 67 | | /// </summary> |
| | 1 | 68 | | public static readonly DiagnosticDescriptor LoggerNotFound = new( |
| | 1 | 69 | | id: DiagnosticIds.LoggerNotFound, |
| | 1 | 70 | | title: "NeedlrLoggerMessage method has no accessible ILogger", |
| | 1 | 71 | | messageFormat: "Logging method '{0}' has no accessible ILogger; an instance method needs an ILogger field or pro |
| | 1 | 72 | | category: Category, |
| | 1 | 73 | | defaultSeverity: DiagnosticSeverity.Error, |
| | 1 | 74 | | isEnabledByDefault: true, |
| | 1 | 75 | | description: "A [NeedlrLoggerMessage] method needs a logger: an instance method must have an ILogger field or pr |
| | 1 | 76 | | helpLinkUri: HelpLinkBase + "NDLRLOG005.md"); |
| | | 77 | | |
| | | 78 | | /// <summary> |
| | | 79 | | /// NDLRLOG006: a <c>[NeedlrLoggerMessage]</c> method has more than six non-exception parameters. |
| | | 80 | | /// </summary> |
| | 1 | 81 | | public static readonly DiagnosticDescriptor TooManyParameters = new( |
| | 1 | 82 | | id: DiagnosticIds.TooManyParameters, |
| | 1 | 83 | | title: "NeedlrLoggerMessage method exceeds the LoggerMessage.Define parameter limit", |
| | 1 | 84 | | messageFormat: "Logging method '{0}' has {1} non-exception parameters; the allocation-free fast path supports at |
| | 1 | 85 | | category: Category, |
| | 1 | 86 | | defaultSeverity: DiagnosticSeverity.Info, |
| | 1 | 87 | | isEnabledByDefault: true, |
| | 1 | 88 | | description: "LoggerMessage.Define supports at most six message parameters. Methods with more parameters still w |
| | 1 | 89 | | helpLinkUri: HelpLinkBase + "NDLRLOG006.md"); |
| | | 90 | | } |