Skip to content

Commit 4e49e43

Browse files
authored
Fix some analyzer warnings (#416)
1 parent cf622c7 commit 4e49e43

File tree

265 files changed

+1560
-1744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+1560
-1744
lines changed

.editorconfig

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,6 @@ dotnet_naming_rule.parameters_rule.severity = warning
459459
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers
460460
##########################################
461461

462-
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md
463-
# Using directive should appear within a namespace declaration
464-
dotnet_diagnostic.SA1200.severity = suggestion
465-
466462
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1600.md
467463
# Elements should be documented
468464
dotnet_diagnostic.SA1600.severity = suggestion
@@ -500,10 +496,6 @@ dotnet_diagnostic.VSTHRD101.severity = suggestion
500496
# Add .ConfigureAwait(bool) to your await expression
501497
dotnet_diagnostic.VSTHRD111.severity = suggestion
502498

503-
# https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD200.md
504-
# Use "Async" suffix in names of methods that return an awaitable type
505-
dotnet_diagnostic.VSTHRD200.severity = suggestion
506-
507499
##########################################
508500
# Provided by Roslyn
509501
# https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/
@@ -517,9 +509,6 @@ dotnet_diagnostic.CS0618.severity = suggestion
517509
# Missing XML comment for publicly visible type or member '...'
518510
dotnet_diagnostic.CS1591.severity = suggestion
519511

520-
# IDE0003: Remove qualification
521-
dotnet_diagnostic.IDE0003.severity = suggestion
522-
523512
# CA2007: Consider calling ConfigureAwait on the awaited task
524513
dotnet_diagnostic.CA2007.severity = suggestion
525514

@@ -538,45 +527,21 @@ dotnet_diagnostic.CA1031.severity = suggestion
538527
# CA1711: Identifiers should not have incorrect suffix
539528
dotnet_diagnostic.CA1711.severity = suggestion
540529

541-
# CA1018: Mark attributes with AttributeUsageAttribute
542-
dotnet_diagnostic.CA1018.severity = suggestion
543-
544-
# CA1813: Avoid unsealed attributes
545-
dotnet_diagnostic.CA1813.severity = suggestion
546-
547530
# CA2227: Collection properties should be read only
548531
dotnet_diagnostic.CA2227.severity = suggestion
549532

550-
# CA1825: Avoid zero-length array allocations
551-
dotnet_diagnostic.CA1825.severity = suggestion
552-
553533
# CA1310: Specify StringComparison for correctness
554534
dotnet_diagnostic.CA1310.severity = suggestion
555535

556536
# CA1002: Do not expose generic lists
557537
dotnet_diagnostic.CA1002.severity = suggestion
558538

559-
# IDE0008: Use explicit type
560-
dotnet_diagnostic.IDE0008.severity = suggestion
561-
562539
# CA1305: Specify IFormatProvider
563540
dotnet_diagnostic.CA1305.severity = suggestion
564541

565-
# CA1032: Implement standard exception constructors
566-
dotnet_diagnostic.CA1032.severity = suggestion
567-
568542
# CA1051: Do not declare visible instance fields
569543
dotnet_diagnostic.CA1051.severity = suggestion
570544

571-
# CA1401: P/Invokes should not be visible
572-
dotnet_diagnostic.CA1401.severity = suggestion
573-
574-
# CA5392: Use DefaultDllImportSearchPaths attribute for P/Invokes
575-
dotnet_diagnostic.CA5392.severity = suggestion
576-
577-
# CA2101: Specify marshaling for P/Invoke string arguments
578-
dotnet_diagnostic.CA2101.severity = suggestion
579-
580545
# CA2211: Non-constant fields should not be visible
581546
dotnet_diagnostic.CA2211.severity = suggestion
582547

@@ -592,42 +557,18 @@ dotnet_diagnostic.CA1822.severity = suggestion
592557
# CA1307: Specify StringComparison for clarity
593558
dotnet_diagnostic.CA1307.severity = suggestion
594559

595-
# CA1052: Static holder types should be Static or NotInheritable
596-
dotnet_diagnostic.CA1052.severity = suggestion
597-
598-
# CA1725: Parameter names should match base declaration
599-
dotnet_diagnostic.CA1725.severity = suggestion
600-
601-
# CA1805: Do not initialize unnecessarily
602-
dotnet_diagnostic.CA1805.severity = suggestion
603-
604560
# CA1806: Do not ignore method results
605561
dotnet_diagnostic.CA1806.severity = suggestion
606562

607563
# CA1303: Do not pass literals as localized parameters
608564
dotnet_diagnostic.CA1303.severity = suggestion
609565

610-
# CA1816: Dispose methods should call SuppressFinalize
611-
dotnet_diagnostic.CA1816.severity = suggestion
612-
613-
# CA2249: Consider using 'string.Contains' instead of 'string.IndexOf'
614-
dotnet_diagnostic.CA2249.severity = suggestion
615-
616-
# CA1836: Prefer IsEmpty over Count
617-
dotnet_diagnostic.CA1836.severity = suggestion
618-
619-
# CA2208: Instantiate argument exceptions correctly
620-
dotnet_diagnostic.CA2208.severity = suggestion
621-
622566
# CA1028: Enum Storage should be Int32
623567
dotnet_diagnostic.CA1028.severity = suggestion
624568

625569
# CA1034: Nested types should not be visible
626570
dotnet_diagnostic.CA1034.severity = suggestion
627571

628-
# CA1033: Interface methods should be callable by child types
629-
dotnet_diagnostic.CA1033.severity = suggestion
630-
631572
# CA1054: URI-like parameters should not be strings
632573
dotnet_diagnostic.CA1054.severity = suggestion
633574

@@ -637,42 +578,18 @@ dotnet_diagnostic.CA1027.severity = suggestion
637578
# CA1056: URI-like properties should not be strings
638579
dotnet_diagnostic.CA1056.severity = suggestion
639580

640-
# CA1838: Avoid 'StringBuilder' parameters for P/Invokes
641-
dotnet_diagnostic.CA1838.severity = suggestion
642-
643581
# CA2000: Dispose objects before losing scope
644582
dotnet_diagnostic.CA2000.severity = suggestion
645583

646-
# CA2016: Forward the 'CancellationToken' parameter to methods
647-
dotnet_diagnostic.CA2016.severity = suggestion
648-
649584
# CA1014: Mark assemblies with CLSCompliantAttribute
650585
dotnet_diagnostic.CA1014.severity = none
651586

652587
# CA1824: Mark assemblies with NeutralResourcesLanguageAttribute
653588
dotnet_diagnostic.CA1824.severity = none
654589

655-
# CA1508: Avoid dead conditional code
656-
dotnet_diagnostic.CA1508.severity = suggestion
657-
658-
# CA1823: Avoid unused private fields
659-
dotnet_diagnostic.CA1823.severity = suggestion
660-
661-
# CA2234: Pass system uri objects instead of strings
662-
dotnet_diagnostic.CA2234.severity = suggestion
663-
664-
# SA1101: Prefix local calls with this
665-
dotnet_diagnostic.SA1101.severity = suggestion
666-
667590
# CA2219: Do not raise exceptions in finally clauses
668591
dotnet_diagnostic.CA2219.severity = suggestion
669592

670-
# CA2201: Exception type System.Exception is not sufficiently specific
671-
dotnet_diagnostic.CA2201.severity = suggestion
672-
673-
# CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
674-
dotnet_diagnostic.CA1835.severity = suggestion
675-
676593
# CA1036: Override methods on comparable types
677594
dotnet_diagnostic.CA1036.severity = suggestion
678595

src/Microsoft.ComponentDetection.Common/AsyncExecution.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System;
23
using System.Threading;
34
using System.Threading.Tasks;
45

5-
namespace Microsoft.ComponentDetection.Common;
6-
76
public static class AsyncExecution
87
{
98
public static async Task<T> ExecuteWithTimeoutAsync<T>(Func<Task<T>> toExecute, TimeSpan timeout, CancellationToken cancellationToken)
@@ -31,7 +30,7 @@ public static async Task ExecuteVoidWithTimeoutAsync(Action toExecute, TimeSpan
3130
throw new ArgumentNullException(nameof(toExecute));
3231
}
3332

34-
var work = Task.Run(toExecute);
33+
var work = Task.Run(toExecute, cancellationToken);
3534
var completedInTime = await Task.Run(() => work.Wait(timeout));
3635
if (!completedInTime)
3736
{

src/Microsoft.ComponentDetection.Common/CommandLineInvocationService.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System;
23
using System.Collections.Concurrent;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -10,17 +11,15 @@
1011
using Microsoft.ComponentDetection.Common.Telemetry.Records;
1112
using Microsoft.ComponentDetection.Contracts;
1213

13-
namespace Microsoft.ComponentDetection.Common;
14-
1514
[Export(typeof(ICommandLineInvocationService))]
1615
public class CommandLineInvocationService : ICommandLineInvocationService
1716
{
1817
private readonly IDictionary<string, string> commandLocatableCache = new ConcurrentDictionary<string, string>();
1918

20-
public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string> additionalCandidateCommands = null, DirectoryInfo workingDirectory = null, params string[] parameters)
19+
public async Task<bool> CanCommandBeLocatedAsync(string command, IEnumerable<string> additionalCandidateCommands = null, DirectoryInfo workingDirectory = null, params string[] parameters)
2120
{
2221
additionalCandidateCommands ??= Enumerable.Empty<string>();
23-
parameters ??= new string[0];
22+
parameters ??= Array.Empty<string>();
2423
var allCommands = new[] { command }.Concat(additionalCandidateCommands);
2524
if (!this.commandLocatableCache.TryGetValue(command, out var validCommand))
2625
{
@@ -51,19 +50,19 @@ public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string>
5150
return !string.IsNullOrWhiteSpace(validCommand);
5251
}
5352

54-
public async Task<CommandLineExecutionResult> ExecuteCommand(string command, IEnumerable<string> additionalCandidateCommands = null, DirectoryInfo workingDirectory = null, params string[] parameters)
53+
public async Task<CommandLineExecutionResult> ExecuteCommandAsync(string command, IEnumerable<string> additionalCandidateCommands = null, DirectoryInfo workingDirectory = null, params string[] parameters)
5554
{
56-
var isCommandLocatable = await this.CanCommandBeLocated(command, additionalCandidateCommands);
55+
var isCommandLocatable = await this.CanCommandBeLocatedAsync(command, additionalCandidateCommands);
5756
if (!isCommandLocatable)
5857
{
5958
throw new InvalidOperationException(
60-
$"{nameof(this.ExecuteCommand)} was called with a command that could not be located: `{command}`!");
59+
$"{nameof(this.ExecuteCommandAsync)} was called with a command that could not be located: `{command}`!");
6160
}
6261

6362
if (workingDirectory != null && !Directory.Exists(workingDirectory.FullName))
6463
{
6564
throw new InvalidOperationException(
66-
$"{nameof(this.ExecuteCommand)} was called with a working directory that could not be located: `{workingDirectory.FullName}`");
65+
$"{nameof(this.ExecuteCommandAsync)} was called with a working directory that could not be located: `{workingDirectory.FullName}`");
6766
}
6867

6968
using var record = new CommandLineInvocationTelemetryRecord();
@@ -88,14 +87,14 @@ public bool IsCommandLineExecution()
8887
return true;
8988
}
9089

91-
public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string> additionalCandidateCommands = null, params string[] parameters)
90+
public async Task<bool> CanCommandBeLocatedAsync(string command, IEnumerable<string> additionalCandidateCommands = null, params string[] parameters)
9291
{
93-
return await this.CanCommandBeLocated(command, additionalCandidateCommands, workingDirectory: null, parameters);
92+
return await this.CanCommandBeLocatedAsync(command, additionalCandidateCommands, workingDirectory: null, parameters);
9493
}
9594

96-
public async Task<CommandLineExecutionResult> ExecuteCommand(string command, IEnumerable<string> additionalCandidateCommands = null, params string[] parameters)
95+
public async Task<CommandLineExecutionResult> ExecuteCommandAsync(string command, IEnumerable<string> additionalCandidateCommands = null, params string[] parameters)
9796
{
98-
return await this.ExecuteCommand(command, additionalCandidateCommands, workingDirectory: null, parameters);
97+
return await this.ExecuteCommandAsync(command, additionalCandidateCommands, workingDirectory: null, parameters);
9998
}
10099

101100
private static Task<CommandLineExecutionResult> RunProcessAsync(string fileName, string parameters, DirectoryInfo workingDirectory = null)
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
using System.Collections.Generic;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System.Collections.Generic;
23
using Microsoft.ComponentDetection.Contracts.TypedComponent;
34

4-
namespace Microsoft.ComponentDetection.Common;
5-
65
public class ComponentComparer : EqualityComparer<TypedComponent>
76
{
8-
public override bool Equals(TypedComponent t0, TypedComponent t1)
7+
public override bool Equals(TypedComponent x, TypedComponent y)
98
{
10-
return t0.Id.Equals(t1.Id);
9+
return x.Id.Equals(y.Id);
1110
}
1211

13-
public override int GetHashCode(TypedComponent typedComponent)
12+
public override int GetHashCode(TypedComponent obj)
1413
{
15-
return typedComponent.Id.GetHashCode();
14+
return obj.Id.GetHashCode();
1615
}
1716
}

src/Microsoft.ComponentDetection.Common/ComponentStream.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System.IO;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System.IO;
23
using Microsoft.ComponentDetection.Contracts;
34

4-
namespace Microsoft.ComponentDetection.Common;
5-
65
public class ComponentStream : IComponentStream
76
{
87
public Stream Stream { get; set; }

src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerable.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System;
23
using System.Collections;
34
using System.Collections.Generic;
45
using System.IO;
56
using Microsoft.ComponentDetection.Contracts;
67

7-
namespace Microsoft.ComponentDetection.Common;
8-
98
public class ComponentStreamEnumerable : IEnumerable<IComponentStream>
109
{
1110
public ComponentStreamEnumerable(IEnumerable<MatchedFile> fileEnumerable, ILogger logger)

src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerableFactory.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System;
23
using System.Collections.Generic;
34
using System.Composition;
45
using System.IO;
56
using Microsoft.ComponentDetection.Contracts;
67

7-
namespace Microsoft.ComponentDetection.Common;
8-
98
[Export(typeof(IComponentStreamEnumerableFactory))]
109
[Shared]
1110
public class ComponentStreamEnumerableFactory : IComponentStreamEnumerableFactory

src/Microsoft.ComponentDetection.Common/ConsoleWritingService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
using System;
1+
namespace Microsoft.ComponentDetection.Common;
2+
using System;
23
using System.Composition;
34

4-
namespace Microsoft.ComponentDetection.Common;
5-
65
[Export(typeof(IConsoleWritingService))]
76
public class ConsoleWritingService : IConsoleWritingService
87
{

src/Microsoft.ComponentDetection.Common/DependencyGraph/ComponentRecorder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ internal DependencyGraph GetDependencyGraphForLocation(string location)
9090
return this.singleFileRecorders.Single(x => x.ManifestFileLocation == location).DependencyGraph;
9191
}
9292

93-
public class SingleFileComponentRecorder : ISingleFileComponentRecorder
93+
public sealed class SingleFileComponentRecorder : ISingleFileComponentRecorder
9494
{
9595
private readonly ILogger log;
9696

src/Microsoft.ComponentDetection.Common/DependencyGraph/DependencyGraph.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void AddComponent(ComponentRefNode componentNode, string parentComponentI
3434

3535
if (string.IsNullOrWhiteSpace(componentNode.Id))
3636
{
37-
throw new ArgumentNullException(nameof(componentNode.Id));
37+
throw new ArgumentNullException(nameof(componentNode.Id), "Invalid component node id");
3838
}
3939

4040
this.componentNodes.AddOrUpdate(componentNode.Id, componentNode, (key, currentNode) =>
@@ -99,7 +99,7 @@ public HashSet<string> GetAdditionalRelatedFiles()
9999

100100
public bool HasComponents()
101101
{
102-
return this.componentNodes.Count > 0;
102+
return !this.componentNodes.IsEmpty;
103103
}
104104

105105
public bool? IsDevelopmentDependency(string componentId)

0 commit comments

Comments
 (0)