Skip to content

Commit 71bb0d4

Browse files
authored
Adds diagnostic for out parameter in LSG (#80458)
fixes #64665
1 parent 4ece8f0 commit 71bb0d4

File tree

18 files changed

+167
-1
lines changed

18 files changed

+167
-1
lines changed

docs/project/list-of-diagnostics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
135135
| __`SYSLIB1021`__ | Can't have the same template with different casing |
136136
| __`SYSLIB1022`__ | Can't have malformed format strings (like dangling {, etc) |
137137
| __`SYSLIB1023`__ | Generating more than 6 arguments is not supported |
138-
| __`SYSLIB1024`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
138+
| __`SYSLIB1024`__ | Argument is using the unsupported out parameter modifier |
139139
| __`SYSLIB1025`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
140140
| __`SYSLIB1026`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |
141141
| __`SYSLIB1027`__ | *_`SYSLIB1024`-`SYSLIB1029` reserved for logging._* |

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/DiagnosticDescriptors.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,13 @@ public static class DiagnosticDescriptors
183183
category: "LoggingGenerator",
184184
DiagnosticSeverity.Error,
185185
isEnabledByDefault: true);
186+
187+
public static DiagnosticDescriptor InvalidLoggingMethodParameterOut { get; } = new DiagnosticDescriptor(
188+
id: "SYSLIB1024",
189+
title: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodParameterOutTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
190+
messageFormat: new LocalizableResourceString(nameof(SR.InvalidLoggingMethodParameterOutMessage), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
191+
category: "LoggingGenerator",
192+
DiagnosticSeverity.Error,
193+
isEnabledByDefault: true);
186194
}
187195
}

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/LoggerMessageGenerator.Parser.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,13 @@ public IReadOnlyList<LoggerClass> GetLogClasses(IEnumerable<ClassDeclarationSynt
312312
{
313313
qualifier = "ref";
314314
}
315+
else if (paramSymbol.RefKind == RefKind.Out)
316+
{
317+
Diag(DiagnosticDescriptors.InvalidLoggingMethodParameterOut, paramSymbol.Locations[0], paramName);
318+
keepMethod = false;
319+
break;
320+
}
321+
315322
string typeName = paramTypeSymbol.ToDisplayString(
316323
SymbolDisplayFormat.FullyQualifiedFormat.WithMiscellaneousOptions(
317324
SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier));

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/Strings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,10 @@
216216
<data name="GeneratingForMax6ArgumentsMessage" xml:space="preserve">
217217
<value>Generating more than 6 arguments is not supported</value>
218218
</data>
219+
<data name="InvalidLoggingMethodParameterOutMessage" xml:space="preserve">
220+
<value>Argument '{0}' is using the unsupported out parameter modifier</value>
221+
</data>
222+
<data name="InvalidLoggingMethodParameterOutTitle" xml:space="preserve">
223+
<value>Argument is using the unsupported out parameter modifier</value>
224+
</data>
219225
</root>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.cs.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<target state="translated">Názvy parametrů metody protokolování nemůžou začínat podtržítkem (_).</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="InvalidLoggingMethodParameterOutMessage">
36+
<source>Argument '{0}' is using the unsupported out parameter modifier</source>
37+
<target state="new">Argument '{0}' is using the unsupported out parameter modifier</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="InvalidLoggingMethodParameterOutTitle">
41+
<source>Argument is using the unsupported out parameter modifier</source>
42+
<target state="new">Argument is using the unsupported out parameter modifier</target>
43+
<note />
44+
</trans-unit>
3545
<trans-unit id="LoggingMethodHasBodyMessage">
3646
<source>Logging methods cannot have a body</source>
3747
<target state="translated">Metody protokolování nemůžou obsahovat tělo.</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.de.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<target state="translated">Parameternamen für die Protokollierungsmethode dürfen nicht mit "_" beginnen.</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="InvalidLoggingMethodParameterOutMessage">
36+
<source>Argument '{0}' is using the unsupported out parameter modifier</source>
37+
<target state="new">Argument '{0}' is using the unsupported out parameter modifier</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="InvalidLoggingMethodParameterOutTitle">
41+
<source>Argument is using the unsupported out parameter modifier</source>
42+
<target state="new">Argument is using the unsupported out parameter modifier</target>
43+
<note />
44+
</trans-unit>
3545
<trans-unit id="LoggingMethodHasBodyMessage">
3646
<source>Logging methods cannot have a body</source>
3747
<target state="translated">Protokollierungsmethoden dürfen keinen Text enthalten.</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.es.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<target state="translated">Los nombres de parámetro del método de registro no pueden empezar por _</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="InvalidLoggingMethodParameterOutMessage">
36+
<source>Argument '{0}' is using the unsupported out parameter modifier</source>
37+
<target state="new">Argument '{0}' is using the unsupported out parameter modifier</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="InvalidLoggingMethodParameterOutTitle">
41+
<source>Argument is using the unsupported out parameter modifier</source>
42+
<target state="new">Argument is using the unsupported out parameter modifier</target>
43+
<note />
44+
</trans-unit>
3545
<trans-unit id="LoggingMethodHasBodyMessage">
3646
<source>Logging methods cannot have a body</source>
3747
<target state="translated">Los métodos de registro no pueden tener cuerpo</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.fr.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<target state="translated">Les noms de paramètres de méthode de journalisation ne peuvent pas commencer par _</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="InvalidLoggingMethodParameterOutMessage">
36+
<source>Argument '{0}' is using the unsupported out parameter modifier</source>
37+
<target state="new">Argument '{0}' is using the unsupported out parameter modifier</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="InvalidLoggingMethodParameterOutTitle">
41+
<source>Argument is using the unsupported out parameter modifier</source>
42+
<target state="new">Argument is using the unsupported out parameter modifier</target>
43+
<note />
44+
</trans-unit>
3545
<trans-unit id="LoggingMethodHasBodyMessage">
3646
<source>Logging methods cannot have a body</source>
3747
<target state="translated">Les méthodes de journalisation ne peuvent pas avoir de corps</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.it.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<target state="translated">I nomi dei parametri del metodo di registrazione non possono iniziare con _</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="InvalidLoggingMethodParameterOutMessage">
36+
<source>Argument '{0}' is using the unsupported out parameter modifier</source>
37+
<target state="new">Argument '{0}' is using the unsupported out parameter modifier</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="InvalidLoggingMethodParameterOutTitle">
41+
<source>Argument is using the unsupported out parameter modifier</source>
42+
<target state="new">Argument is using the unsupported out parameter modifier</target>
43+
<note />
44+
</trans-unit>
3545
<trans-unit id="LoggingMethodHasBodyMessage">
3646
<source>Logging methods cannot have a body</source>
3747
<target state="translated">I metodi di registrazione non possono avere un corpo</target>

src/libraries/Microsoft.Extensions.Logging.Abstractions/gen/Resources/xlf/Strings.ja.xlf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
<target state="translated">Logging method パラメーター名は「 _ 」で始まることはできません</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="InvalidLoggingMethodParameterOutMessage">
36+
<source>Argument '{0}' is using the unsupported out parameter modifier</source>
37+
<target state="new">Argument '{0}' is using the unsupported out parameter modifier</target>
38+
<note />
39+
</trans-unit>
40+
<trans-unit id="InvalidLoggingMethodParameterOutTitle">
41+
<source>Argument is using the unsupported out parameter modifier</source>
42+
<target state="new">Argument is using the unsupported out parameter modifier</target>
43+
<note />
44+
</trans-unit>
3545
<trans-unit id="LoggingMethodHasBodyMessage">
3646
<source>Logging methods cannot have a body</source>
3747
<target state="translated">ログ メソッドは本文を含めることができません</target>

0 commit comments

Comments
 (0)