Skip to content

Commit 3b73682

Browse files
committed
Enable several recently added analyzers
1 parent a87cf1b commit 3b73682

File tree

8 files changed

+37
-13
lines changed

8 files changed

+37
-13
lines changed

eng/CodeAnalysis.src.globalconfig

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ dotnet_diagnostic.CA1860.severity = warning
480480
# CA1861: Avoid constant arrays as arguments
481481
dotnet_diagnostic.CA1861.severity = warning
482482

483-
# CA1862: Prefer using 'StringComparer'/'StringComparison' to perform case-insensitive string comparisons
483+
# CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
484484
dotnet_diagnostic.CA1862.severity = suggestion
485485

486486
# CA1863: Use 'CompositeFormat'
@@ -513,6 +513,15 @@ dotnet_diagnostic.CA1871.severity = warning
513513
# CA1872: Prefer 'Convert.ToHexString' and 'Convert.ToHexStringLower' over call chains based on 'BitConverter.ToString'
514514
dotnet_diagnostic.CA1872.severity = warning
515515

516+
# CA1873: Avoid potentially expensive logging
517+
dotnet_diagnostic.CA1873.severity = warning
518+
519+
# CA1874: Use 'Regex.IsMatch'
520+
dotnet_diagnostic.CA1874.severity = warning
521+
522+
# CA1875: Use 'Regex.Count'
523+
dotnet_diagnostic.CA1875.severity = warning
524+
516525
# CA2000: Dispose objects before losing scope
517526
dotnet_diagnostic.CA2000.severity = none
518527

@@ -564,7 +573,13 @@ dotnet_diagnostic.CA2021.severity = warning
564573
# CA2022: Avoid inexact read with 'Stream.Read'
565574
dotnet_diagnostic.CA2022.severity = warning
566575

567-
# CA2025: Ensure tasks using 'IDisposable' instances complete before the instances are disposed
576+
# CA2023: Invalid braces in message template
577+
dotnet_diagnostic.CA2023.severity = warning
578+
579+
# CA2024: Do not use 'StreamReader.EndOfStream' in async methods
580+
dotnet_diagnostic.CA2024.severity = warning
581+
582+
# CA2025: Do not pass 'IDisposable' instances into unawaited tasks
568583
dotnet_diagnostic.CA2025.severity = warning
569584

570585
# CA2100: Review SQL queries for security vulnerabilities

src/coreclr/tools/Common/Compiler/ProcessLinkerXmlBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private void MatchType(TypeDesc type, Regex regex, XPathNavigator nav)
241241
{
242242
StringBuilder sb = new StringBuilder();
243243
CecilTypeNameFormatter.Instance.AppendName(sb, type);
244-
if (regex.Match(sb.ToString()).Success)
244+
if (regex.IsMatch(sb.ToString()))
245245
ProcessType(type, nav);
246246
}
247247

src/libraries/Microsoft.Extensions.Hosting.Systemd/src/SystemdLifetime.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
9292

9393
private void OnApplicationStarted()
9494
{
95-
Logger.LogInformation("Application started. Hosting environment: {EnvironmentName}; Content root path: {ContentRoot}",
96-
Environment.EnvironmentName, Environment.ContentRootPath);
95+
if (Logger.IsEnabled(LogLevel.Information))
96+
{
97+
Logger.LogInformation("Application started. Hosting environment: {EnvironmentName}; Content root path: {ContentRoot}",
98+
Environment.EnvironmentName, Environment.ContentRootPath);
99+
}
97100

98101
SystemdNotifier.Notify(ServiceState.Ready);
99102
}

src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceLifetime.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
7777
cancellationToken.Register(() => _delayStart.TrySetCanceled());
7878
ApplicationLifetime.ApplicationStarted.Register(() =>
7979
{
80-
Logger.LogInformation("Application started. Hosting environment: {EnvName}; Content root path: {ContentRoot}",
80+
if (Logger.IsEnabled(LogLevel.Information))
81+
{
82+
Logger.LogInformation("Application started. Hosting environment: {EnvName}; Content root path: {ContentRoot}",
8183
Environment.EnvironmentName, Environment.ContentRootPath);
84+
}
8285
});
8386
ApplicationLifetime.ApplicationStopping.Register(() =>
8487
{

src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,12 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)
9999

100100
private void OnApplicationStarted()
101101
{
102-
Logger.LogInformation("Application started. Press Ctrl+C to shut down.");
103-
Logger.LogInformation("Hosting environment: {EnvName}", Environment.EnvironmentName);
104-
Logger.LogInformation("Content root path: {ContentRoot}", Environment.ContentRootPath);
102+
if (Logger.IsEnabled(LogLevel.Information))
103+
{
104+
Logger.LogInformation("Application started. Press Ctrl+C to shut down.");
105+
Logger.LogInformation("Hosting environment: {EnvName}", Environment.EnvironmentName);
106+
Logger.LogInformation("Content root path: {ContentRoot}", Environment.ContentRootPath);
107+
}
105108
}
106109

107110
private void OnApplicationStopping()

src/mono/browser/debugger/BrowserDebugHost/BrowserDebugHost.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>$(AspNetCoreAppCurrent)</TargetFramework>
55
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
6-
<NoWarn>$(NoWarn),CA2007</NoWarn>
6+
<NoWarn>$(NoWarn),CA2007,CA1873</NoWarn>
77
<UseAppHost>false</UseAppHost>
88
<RollForward>Major</RollForward>
99
</PropertyGroup>

src/mono/browser/debugger/BrowserDebugProxy/BrowserDebugProxy.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>$(AspNetCoreAppCurrent)</TargetFramework>
5-
<NoWarn>$(NoWarn),CA2007</NoWarn>
5+
<NoWarn>$(NoWarn),CA2007,CA1873</NoWarn>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
88
</PropertyGroup>

src/tools/illink/src/linker/Linker.Steps/ProcessLinkerXmlBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected virtual void ProcessTypes (AssemblyDefinition assembly, XPathNavigator
195195

196196
void MatchType (TypeDefinition type, Regex regex, XPathNavigator nav)
197197
{
198-
if (regex.Match (type.FullName).Success)
198+
if (regex.IsMatch (type.FullName))
199199
ProcessType (type, nav);
200200

201201
if (!type.HasNestedTypes)
@@ -215,7 +215,7 @@ protected virtual bool ProcessTypePattern (string fullname, AssemblyDefinition a
215215

216216
if (assembly.MainModule.HasExportedTypes) {
217217
foreach (var exported in assembly.MainModule.ExportedTypes) {
218-
if (regex.Match (exported.FullName).Success) {
218+
if (regex.IsMatch (exported.FullName)) {
219219
var type = ProcessExportedType (exported, assembly, nav);
220220
if (type != null) {
221221
ProcessType (type, nav);

0 commit comments

Comments
 (0)