Skip to content
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

Limit language version on Logger and Options source gens #90654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1023`__ | Generating more than 6 arguments is not supported |
| __`SYSLIB1024`__ | Argument is using the unsupported out parameter modifier |
| __`SYSLIB1025`__ | Multiple logging methods cannot use the same event name within a class |
| __`SYSLIB1026`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1027`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1028`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1029`__ | _`SYSLIB1026`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1026`__ | C# language version not supported by the logging source generator. |
| __`SYSLIB1027`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1028`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1029`__ | _`SYSLIB1001`-`SYSLIB1029` reserved for logging._ |
| __`SYSLIB1030`__ | JsonSourceGenerator did not generate serialization metadata for type |
| __`SYSLIB1031`__ | JsonSourceGenerator encountered a duplicate JsonTypeInfo property name |
| __`SYSLIB1032`__ | JsonSourceGenerator encountered a context class that is not partial |
Expand Down Expand Up @@ -250,7 +250,7 @@ The diagnostic id values reserved for .NET Libraries analyzer warnings are `SYSL
| __`SYSLIB1213`__ | Options validation generator: Member potentially missing enumerable validation. |
| __`SYSLIB1214`__ | Options validation generator: Can't validate constants, static fields or properties. |
| __`SYSLIB1215`__ | Options validation generator: Validation attribute on the member is inaccessible from the validator type. |
| __`SYSLIB1216`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
| __`SYSLIB1216`__ | C# language version not supported by the options validation source generator. |
| __`SYSLIB1217`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
| __`SYSLIB1218`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
| __`SYSLIB1219`__ | *_`SYSLIB1201`-`SYSLIB1219` reserved for Microsoft.Extensions.Options.SourceGeneration.* |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,13 @@ public static class DiagnosticDescriptors
category: "LoggingGenerator",
DiagnosticSeverity.Warning,
isEnabledByDefault: true);

public static DiagnosticDescriptor LoggingUnsupportedLanguageVersion { get; } = new DiagnosticDescriptor(
id: "SYSLIB1026",
title: new LocalizableResourceString(nameof(SR.LoggingUnsupportedLanguageVersionTitle), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
messageFormat: new LocalizableResourceString(nameof(SR.LoggingUnsupportedLanguageVersionMessageFormat), SR.ResourceManager, typeof(FxResources.Microsoft.Extensions.Logging.Generators.SR)),
category: "LoggingGenerator",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,13 @@ static bool IsAllowedKind(SyntaxKind kind) =>
}
}

if (results.Count > 0 && _compilation is CSharpCompilation { LanguageVersion : LanguageVersion version and < LanguageVersion.CSharp8 })
{
// we only support C# 8.0 and above
Diag(DiagnosticDescriptors.LoggingUnsupportedLanguageVersion, null, version.ToDisplayString(), LanguageVersion.CSharp8.ToDisplayString());
return Array.Empty<LoggerClass>();
}

return results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,10 @@
<data name="MalformedFormatStringsTitle" xml:space="preserve">
<value>Logging method contains malformed format strings</value>
</data>
<data name="LoggingUnsupportedLanguageVersionTitle" xml:space="preserve">
<value>C# language version not supported by the source generator.</value>
</data>
<data name="LoggingUnsupportedLanguageVersionMessageFormat" xml:space="preserve">
<value>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be removing quotes from both places rather than adding them. We control the version enum that is being passed in both cases, so there's no need to guard with quotes.

I'll submit a new PR changing this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not seeing having the quotes is bad to show in the message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes are typically used to delimit inputs that might contain arbitrary values, including whitespace. We control the inputs passed to the diagnostic and it's kind of weird to say C# '8'.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a PR but somehow didn't add you as a reviewer:

#90720

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quotes are typically used to delimit inputs that might contain arbitrary values, including whitespace. We control the inputs passed to the diagnostic and it's kind of weird to say C# '8'.

Not necessary, sometimes the quotes can be used to emphasize the info inside the quote. Anyway, I don't mind either way. I'll take a look at the PR.

</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Metody protokolování musí být statické.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">Metoda protokolování {0} obsahuje řetězce s poškozeným formátem.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Protokollierungsmethoden müssen statisch sein.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">Die Protokollierungsmethode „{0}“ enthält nicht wohlgeformte Formatzeichenfolgen.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Los métodos de registro deben ser estáticos</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">El método de registro “{0}” contiene cadenas con formato incorrecto</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Les méthodes de journalisation doivent être statiques</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">La méthode de journalisation « {0} »contient des chaînes de format incorrectes</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">I metodi di registrazione devono essere statici</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">Il metodo di registrazione '{0}' contiene stringhe in formato non valido</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">ログ メソッドは静的である必要があります</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">ログ メソッド '{0}' に、形式の正しくない文字列が含まれています</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">로깅 메서드는 정적이어야 함</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">로깅 메서드 '{0}'에 잘못된 형식의 문자열이 포함되어 있습니다.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Metody rejestrowania muszą być statyczne</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">Metoda rejestrowania „{0}” zawiera źle sformułowane ciągi formatu</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Os métodos de registro em log devem ser estáticos</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">O método de registro '{0}' contém strings de formato malformado</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Методы ведения журнала должны быть статическими</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">Метод ведения журнала событий "{0}" содержит строки неправильного формата</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">Günlüğe kaydetme yöntemleri statik olmalıdır</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">'{0}' günlüğe kaydetme yöntemi hatalı biçimlendirilmiş biçim dizeleri içeriyor</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">日志记录方法必须为静态方法</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">日志记录方法“{0}”包含格式错误的字符串</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
<target state="translated">記錄方法必須是靜態</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionMessageFormat">
<source>The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</source>
<target state="new">The Logging source generator is not available in C# '{0}'. Please use language version '{1}' or greater.</target>
<note />
</trans-unit>
<trans-unit id="LoggingUnsupportedLanguageVersionTitle">
<source>C# language version not supported by the source generator.</source>
<target state="new">C# language version not supported by the source generator.</target>
<note />
</trans-unit>
<trans-unit id="MalformedFormatStringsMessage">
<source>Logging method '{0}' contains malformed format strings</source>
<target state="translated">記錄方法 '{0}' 包含格式錯誤的格式字串</target>
Expand Down
Loading
Loading