Skip to content

Commit b1532df

Browse files
Fix analyzer warnings: SA1142, SA1201 (#308)
1 parent abd15de commit b1532df

70 files changed

Lines changed: 1080 additions & 1092 deletions

File tree

Some content is hidden

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

.editorconfig

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

462-
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1142.md
463-
# Refer to tuple fields by name
464-
dotnet_diagnostic.SA1142.severity = suggestion
465-
466462
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md
467463
# Using directive should appear within a namespace declaration
468464
dotnet_diagnostic.SA1200.severity = suggestion
469465

470-
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1201.md
471-
# A field should not follow a property
472-
dotnet_diagnostic.SA1201.severity = suggestion
473-
474466
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1203.md
475467
# 'public' members should come before 'private' members
476468
dotnet_diagnostic.SA1203.severity = suggestion
@@ -570,9 +562,6 @@ dotnet_diagnostic.CA2007.severity = suggestion
570562
# CA1062: Validate arguments of public methods
571563
dotnet_diagnostic.CA1062.severity = suggestion
572564

573-
# SA1201: Elements should appear in the correct order
574-
dotnet_diagnostic.SA1201.severity = suggestion
575-
576565
# CA1819: Properties should not return arrays
577566
dotnet_diagnostic.CA1819.severity = suggestion
578567

src/Microsoft.ComponentDetection.Common/ComponentStreamEnumerable.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ namespace Microsoft.ComponentDetection.Common
88
{
99
public class ComponentStreamEnumerable : IEnumerable<IComponentStream>
1010
{
11-
private IEnumerable<MatchedFile> ToEnumerate { get; }
12-
13-
private ILogger Logger { get; }
14-
1511
public ComponentStreamEnumerable(IEnumerable<MatchedFile> fileEnumerable, ILogger logger)
1612
{
1713
this.ToEnumerate = fileEnumerable;
1814
this.Logger = logger;
1915
}
2016

17+
private IEnumerable<MatchedFile> ToEnumerate { get; }
18+
19+
private ILogger Logger { get; }
20+
2121
public IEnumerator<IComponentStream> GetEnumerator()
2222
{
2323
foreach (var filePairing in this.ToEnumerate)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ public class SingleFileComponentRecorder : ISingleFileComponentRecorder
9494
{
9595
private readonly ILogger log;
9696

97-
public string ManifestFileLocation { get; }
98-
99-
IDependencyGraph ISingleFileComponentRecorder.DependencyGraph => this.DependencyGraph;
100-
101-
internal DependencyGraph DependencyGraph { get; }
102-
10397
private readonly ConcurrentDictionary<string, DetectedComponent> detectedComponentsInternal = new ConcurrentDictionary<string, DetectedComponent>();
10498

10599
private readonly ComponentRecorder recorder;
@@ -114,6 +108,12 @@ public SingleFileComponentRecorder(string location, ComponentRecorder recorder,
114108
this.DependencyGraph = new DependencyGraph(enableManualTrackingOfExplicitReferences);
115109
}
116110

111+
public string ManifestFileLocation { get; }
112+
113+
IDependencyGraph ISingleFileComponentRecorder.DependencyGraph => this.DependencyGraph;
114+
115+
internal DependencyGraph DependencyGraph { get; }
116+
117117
public DetectedComponent GetComponent(string componentId)
118118
{
119119
if (this.detectedComponentsInternal.TryGetValue(componentId, out var detectedComponent))

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ internal class DependencyGraph : IDependencyGraph
1515
{
1616
private ConcurrentDictionary<string, ComponentRefNode> componentNodes;
1717

18-
internal ConcurrentDictionary<string, byte> AdditionalRelatedFiles { get; } = new ConcurrentDictionary<string, byte>();
19-
2018
private bool enableManualTrackingOfExplicitReferences;
2119

2220
public DependencyGraph(bool enableManualTrackingOfExplicitReferences)
@@ -25,6 +23,8 @@ public DependencyGraph(bool enableManualTrackingOfExplicitReferences)
2523
this.enableManualTrackingOfExplicitReferences = enableManualTrackingOfExplicitReferences;
2624
}
2725

26+
internal ConcurrentDictionary<string, byte> AdditionalRelatedFiles { get; } = new ConcurrentDictionary<string, byte>();
27+
2828
public void AddComponent(ComponentRefNode componentNode, string parentComponentId = null)
2929
{
3030
if (componentNode == null)
@@ -134,27 +134,6 @@ bool IDependencyGraph.IsComponentExplicitlyReferenced(string componentId)
134134
return this.IsExplicitReferencedDependency(this.componentNodes[componentId]);
135135
}
136136

137-
internal class ComponentRefNode
138-
{
139-
internal bool IsExplicitReferencedDependency { get; set; }
140-
141-
internal string Id { get; set; }
142-
143-
internal ISet<string> DependencyIds { get; private set; }
144-
145-
internal ISet<string> DependedOnByIds { get; private set; }
146-
147-
internal bool? IsDevelopmentDependency { get; set; }
148-
149-
internal DependencyScope? DependencyScope { get; set; }
150-
151-
internal ComponentRefNode()
152-
{
153-
this.DependencyIds = new HashSet<string>();
154-
this.DependedOnByIds = new HashSet<string>();
155-
}
156-
}
157-
158137
private void GetExplicitReferencedDependencies(ComponentRefNode component, IList<string> explicitReferencedDependencyIds, ISet<string> visited)
159138
{
160139
if (this.IsExplicitReferencedDependency(component))
@@ -194,5 +173,26 @@ private void AddDependency(string componentId, string parentComponentId)
194173
parentComponentRefNode.DependencyIds.Add(componentId);
195174
this.componentNodes[componentId].DependedOnByIds.Add(parentComponentId);
196175
}
176+
177+
internal class ComponentRefNode
178+
{
179+
internal ComponentRefNode()
180+
{
181+
this.DependencyIds = new HashSet<string>();
182+
this.DependedOnByIds = new HashSet<string>();
183+
}
184+
185+
internal bool IsExplicitReferencedDependency { get; set; }
186+
187+
internal string Id { get; set; }
188+
189+
internal ISet<string> DependencyIds { get; private set; }
190+
191+
internal ISet<string> DependedOnByIds { get; private set; }
192+
193+
internal bool? IsDevelopmentDependency { get; set; }
194+
195+
internal DependencyScope? DependencyScope { get; set; }
196+
}
197197
}
198198
}

src/Microsoft.ComponentDetection.Common/DockerReference/DockerRegex.cs

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,58 @@ namespace Microsoft.ComponentDetection.Common
55
{
66
public class DockerRegex
77
{
8+
public static Regex AlphaNumericRegexp = new Regex("[a-z0-9]+");
9+
public static Regex SeparatorRegexp = new Regex("(?:[._]|__|[-]*)");
10+
11+
public static Regex DomainComponentRegexp = new Regex("(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])");
12+
public static Regex TagRegexp = new Regex(@"[\w][\w.-]{0,127}");
13+
public static Regex DigestRegexp = new Regex("[a-zA-Z][a-zA-Z0-9]*(?:[-_+.][a-zA-Z][a-zA-Z0-9]*)*[:][a-fA-F0-9]{32,}");
14+
public static Regex IdentifierRegexp = new Regex("[a-f0-9]{64}");
15+
16+
public static Regex NameComponentRegexp = Expression(
17+
AlphaNumericRegexp,
18+
Optional(Repeated(SeparatorRegexp, AlphaNumericRegexp)));
19+
20+
public static Regex DomainRegexp = Expression(
21+
DomainComponentRegexp,
22+
Optional(
23+
Repeated(
24+
new Regex(@"\."),
25+
DomainComponentRegexp)),
26+
Optional(
27+
new Regex(":"),
28+
new Regex("[0-9]+")));
29+
30+
public static Regex AnchoredDigestRegexp = Anchored(DigestRegexp);
31+
32+
public static Regex NameRegexp = Expression(
33+
Optional(
34+
DomainRegexp,
35+
new Regex(@"\/")),
36+
NameComponentRegexp,
37+
Optional(
38+
Repeated(
39+
new Regex(@"\/"),
40+
NameComponentRegexp)));
41+
42+
public static Regex AnchoredNameRegexp = Anchored(
43+
Optional(
44+
Capture(DomainRegexp),
45+
new Regex(@"\/")),
46+
Capture(
47+
NameComponentRegexp,
48+
Optional(
49+
Repeated(
50+
new Regex(@"\/"),
51+
NameComponentRegexp))));
52+
53+
public static Regex ReferenceRegexp = Anchored(
54+
Capture(NameRegexp),
55+
Optional(new Regex(":"), Capture(TagRegexp)),
56+
Optional(new Regex("@"), Capture(DigestRegexp)));
57+
58+
public static Regex AnchoredIdentifierRegexp = Anchored(IdentifierRegexp);
59+
860
/// <summary>
961
/// expression defines a full expression, where each regular expression must follow the previous.
1062
/// </summary>
@@ -64,57 +116,5 @@ public static Regex Capture(params Regex[] regexps)
64116
{
65117
return new Regex($"({Expression(regexps).ToString()})");
66118
}
67-
68-
public static Regex AlphaNumericRegexp = new Regex("[a-z0-9]+");
69-
public static Regex SeparatorRegexp = new Regex("(?:[._]|__|[-]*)");
70-
71-
public static Regex DomainComponentRegexp = new Regex("(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])");
72-
public static Regex TagRegexp = new Regex(@"[\w][\w.-]{0,127}");
73-
public static Regex DigestRegexp = new Regex("[a-zA-Z][a-zA-Z0-9]*(?:[-_+.][a-zA-Z][a-zA-Z0-9]*)*[:][a-fA-F0-9]{32,}");
74-
public static Regex IdentifierRegexp = new Regex("[a-f0-9]{64}");
75-
76-
public static Regex NameComponentRegexp = Expression(
77-
AlphaNumericRegexp,
78-
Optional(Repeated(SeparatorRegexp, AlphaNumericRegexp)));
79-
80-
public static Regex DomainRegexp = Expression(
81-
DomainComponentRegexp,
82-
Optional(
83-
Repeated(
84-
new Regex(@"\."),
85-
DomainComponentRegexp)),
86-
Optional(
87-
new Regex(":"),
88-
new Regex("[0-9]+")));
89-
90-
public static Regex AnchoredDigestRegexp = Anchored(DigestRegexp);
91-
92-
public static Regex NameRegexp = Expression(
93-
Optional(
94-
DomainRegexp,
95-
new Regex(@"\/")),
96-
NameComponentRegexp,
97-
Optional(
98-
Repeated(
99-
new Regex(@"\/"),
100-
NameComponentRegexp)));
101-
102-
public static Regex AnchoredNameRegexp = Anchored(
103-
Optional(
104-
Capture(DomainRegexp),
105-
new Regex(@"\/")),
106-
Capture(
107-
NameComponentRegexp,
108-
Optional(
109-
Repeated(
110-
new Regex(@"\/"),
111-
NameComponentRegexp))));
112-
113-
public static Regex ReferenceRegexp = Anchored(
114-
Capture(NameRegexp),
115-
Optional(new Regex(":"), Capture(TagRegexp)),
116-
Optional(new Regex("@"), Capture(DigestRegexp)));
117-
118-
public static Regex AnchoredIdentifierRegexp = Anchored(IdentifierRegexp);
119119
}
120120
}

src/Microsoft.ComponentDetection.Common/DockerService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public class DockerService : IDockerService
2121

2222
private static int incrementingContainerId;
2323

24-
[Import]
25-
public ILogger Logger { get; set; }
26-
2724
// Base image annotations from ADO dockerTask
2825
private const string BaseImageRefAnnotation = "image.base.ref.name";
2926
private const string BaseImageDigestAnnotation = "image.base.digest";
3027

28+
[Import]
29+
public ILogger Logger { get; set; }
30+
3131
public async Task<bool> CanPingDockerAsync(CancellationToken cancellationToken = default)
3232
{
3333
try

src/Microsoft.ComponentDetection.Common/LazyComponentStream.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ public class LazyComponentStream : IComponentStream
1010
private readonly Lazy<byte[]> fileBuffer;
1111
private readonly ILogger logger;
1212

13+
public LazyComponentStream(FileInfo fileInfo, string pattern, ILogger logger)
14+
{
15+
this.Pattern = pattern;
16+
this.Location = fileInfo.FullName;
17+
this.fileInfo = fileInfo;
18+
this.logger = logger;
19+
this.fileBuffer = new Lazy<byte[]>(this.SafeOpenFile);
20+
}
21+
22+
public Stream Stream => new MemoryStream(this.fileBuffer.Value);
23+
24+
public string Pattern { get; set; }
25+
26+
public string Location { get; set; }
27+
1328
private byte[] SafeOpenFile()
1429
{
1530
try
@@ -33,20 +48,5 @@ private byte[] SafeOpenFile()
3348

3449
return new byte[0];
3550
}
36-
37-
public LazyComponentStream(FileInfo fileInfo, string pattern, ILogger logger)
38-
{
39-
this.Pattern = pattern;
40-
this.Location = fileInfo.FullName;
41-
this.fileInfo = fileInfo;
42-
this.logger = logger;
43-
this.fileBuffer = new Lazy<byte[]>(this.SafeOpenFile);
44-
}
45-
46-
public Stream Stream => new MemoryStream(this.fileBuffer.Value);
47-
48-
public string Pattern { get; set; }
49-
50-
public string Location { get; set; }
5151
}
5252
}

src/Microsoft.ComponentDetection.Common/Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace Microsoft.ComponentDetection.Common
1313
[Shared]
1414
public class Logger : ILogger
1515
{
16+
public const string LogRelativePath = "GovCompDisc_Log_{timestamp}.log";
17+
1618
[Import]
1719
public IFileWritingService FileWritingService { get; set; }
1820

@@ -23,8 +25,6 @@ public class Logger : ILogger
2325

2426
private bool WriteToFile { get; set; }
2527

26-
public const string LogRelativePath = "GovCompDisc_Log_{timestamp}.log";
27-
2828
public void Init(VerbosityMode verbosity)
2929
{
3030
this.WriteToFile = true;

0 commit comments

Comments
 (0)