Skip to content

Commit

Permalink
fix(CA2023: Adds validation against invalid braces in logger message …
Browse files Browse the repository at this point in the history
…templates) (#7286)

* Stabilize package versions (#7002)

* Revert "Stabilize package versions (#7002)" (#7003)

This reverts commit e640355.

* Adds validation against invalid bracket pairs
* Fixes #7285

* Fix extra break flagged by CI

* Remove one branch to be fully covered

* Adds secondary occurrence of CA2017 around mismatched braces

* Adds new messages to base resource file

* Ran resource generation

* Fix tests, use `WorkItem` attribute

* documentation updates for CA2017

* Revert "documentation updates for CA2017"

This reverts commit 4c41c4e.

* Trying something else with CA2017 regarding localization
* Needed to have a title and description that match *both* potential reasons for this warning
* The individual messages for the differing reasons is still separate, but the MD/sarif description seemed to be "last wins" when it comes to a title/description
* The `msbuild /t:pack` command kept failing for me, so upped the global.json to target a non preview .net8 SDK, but am not checking that change in

* Finish rebase

* Take into account escaped braces

* Use CA2023 instead of an overloaded CA2017

* Revert "Ran resource generation"

This reverts commit 26f1e68.

* Revert "Adds new messages to base resource file"

This reverts commit 386fe96.

* Adds new CA2023 information to resources
* Will likely need a follow up commit to "undo" the "new" tags around `CA2017`, as these should now match from main

* Reverts "new" translation indicators back to their previously "translated" versions from CA2017
* CA2017 was originally repurposed, which caused undesired impacts to already released versions of the analyzer. Instead these changes are introduced as a new CA2023 #7286 (comment)

* Missed a few files from last commit

* More covering tests, comment tweaking

* Remove additional space between sentences, `error` -> `warning`

* fix(LoggerMessageDefineAnalyzer): BuildError -> BuildWarning

* Optimized impl from @tarekgh

* linting and another missed `error` -> `warning`

* Additional covering tests

---------

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
  • Loading branch information
Kritner and ViktorHofer committed Aug 23, 2024
1 parent 052da18 commit 48136f7
Show file tree
Hide file tree
Showing 21 changed files with 354 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/NetAnalyzers/Core/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CA1515 | Maintainability | Disabled | MakeTypesInternal, [Documentation](https:/
CA1871 | Performance | Info | DoNotPassNonNullableValueToArgumentNullExceptionThrowIfNull, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1871)
CA1872 | Performance | Info | PreferConvertToHexStringOverBitConverterAnalyzer, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1872)
CA2022 | Reliability | Warning | AvoidUnreliableStreamReadAnalyzer, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2022)
CA2023 | Reliability | Warning | LoggerMessageDefineAnalyzer, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2023)
CA2262 | Usage | Info | ProvideHttpClientHandlerMaxResponseHeaderLengthValueCorrectly, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2262)
CA2263 | Usage | Info | PreferGenericOverloadsAnalyzer, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2263)
CA2264 | Usage | Warning | DoNotPassNonNullableValueToArgumentNullExceptionThrowIfNull, [Documentation](https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2264)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@
<data name="LoggerMessageDiagnosticFormatParameterCountMismatchDescription" xml:space="preserve">
<value>Number of parameters supplied in the logging message template do not match the number of named placeholders.</value>
</data>
<data name="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle" xml:space="preserve">
<value>Invalid braces in message template</value>
</data>
<data name="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage" xml:space="preserve">
<value>The braces present in the message template are invalid</value>
</data>
<data name="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription" xml:space="preserve">
<value>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</value>
</data>
<data name="LoggerMessageDiagnosticUseCompiledLogMessagesTitle" xml:space="preserve">
<value>Use the LoggerMessage delegates</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Neshoda počtu parametrů.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Pojmenované zástupné symboly v šabloně zprávy protokolování by neměly obsahovat jenom číselné znaky.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Konflikt bei der Parameteranzahl</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Benannte Platzhalter in der Vorlage für Protokollierungsnachrichten dürfen nicht nur aus numerischen Zeichen bestehen.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">El recuento de parámetros no coincide</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Los marcadores de posición con nombre de la plantilla de mensaje de registro no deben estar formados solo por caracteres numéricos.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Nombre de paramètres incorrects.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Les espaces réservés nommés dans le modèle de message de journalisation ne doivent pas être composés uniquement de caractères numériques.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Numero di parametri non corrispondente</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">I segnaposto denominati nel modello di messaggio di registrazione non devono contenere solo caratteri numerici.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">パラメーター カウントが不一致</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">ログ メッセージ テンプレートの名前付きプレースホルダーは、数字のみで構成することはできません。</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">매개 변수의 개수가 일치하지 않음</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">로깅 메시지 템플릿의 명명된 자리 표시자는 숫자로만 구성되어서는 안 됩니다.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Niezgodność liczby parametrów</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Nazwane symbole zastępcze w szablonie wiadomości rejestrowania nie powinny składać się tylko z samych cyfr.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Incompatibilidade de contagem de parâmetros</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Espaços reservados nomeados no modelo de mensagem de log não devem ser compostos apenas de caracteres numéricos.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Несоответствие количества параметров</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Именованные заполнители в шаблоне сообщения о ведении журнала не должны состоять только из цифр.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@
<target state="translated">Parametre sayısı uyuşmazlığı</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchDescription">
<source>The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</source>
<target state="new">The braces present in the message template are invalid. Ensure any braces in the message template are valid opening/closing braces, or are escaped.</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchMessage">
<source>The braces present in the message template are invalid</source>
<target state="new">The braces present in the message template are invalid</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticMessageTemplateBracesMismatchTitle">
<source>Invalid braces in message template</source>
<target state="new">Invalid braces in message template</target>
<note />
</trans-unit>
<trans-unit id="LoggerMessageDiagnosticNumericsInFormatStringDescription">
<source>Named placeholders in the logging message template should not be comprised of only numeric characters.</source>
<target state="translated">Günlük ileti şablonundaki adlandırılmış yer tutucular, yalnızca sayısal karakterlerden oluşmamalıdır</target>
Expand Down
Loading

0 comments on commit 48136f7

Please sign in to comment.