Skip to content

Commit 3da9140

Browse files
daniel-akiliDaniel AkiliJamieMagee
authored
fix: CA1829, CA1834, CA1846, CA1847 (#338)
* CA1829 * CA1834 * CA1846, CA1847 * updated if statement condition * added JSON002 as suggestion * pr snapshot * spdx elements count * removed JSON22 suggestion * if statement syntax update Co-authored-by: Jamie Magee <[email protected]> * updated if statement * if statement * removed extra '?' * verifying snapshots early success * short if statement syntax Co-authored-by: Daniel Akili <[email protected]> Co-authored-by: Jamie Magee <[email protected]>
1 parent dae3f37 commit 3da9140

File tree

7 files changed

+17
-26
lines changed

7 files changed

+17
-26
lines changed

.editorconfig

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,6 @@ dotnet_diagnostic.CA1725.severity = suggestion
621621
# CA1805: Do not initialize unnecessarily
622622
dotnet_diagnostic.CA1805.severity = suggestion
623623

624-
# CA1846: Prefer 'AsSpan' over 'Substring'
625-
dotnet_diagnostic.CA1846.severity = suggestion
626-
627624
# CA1806: Do not ignore method results
628625
dotnet_diagnostic.CA1806.severity = suggestion
629626

@@ -684,9 +681,6 @@ dotnet_diagnostic.CA1508.severity = suggestion
684681
# CA1823: Avoid unused private fields
685682
dotnet_diagnostic.CA1823.severity = suggestion
686683

687-
# CA1829: Use Length/Count property instead of Count() when available
688-
dotnet_diagnostic.CA1829.severity = suggestion
689-
690684
# CA2234: Pass system uri objects instead of strings
691685
dotnet_diagnostic.CA2234.severity = suggestion
692686

@@ -699,9 +693,6 @@ dotnet_diagnostic.CA2219.severity = suggestion
699693
# CA2201: Exception type System.Exception is not sufficiently specific
700694
dotnet_diagnostic.CA2201.severity = suggestion
701695

702-
# CA1847: Use char literal for a single character lookup
703-
dotnet_diagnostic.CA1847.severity = suggestion
704-
705696
# CA1835: Prefer the 'Memory'-based overloads for 'ReadAsync' and 'WriteAsync'
706697
dotnet_diagnostic.CA1835.severity = suggestion
707698

@@ -720,9 +711,6 @@ dotnet_diagnostic.CA1837.severity = suggestion
720711
# CA1024: Use properties where appropriate
721712
dotnet_diagnostic.CA1024.severity = suggestion
722713

723-
# CA1834: Consider using 'StringBuilder.Append(char)' when applicable
724-
dotnet_diagnostic.CA1834.severity = suggestion
725-
726714
# SA1202: Elements should be ordered by access
727715
dotnet_diagnostic.SA1202.severity = suggestion
728716

@@ -786,3 +774,6 @@ dotnet_diagnostic.CA1852.severity = suggestion
786774

787775
# CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method
788776
dotnet_diagnostic.CA1854.severity = suggestion
777+
778+
# JSON002: Probable JSON string detected
779+
dotnet_diagnostic.JSON002.severity = suggestion

src/Microsoft.ComponentDetection.Detectors/spdx/Spdx22ComponentDetector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Composition;
44
using System.IO;
@@ -91,7 +91,7 @@ private SpdxComponent ConvertJObjectToSbomComponent(ProcessRequest processReques
9191
var name = document["name"]?.ToString();
9292
var spdxVersion = document["spdxVersion"]?.ToString();
9393

94-
if (rootElements != null && rootElements.Count() > 1)
94+
if (rootElements?.Length > 1)
9595
{
9696
this.Logger.LogWarning($"SPDX file at {processRequest.ComponentStream.Location} has more than one element in documentDescribes, first will be selected as root element.");
9797
}

src/Microsoft.ComponentDetection.Detectors/yarn/Parsers/YarnLockParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private Func<string, string> GenerateBlockTitleNormalizer(YarnBlock block)
117117
// resolved "https://registry.Yarnpkg.com/nyc/-/nyc-10.0.0.tgz#95bd4a2c3487f33e1e78f213c6d5a53d88074ce6"
118118
return blockTitleMember =>
119119
{
120-
if (blockTitleMember.Contains("@"))
120+
if (blockTitleMember.Contains('@'))
121121
{
122122
return blockTitleMember;
123123
}
@@ -140,7 +140,7 @@ private bool TryReadNameAndSatisfiedVersion(string nameVersionPairing, out Tuple
140140
workingString = workingString.TrimEnd(':');
141141
workingString = workingString.Trim('\"');
142142
var startsWithAtSign = false;
143-
if (workingString.StartsWith("@"))
143+
if (workingString.StartsWith('@'))
144144
{
145145
startsWithAtSign = true;
146146
workingString = workingString.TrimStart('@');

test/Microsoft.ComponentDetection.Detectors.Tests/RustDependencySpecifierTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using FluentAssertions;
33
using Microsoft.ComponentDetection.Detectors.Rust;
44
using Microsoft.ComponentDetection.Detectors.Rust.Contracts;

test/Microsoft.ComponentDetection.Detectors.Tests/SPDX22ComponentDetectorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public async Task TestSbomDetector_SimpleSbom()
118118
Encoding.UTF8.GetBytes(spdxFile))).Replace("-", string.Empty).ToLower();
119119
#pragma warning restore CA5350
120120

121-
Assert.AreEqual(1, components.Count());
121+
Assert.AreEqual(1, components.Count);
122122
Assert.AreEqual(sbomComponent.Name, "Test 1.0.0");
123123
Assert.AreEqual(sbomComponent.RootElementId, "SPDXRef-RootPackage");
124124
Assert.AreEqual(sbomComponent.DocumentNamespace, new Uri("https://sbom.microsoft/Test/1.0.0/61de1a5-57cc-4732-9af5-edb321b4a7ee"));

test/Microsoft.ComponentDetection.Detectors.Tests/VcpkgComponentDetectorTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public async Task TestNlohmann()
6464
throw new AssertFailedException($"{nameof(sbomComponent)} is null");
6565
}
6666

67-
Assert.AreEqual(1, components.Count());
67+
Assert.AreEqual(1, components.Count);
6868
Assert.AreEqual("nlohmann-json", sbomComponent.Name);
6969
Assert.AreEqual("3.10.4", sbomComponent.Version);
7070
Assert.AreEqual(5, sbomComponent.PortVersion);
@@ -117,7 +117,7 @@ public async Task TestTinyxmlAndResource()
117117
var detectedComponents = componentRecorder.GetDetectedComponents();
118118
var components = detectedComponents.ToList();
119119

120-
Assert.AreEqual(2, components.Count());
120+
Assert.AreEqual(2, components.Count);
121121
var sbomComponent = (VcpkgComponent)components.FirstOrDefault(c => ((VcpkgComponent)c?.Component).SPDXID.Equals("SPDXRef-binary")).Component;
122122
Assert.IsNotNull(sbomComponent);
123123
Assert.AreEqual("tinyxml2:x64-linux", sbomComponent.Name);

test/Microsoft.ComponentDetection.Detectors.Tests/YarnLockDetectorTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -859,7 +859,7 @@ public async Task MalformedYarnLockV1_Duplicate()
859859
private string CreatePackageJsonFileContent(IList<YarnTestComponentDefinition> components)
860860
{
861861
var builder = new StringBuilder();
862-
builder.Append("{");
862+
builder.Append('{');
863863
builder.Append(@"""name"": ""test"",");
864864
builder.Append(@"""version"": ""0.0.0"",");
865865
builder.Append(@"""dependencies"": {");
@@ -877,11 +877,11 @@ private string CreatePackageJsonFileContent(IList<YarnTestComponentDefinition> c
877877
}
878878
}
879879

880-
builder.Append("}");
880+
builder.Append('}');
881881

882882
if (components.Any(component => component.IsDevDependency))
883883
{
884-
builder.Append(",");
884+
builder.Append(',');
885885
builder.Append(@"""devDependencies"": {");
886886

887887
var dependencyComponents = components.Where(c => c.IsDevDependency).ToList();
@@ -899,8 +899,8 @@ private string CreatePackageJsonFileContent(IList<YarnTestComponentDefinition> c
899899
}
900900
}
901901

902-
builder.Append("}");
903-
builder.Append("}");
902+
builder.Append('}');
903+
builder.Append('}');
904904

905905
return builder.ToString();
906906
}

0 commit comments

Comments
 (0)