Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove warnings from terminal when compiling the test runner. #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nicrowe00
Copy link
Contributor

@nicrowe00 nicrowe00 commented Dec 5, 2024

A fix for the test runner that patches most of the warnings that are reported in the terminal when compiling the test runner. Some warnings were suppressed as it was too time-consuming or there were impacts to other parts of the test runner when they were fixed.

Fixes #83

@nicrowe00 nicrowe00 force-pushed the warnings branch 2 times, most recently from ff2ff38 to c51809d Compare December 5, 2024 11:03
A fix for the test runner that patches most of the warnings
that are reported in the terminal when compiling the test runner.
Some warnings were suppressed as it was too time-consuming or
there were impacts to other parts of the test runner when they
were fixed.
@nicrowe00
Copy link
Contributor Author

CentOS 9 and 10 are unrelated to this PR.

@nicrowe00 nicrowe00 requested review from tmds and omajid December 5, 2024 12:54
public List<string> IgnoredRIDs { get; set; } = new();
public List<string> SkipWhen { get; set; } = new();
#pragma warning disable CA1051 // Do not declare visible instance fields
public List<string> IgnoredRIDs = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a {get; set;} so these become properties instead of instance fields. Then you can omit the warning supressions.

public class Program
#pragma warning restore CA1052 // Static holder types should be Static or NotInheritable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add the static modifier instead of suppressing these warnings?

@@ -18,7 +18,9 @@ public List<string> CurrentIds

public List<string> ComputePlatformIds(string[] osReleaseLines, string lddVersionOutput)
{
#pragma warning disable CA1308 // Normalize strings to uppercase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never had this warning. Do we have some specific analyzer settings?

Anyway, I'd simplify this code to (which probably won't get rid of the warning):

string arch = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant();

Or if you want to do something fancy:

static class EnumExtensionMethods
{
    public static string ToLowerInvariant(this Enum e)
        => e.ToString().ToLowerInvariant();
}

Comment on lines +44 to +50
public Task<string> GenerateNuGetConfig(List<string> urls, string nugetConfig = null)
#pragma warning restore CA1822 // Mark members as static
{
if( !urls.Any() && nugetConfig == null )
#pragma warning disable CA2208 // Instantiate argument exceptions correctly
throw new ArgumentNullException();
#pragma warning restore CA2208 // Instantiate argument exceptions correctly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!urls.Any())
   ArgumentNullException.ThrowIfNull(nugetConfig);

@@ -36,7 +36,9 @@ public static IEnumerable<string> LocalProjectCruft()
yield return "project.lock.json";
}

public async Task CleanProjectLocalDotNetCruftAsync()
#pragma warning disable CA1822 // Mark members as static
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to https://github.com/redhat-developer/dotnet-bunny/pull/91/files#r1888234678, I'm not used to seeing this message though I often don't add the static keyword to members that are not using instance members. I wonder if we have some specific analyser settings that trigger this?

@tmds
Copy link
Member

tmds commented Dec 17, 2024

@nicrowe00 thanks for tacking this! Some of the changes you are making made me wonder if the analyzers you are fixing against are more strict than what I'm used to. I see there are some analyser references being made:

<PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.6" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="2.6" />
<PackageReference Include="Text.Analyzers" Version="2.6" />

If we want to keep these analyzers but don't want to strictly apply every rule (for example requiring the static) then we can suppress those at the project level or introduce an editorconfig file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix warnings reported when compiling the test runner
2 participants