Skip to content

Commit 8e94377

Browse files
fix analyzer warnings: IDE0024, IDE0039, IDE0066, IDE0010, IDE0074, IDE0075, SA1500, SA1515, CA1827, IDE0044 (#317)
* fix IDE0024: Use expression body for operators * fix IDE0039: Use local function * fix IDE0066: Use 'switch' expression * fix IDE0010: Populate switch * fix IDE0074: Use compound assignment * fix IDE0075: Conditional expression can be simplified * fix SA1500: Braces for multi-line statements should not share line * fix SA1515: Single-line comment should be preceded by blank line * fix CA1827: Do not use Count() or LongCount() when Any() can be used * fix IDE0044: Add readonly modifier
1 parent 2ad1008 commit 8e94377

37 files changed

+169
-257
lines changed

.editorconfig

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,6 @@ dotnet_diagnostic.CA1036.severity = suggestion
738738
# CA1001: Types that own disposable fields should be disposable
739739
dotnet_diagnostic.CA1001.severity = suggestion
740740

741-
# CA1827: Do not use Count() or LongCount() when Any() can be used
742-
dotnet_diagnostic.CA1827.severity = suggestion
743-
744741
# CA1064: Exceptions should be public
745742
dotnet_diagnostic.CA1064.severity = suggestion
746743

@@ -756,21 +753,12 @@ dotnet_diagnostic.CA1834.severity = suggestion
756753
# SA1202: Elements should be ordered by access
757754
dotnet_diagnostic.SA1202.severity = suggestion
758755

759-
# SA1500: Braces for multi-line statements should not share line
760-
dotnet_diagnostic.SA1500.severity = suggestion
761-
762-
# SA1515: Single-line comment should be preceded by blank line
763-
dotnet_diagnostic.SA1515.severity = suggestion
764-
765756
# IDE0022: Use expression body for methods
766757
dotnet_diagnostic.IDE0022.severity = suggestion
767758

768759
# IDE0090: Simplify new expression
769760
dotnet_diagnostic.IDE0090.severity = suggestion
770761

771-
# IDE0044: Add readonly modifier
772-
dotnet_diagnostic.IDE0044.severity = suggestion
773-
774762
# IDE0065: 'using' directive placement
775763
dotnet_diagnostic.IDE0065.severity = suggestion
776764

@@ -829,27 +817,9 @@ dotnet_diagnostic.IDE0027.severity = suggestion
829817
# IDE0120: Simplify LINQ expression
830818
dotnet_diagnostic.IDE0120.severity = suggestion
831819

832-
# IDE0075: Conditional expression can be simplified
833-
dotnet_diagnostic.IDE0075.severity = suggestion
834-
835820
# IDE0037: Member name can be simplified
836821
dotnet_diagnostic.IDE0037.severity = suggestion
837822

838-
# IDE0066: Use 'switch' expression
839-
dotnet_diagnostic.IDE0066.severity = suggestion
840-
841-
# IDE0074: Use compound assignment
842-
dotnet_diagnostic.IDE0074.severity = suggestion
843-
844-
# IDE0024: Use expression body for operators
845-
dotnet_diagnostic.IDE0024.severity = suggestion
846-
847-
# IDE0010: Populate switch
848-
dotnet_diagnostic.IDE0010.severity = suggestion
849-
850-
# IDE0039: Use local function
851-
dotnet_diagnostic.IDE0039.severity = suggestion
852-
853823
# CA1724: Type names should not match namespaces
854824
dotnet_diagnostic.CA1724.severity = suggestion
855825

src/Microsoft.ComponentDetection.Common/CommandLineInvocationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.ComponentDetection.Common
1515
[Export(typeof(ICommandLineInvocationService))]
1616
public class CommandLineInvocationService : ICommandLineInvocationService
1717
{
18-
private IDictionary<string, string> commandLocatableCache = new ConcurrentDictionary<string, string>();
18+
private readonly IDictionary<string, string> commandLocatableCache = new ConcurrentDictionary<string, string>();
1919

2020
public async Task<bool> CanCommandBeLocated(string command, IEnumerable<string> additionalCandidateCommands = null, DirectoryInfo workingDirectory = null, params string[] parameters)
2121
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class SingleFileComponentRecorder : ISingleFileComponentRecorder
9898

9999
private readonly ComponentRecorder recorder;
100100

101-
private object registerUsageLock = new object();
101+
private readonly object registerUsageLock = new object();
102102

103103
public SingleFileComponentRecorder(string location, ComponentRecorder recorder, bool enableManualTrackingOfExplicitReferences, ILogger log)
104104
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace Microsoft.ComponentDetection.Common.DependencyGraph
1313
{
1414
internal class DependencyGraph : IDependencyGraph
1515
{
16-
private ConcurrentDictionary<string, ComponentRefNode> componentNodes;
16+
private readonly ConcurrentDictionary<string, ComponentRefNode> componentNodes;
1717

18-
private bool enableManualTrackingOfExplicitReferences;
18+
private readonly bool enableManualTrackingOfExplicitReferences;
1919

2020
public DependencyGraph(bool enableManualTrackingOfExplicitReferences)
2121
{

src/Microsoft.ComponentDetection.Common/FileWritingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ public class FileWritingService : IFileWritingService
1212
{
1313
public const string TimestampFormatString = "yyyyMMddHHmmssfff";
1414

15-
private object lockObject = new object();
16-
private string timestamp = DateTime.Now.ToString(TimestampFormatString);
15+
private readonly object lockObject = new object();
16+
private readonly string timestamp = DateTime.Now.ToString(TimestampFormatString);
1717

1818
public string BasePath { get; private set; }
1919

src/Microsoft.ComponentDetection.Common/PathUtilityService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class PathUtilityService : IPathUtilityService
3131

3232
private readonly ConcurrentDictionary<string, string> resolvedPaths = new ConcurrentDictionary<string, string>();
3333

34-
private object isRunningOnWindowsContainerLock = new object();
34+
private readonly object isRunningOnWindowsContainerLock = new object();
3535
private bool? isRunningOnWindowsContainer = null;
3636

3737
public bool IsRunningOnWindowsContainer

src/Microsoft.ComponentDetection.Common/SafeFileEnumerable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SafeFileEnumerable : IEnumerable<MatchedFile>
1919

2020
private readonly EnumerationOptions enumerationOptions;
2121

22-
private HashSet<string> enumeratedDirectories;
22+
private readonly HashSet<string> enumeratedDirectories;
2323

2424
public SafeFileEnumerable(DirectoryInfo directory, IEnumerable<string> searchPatterns, ILogger logger, IPathUtilityService pathUtilityService, ExcludeDirectoryPredicate directoryExclusionPredicate, bool recursivelyScanDirectories = true, HashSet<string> previouslyEnumeratedDirectories = null)
2525
{

src/Microsoft.ComponentDetection.Common/TabularStringFormat.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public class TabularStringFormat
1010
public const char DefaultVerticalLineChar = '|';
1111
public const char DefaultHorizontalLineChar = '_';
1212

13-
private IList<Column> columns;
14-
private int totalWidth;
15-
private char horizontalLineChar;
16-
private char verticalLineChar;
17-
private string tableTitle;
13+
private readonly IList<Column> columns;
14+
private readonly int totalWidth;
15+
private readonly char horizontalLineChar;
16+
private readonly char verticalLineChar;
17+
private readonly string tableTitle;
1818

1919
public TabularStringFormat(IList<Column> columns, char horizontalLineChar = DefaultHorizontalLineChar, char verticalLineChar = DefaultVerticalLineChar, string tableTitle = null)
2020
{

src/Microsoft.ComponentDetection.Common/Telemetry/CommandLineTelemetryService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry
1313
[TelemetryService(nameof(CommandLineTelemetryService))]
1414
internal class CommandLineTelemetryService : ITelemetryService
1515
{
16-
private static ConcurrentQueue<JObject> records = new ConcurrentQueue<JObject>();
16+
private static readonly ConcurrentQueue<JObject> Records = new ConcurrentQueue<JObject>();
1717

1818
public const string TelemetryRelativePath = "ScanTelemetry_{timestamp}.json";
1919

@@ -27,7 +27,7 @@ internal class CommandLineTelemetryService : ITelemetryService
2727

2828
public void Flush()
2929
{
30-
this.FileWritingService.WriteFile(TelemetryRelativePath, JsonConvert.SerializeObject(records));
30+
this.FileWritingService.WriteFile(TelemetryRelativePath, JsonConvert.SerializeObject(Records));
3131
}
3232

3333
public void PostRecord(IDetectionTelemetryRecord record)
@@ -38,7 +38,7 @@ public void PostRecord(IDetectionTelemetryRecord record)
3838
jsonRecord.Add("Timestamp", DateTime.UtcNow);
3939
jsonRecord.Add("CorrelationId", TelemetryConstants.CorrelationId);
4040

41-
records.Enqueue(jsonRecord);
41+
Records.Enqueue(jsonRecord);
4242

4343
if (this.telemetryMode == TelemetryMode.Debug)
4444
{

src/Microsoft.ComponentDetection.Common/Telemetry/Records/BaseDetectionTelemetryRecord.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
66
{
77
public abstract class BaseDetectionTelemetryRecord : IDetectionTelemetryRecord
88
{
9-
private Stopwatch stopwatch = new Stopwatch();
9+
private readonly Stopwatch stopwatch = new Stopwatch();
1010

1111
private bool disposedValue = false;
1212

0 commit comments

Comments
 (0)