Skip to content

Commit 4387dc4

Browse files
authored
Enable Roslyn analysis - BuildTasks (#4666)
* BuildTasks - enable analysis * cleanup * Mute CA1819
1 parent b3b3329 commit 4387dc4

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

src/OpenTelemetry.AutoInstrumentation.BuildTasks/CheckForInstrumentationPackages.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ public class CheckForInstrumentationPackages : Microsoft.Build.Utilities.Task
2020
/// Gets or sets the list of instrumentation target items.
2121
/// </summary>
2222
/// <remarks>
23-
/// See the <code>InstrumentationTarget</code>"/> items on the <code>.targets</code> file for a list of the
23+
/// See the <code>InstrumentationTarget</code> items on the <code>.targets</code> file for a list of the
2424
/// required metadata.
2525
/// </remarks>
2626
[Required]
27+
#pragma warning disable CA1819 // Properties should not return arrays. Keeping to avoid breaking changes.
2728
public ITaskItem[]? InstrumentationTargetItems { get; set; }
29+
#pragma warning restore CA1819 // Properties should not return arrays. Keeping to avoid breaking changes.
2830

2931
/// <summary>
3032
/// Gets or sets the list of runtime copy local items.
@@ -33,7 +35,9 @@ public class CheckForInstrumentationPackages : Microsoft.Build.Utilities.Task
3335
/// This list generated by the standard build target <code>ResolvePackageAssets</code>.
3436
/// </remarks>
3537
[Required]
38+
#pragma warning disable CA1819 // Properties should not return arrays. Keeping to avoid breaking changes.
3639
public ITaskItem[]? RuntimeCopyLocalItems { get; set; }
40+
#pragma warning restore CA1819 // Properties should not return arrays. Keeping to avoid breaking changes.
3741

3842
/// <summary>
3943
/// Gets or sets a value indicating whether to use verbose logging.
@@ -82,7 +86,7 @@ private bool ExecuteImplementation()
8286
}
8387

8488
// Process each instrumentation target item.
85-
foreach (var instrumentationTarget in InstrumentationTargetItems ?? Array.Empty<ITaskItem>())
89+
foreach (var instrumentationTarget in InstrumentationTargetItems ?? [])
8690
{
8791
MissingInstrumentationAdapterPackage(instrumentationTarget, runtimeCopyLocalItemsDictionary);
8892
}

src/OpenTelemetry.AutoInstrumentation.BuildTasks/InstrumentationTarget.cs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ public VersionRange TargetNuGetPackageVersionRange
4141
{
4242
get
4343
{
44-
if (_targetNuGetPackageVersionRange is null)
45-
{
46-
_targetNuGetPackageVersionRange = ReadAndParseMetadata<VersionRange>(
47-
"TargetNuGetPackageVersionRange", VersionRange.TryParse);
48-
}
44+
_targetNuGetPackageVersionRange ??= ReadAndParseMetadata<VersionRange>(
45+
"TargetNuGetPackageVersionRange", VersionRange.TryParse);
4946

5047
return _targetNuGetPackageVersionRange;
5148
}
@@ -55,16 +52,13 @@ public string InstrumentationNuGetPackageId
5552
{
5653
get
5754
{
58-
if (_instrumentationNuGetPackageId is null)
59-
{
60-
_instrumentationNuGetPackageId = ReadAndParseMetadata(
61-
"InstrumentationNuGetPackageId",
62-
(string value, out string parsedValue) =>
63-
{
64-
parsedValue = value;
65-
return true;
66-
});
67-
}
55+
_instrumentationNuGetPackageId ??= ReadAndParseMetadata(
56+
"InstrumentationNuGetPackageId",
57+
(string value, out string parsedValue) =>
58+
{
59+
parsedValue = value;
60+
return true;
61+
});
6862

6963
return _instrumentationNuGetPackageId;
7064
}
@@ -74,11 +68,8 @@ public NuGetVersion InstrumentationNuGetPackageVersion
7468
{
7569
get
7670
{
77-
if (_instrumentationNuGetPackageVersion is null)
78-
{
79-
_instrumentationNuGetPackageVersion = ReadAndParseMetadata<NuGetVersion>(
80-
"InstrumentationNuGetPackageVersion", NuGetVersion.TryParse);
81-
}
71+
_instrumentationNuGetPackageVersion ??= ReadAndParseMetadata<NuGetVersion>(
72+
"InstrumentationNuGetPackageVersion", NuGetVersion.TryParse);
8273

8374
return _instrumentationNuGetPackageVersion;
8475
}

src/OpenTelemetry.AutoInstrumentation.BuildTasks/OpenTelemetry.AutoInstrumentation.BuildTasks.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
<!-- The version of certain packages is needed to copy dependencies when creating the NuGet package -->
1515
<NuGetVersioningVersion>6.5.0</NuGetVersioningVersion>
16+
<AnalysisLevel>latest-All</AnalysisLevel>
1617
</PropertyGroup>
1718

1819
<!-- ItemGroup with build files -->

0 commit comments

Comments
 (0)