Skip to content

Commit

Permalink
Fix linting issues (cake-contrib#516)
Browse files Browse the repository at this point in the history
* Use concrete types for improved performance (CA1859)
* Simplify if statement (IDE0046)
* Use caller info (S3236)
* Remove lambda expression (IDE0200)
* Fix formatting (IDE0055)
  • Loading branch information
pascalberger authored Nov 21, 2024
1 parent f7f6f46 commit 0b18de6
Show file tree
Hide file tree
Showing 35 changed files with 204 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void Should_Handle_Issue_Provider_With_Different_Type_But_Same_Run()
// Then
result.Count().ShouldBe(2);

result.ShouldContain(x =>
result.ShouldContain(x =>
x.Name == "Issues-Fake Issue Provider (Run 1)" &&
x.Genre == "Cake.Issues.Recipe" &&
x.State == PullRequestStatusState.Failed &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override Uri DetermineRepositoryRemoteUrl(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
context.NotNull();

return context.AppVeyor().Environment.Repository.Provider switch
{
Expand All @@ -31,23 +31,23 @@ public override string DetermineCommitId(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
context.NotNull();

return context.AppVeyor().Environment.Repository.Commit.Id;
}

/// <inheritdoc />
public override bool DetermineIfPullRequest(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

return context.AppVeyor().Environment.PullRequest.IsPullRequest;
}

/// <inheritdoc />
public override int? DeterminePullRequestId(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

return context.AppVeyor().Environment.PullRequest.Number;
}
Expand All @@ -56,7 +56,7 @@ public override bool DetermineIfPullRequest(IIssuesContext context)
public override void ReportIssuesToBuildServer(
IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

context.ReportIssuesToPullRequest(
context.State.Issues,
Expand All @@ -69,15 +69,15 @@ public override void CreateSummaryIssuesReport(
IIssuesContext context,
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "")
{
context.NotNull(nameof(context));
context.NotNull();

// Summary issues report is not supported for AppVeyor.
}

/// <inheritdoc />
public override void PublishIssuesArtifacts(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

if (context.Parameters.BuildServer.ShouldPublishFullIssuesReport &&
context.State.FullIssuesReport != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override Uri DetermineRepositoryRemoteUrl(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
context.NotNull();

return new Uri(context.EnvironmentVariable("BUILD_REPOSITORY_URI"));
}
Expand All @@ -26,15 +26,15 @@ public override string DetermineCommitId(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
context.NotNull();

return context.AzurePipelines().Environment.Repository.SourceVersion;
}

/// <inheritdoc />
public override bool DetermineIfPullRequest(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

// Could be simplified once https://github.com/cake-build/cake/issues/2149 is fixed
return !string.IsNullOrWhiteSpace(context.EnvironmentVariable("SYSTEM_PULLREQUEST_PULLREQUESTID"));
Expand All @@ -43,23 +43,18 @@ public override bool DetermineIfPullRequest(IIssuesContext context)
/// <inheritdoc />
public override int? DeterminePullRequestId(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

if (!Int32.TryParse(context.EnvironmentVariable("SYSTEM_PULLREQUEST_PULLREQUESTID"), out var pullRequestId))
{
throw new Exception($"Invalid pull request ID: {context.EnvironmentVariable("SYSTEM_PULLREQUEST_PULLREQUESTID")}");
}
else
{
return pullRequestId;
}
return Int32.TryParse(context.EnvironmentVariable("SYSTEM_PULLREQUEST_PULLREQUESTID"), out var pullRequestId)
? pullRequestId
: throw new Exception($"Invalid pull request ID: {context.EnvironmentVariable("SYSTEM_PULLREQUEST_PULLREQUESTID")}");

Check warning on line 50 in Cake.Frosting.Issues.Recipe/Cake.Frosting.Issues.Recipe/BuildServers/AzureDevOpsBuildServer.cs

View workflow job for this annotation

GitHub Actions / Build

Exception type System.Exception is not sufficiently specific (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2201)

Check warning on line 50 in Cake.Frosting.Issues.Recipe/Cake.Frosting.Issues.Recipe/BuildServers/AzureDevOpsBuildServer.cs

View workflow job for this annotation

GitHub Actions / Build

Exception type System.Exception is not sufficiently specific (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2201)

Check warning on line 50 in Cake.Frosting.Issues.Recipe/Cake.Frosting.Issues.Recipe/BuildServers/AzureDevOpsBuildServer.cs

View workflow job for this annotation

GitHub Actions / Build

Exception type System.Exception is not sufficiently specific (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2201)

Check warning on line 50 in Cake.Frosting.Issues.Recipe/Cake.Frosting.Issues.Recipe/BuildServers/AzureDevOpsBuildServer.cs

View workflow job for this annotation

GitHub Actions / Build

Exception type System.Exception is not sufficiently specific (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2201)
}

/// <inheritdoc />
public override void ReportIssuesToBuildServer(
IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

foreach (var issue in context.State.Issues)
{
Expand All @@ -78,7 +73,7 @@ public override void CreateSummaryIssuesReport(
IIssuesContext context,
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "")
{
context.NotNull(nameof(context));
context.NotNull();

var summaryFileName = "summary";
if (!string.IsNullOrWhiteSpace(context.Parameters.BuildIdentifier))
Expand Down Expand Up @@ -113,7 +108,7 @@ public override void CreateSummaryIssuesReport(
/// <inheritdoc />
public override void PublishIssuesArtifacts(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

if (context.Parameters.BuildServer.ShouldPublishFullIssuesReport &&
context.State.FullIssuesReport != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public virtual Uri DetermineRepositoryRemoteUrl(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
repositoryRootDirectory.NotNull(nameof(repositoryRootDirectory));
context.NotNull();
repositoryRootDirectory.NotNull();

return context.State.RepositoryInfo.GetRepositoryRemoteUrl(context, repositoryRootDirectory);
}
Expand All @@ -23,24 +23,24 @@ public virtual string DetermineCommitId(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
repositoryRootDirectory.NotNull(nameof(repositoryRootDirectory));
context.NotNull();
repositoryRootDirectory.NotNull();

return context.State.RepositoryInfo.GetCommitId(context, repositoryRootDirectory);
}

/// <inheritdoc />
public virtual bool DetermineIfPullRequest(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

return false;
}

/// <inheritdoc />
public virtual int? DeterminePullRequestId(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override Uri DetermineRepositoryRemoteUrl(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
context.NotNull();

return new Uri($"https://github.com/{context.GitHubActions().Environment.Workflow.Repository}.git");
}
Expand All @@ -23,23 +23,23 @@ public override string DetermineCommitId(
IIssuesContext context,
DirectoryPath repositoryRootDirectory)
{
context.NotNull(nameof(context));
context.NotNull();

return context.GitHubActions().Environment.Workflow.Sha;
}

/// <inheritdoc />
public override bool DetermineIfPullRequest(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

return context.GitHubActions().Environment.PullRequest.IsPullRequest;
}

/// <inheritdoc />
public override int? DeterminePullRequestId(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

// Not supported by GitHub Actions
return null;
Expand All @@ -49,7 +49,7 @@ public override bool DetermineIfPullRequest(IIssuesContext context)
public override void ReportIssuesToBuildServer(
IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

context.ReportIssuesToPullRequest(
context.State.Issues,
Expand All @@ -62,15 +62,15 @@ public override void CreateSummaryIssuesReport(
IIssuesContext context,
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "")
{
context.NotNull(nameof(context));
context.NotNull();

// Summary issues report is not supported for GitHub Actions.
}

/// <inheritdoc />
public override void PublishIssuesArtifacts(IIssuesContext context)
{
context.NotNull(nameof(context));
context.NotNull();

// Publishing artifacts is currently not supported for GitHub Actions.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
/// <typeparam name="TParameters">Type of the parameters description.</typeparam>
/// <typeparam name="TState">Type of the build state description.</typeparam>
public abstract class IssuesContext<TParameters, TState> : FrostingContext, IIssuesContext
where TParameters: IIssuesParameters
where TState: IIssuesState
where TParameters : IIssuesParameters
where TState : IIssuesState
{
private readonly Lazy<TParameters> parameters;
private readonly Lazy<TState> state;
Expand Down Expand Up @@ -44,8 +44,8 @@ protected IssuesContext(ICakeContext context)
var versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
context.Information("Initializing Cake.Frosting.Issues.Recipe (Version {0})...", versionInfo.FileVersion);

this.parameters = new Lazy<TParameters>(() => this.CreateIssuesParameters());
this.state = new Lazy<TState>(() => this.CreateIssuesState());
this.parameters = new Lazy<TParameters>(this.CreateIssuesParameters);
this.state = new Lazy<TState>(this.CreateIssuesState);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void AddMsBuildBinaryLogFile(FilePath logfilePath, IReadIssuesSettings se
/// <inheritdoc />
public void AddMsBuildBinaryLogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.MsBuildBinaryLogFilePaths.Add(logfilePath, settings);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ public void AddInspectCodeLogFile(FilePath logfilePath, IReadIssuesSettings sett
/// <inheritdoc />
public void AddInspectCodeLogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.InspectCodeLogFilePaths.Add(logfilePath, settings);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public void AddMarkdownlintCliLogFile(FilePath logfilePath, IReadIssuesSettings
/// <inheritdoc />
public void AddMarkdownlintCliLogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.MarkdownlintCliLogFilePaths.Add(logfilePath, settings);
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public void AddMarkdownlintCliJsonLogFile(FilePath logfilePath, IReadIssuesSetti
/// <inheritdoc />
public void AddMarkdownlintCliJsonLogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.MarkdownlintCliJsonLogFilePaths.Add(logfilePath, settings);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ public void AddMarkdownlintV1LogFile(FilePath logfilePath, IReadIssuesSettings s
/// <inheritdoc />
public void AddMarkdownlintV1LogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.MarkdownlintV1LogFilePaths.Add(logfilePath, settings);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ public void AddEsLintJsonLogFile(FilePath logfilePath, IReadIssuesSettings setti
/// <inheritdoc />
public void AddEsLintJsonLogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.EsLintJsonLogFilePaths.Add(logfilePath, settings);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ public void AddSarifLogFile(FilePath logfilePath, IReadIssuesSettings settings)
/// <inheritdoc />
public void AddSarifLogFilePath(FilePath logfilePath, IReadIssuesSettings settings)
{
logfilePath.NotNull(nameof(logfilePath));
logfilePath.NotNull();

this.SarifLogFilePaths.Add(logfilePath, settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class IssuesParametersReporting : IIssuesParametersReporting
public bool ShouldReportIssuesToConsole { get; set; }

/// <inheritdoc />
public ConsoleIssueReportFormatSettings ReportToConsoleSettings { get; set; } =
public ConsoleIssueReportFormatSettings ReportToConsoleSettings { get; set; } =
new ConsoleIssueReportFormatSettings();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace Cake.Frosting.Issues.Recipe
/// <typeparam name="TBuildServer">Type of parameters for build server integration.</typeparam>
/// <typeparam name="TPullRequestSystem">Type of parameters for pull request system integration</typeparam>
public abstract class IssuesParameters<TInputFiles, TReporting, TBuildServer, TPullRequestSystem> : IIssuesParameters
where TInputFiles: IIssuesParametersInputFiles
where TReporting: IIssuesParametersReporting
where TBuildServer: IIssuesParametersBuildServer
where TPullRequestSystem: IIssuesParametersPullRequestSystem
where TInputFiles : IIssuesParametersInputFiles
where TReporting : IIssuesParametersReporting
where TBuildServer : IIssuesParametersBuildServer
where TPullRequestSystem : IIssuesParametersPullRequestSystem
{
private readonly Lazy<TInputFiles> inputFiles;
private readonly Lazy<TReporting> reporting;
Expand Down Expand Up @@ -51,10 +51,10 @@ public abstract class IssuesParameters<TInputFiles, TReporting, TBuildServer, TP
/// </summary>
protected IssuesParameters()
{
this.inputFiles = new Lazy<TInputFiles>(() => this.CreateInputFilesParameters());
this.reporting = new Lazy<TReporting>(() => this.CreateReportingParameters());
this.buildServer = new Lazy<TBuildServer>(() => this.CreateBuildServerParameters());
this.pullRequestSystem = new Lazy<TPullRequestSystem>(() => this.CreatePullRequestSystemParameters());
this.inputFiles = new Lazy<TInputFiles>(this.CreateInputFilesParameters);
this.reporting = new Lazy<TReporting>(this.CreateReportingParameters);
this.buildServer = new Lazy<TBuildServer>(this.CreateBuildServerParameters);
this.pullRequestSystem = new Lazy<TPullRequestSystem>(this.CreatePullRequestSystemParameters);
}

/// <summary>
Expand Down
Loading

0 comments on commit 0b18de6

Please sign in to comment.