Skip to content

Commit

Permalink
Fix code inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Apr 22, 2020
1 parent b3dbcc9 commit 8c26d94
Show file tree
Hide file tree
Showing 52 changed files with 102 additions and 156 deletions.
1 change: 0 additions & 1 deletion build/Build.CodeGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using static Nuke.CodeGeneration.ReferenceUpdater;
using static Nuke.CodeGeneration.SchemaGenerator;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.Git.GitTasks;

partial class Build
Expand Down
1 change: 0 additions & 1 deletion build/Build.GitFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.IO;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Nuke.Common;
using Nuke.Common.Git;
Expand Down
2 changes: 0 additions & 2 deletions build/Build.GlobalSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.GitHub;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.ControlFlow;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.IO.SerializationTasks;
using static Nuke.Common.ProjectModel.ProjectModelTasks;
using static Nuke.Common.Tools.Git.GitTasks;
Expand Down
3 changes: 1 addition & 2 deletions source/Nuke.CodeGeneration/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
Expand Down Expand Up @@ -62,7 +61,7 @@ public static void GenerateCode(Tool tool, string outputFile)
Logger.Info($"Generated code for {tool.Name} from {Path.GetFileName(tool.SpecificationFile) ?? "<in-memory>"}.");
}

// ReSharper disable once CyclomaticComplexity
// ReSharper disable once CognitiveComplexity
private static void ApplyRuntimeInformation(
Tool tool,
string specificationFile,
Expand Down
5 changes: 0 additions & 5 deletions source/Nuke.CodeGeneration/Generators/DataClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ private static string GetPublicPropertyType(Property property)
return property.GetNullableType();
}

private static string AssertionWithValue(string assertion, string propertyName)
{
return $"{assertion} [{propertyName} = {{{propertyName}}}]".DoubleQuoteInterpolated();
}

private static DataClassWriter WriteConfigureArguments(this DataClassWriter writer)
{
var formatProperties = writer.DataClass.Properties.Where(x => x.Format != null).ToList();
Expand Down
4 changes: 1 addition & 3 deletions source/Nuke.CodeGeneration/Generators/WriterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ string GetArgument(Property property)
var argument = valueIndex == -1
? property.Format
: valueIndex != 0
? property.Format.Substring(0, valueIndex).TrimEnd(':', '=', ' ')
? property.Format.Substring(startIndex: 0, valueIndex).TrimEnd(':', '=', ' ')
: $"&lt;{property.Name.ToInstance()}&gt;";
if (!argument.Any(char.IsLetter))
Logger.Warn($"Format for property {property.Name} in {property.DataClass.Tool.Name} is all non-letters.");
Expand All @@ -82,9 +82,7 @@ string GetArgument(Property property)
.OrderBy(x => !x.Argument.StartsWith("&lt;"))
.ThenBy(x => x.Argument);
foreach (var pair in propertiesWithArgument)
{
yield return $" <li><c>{pair.Argument}</c> via {pair.Property.ToSeeCref()}</li>";
}

yield return "</ul>";
}
Expand Down
1 change: 1 addition & 0 deletions source/Nuke.CodeGeneration/ToolSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static void Save(Tool tool, string file)

private class CustomContractResolver : CamelCasePropertyNamesContractResolver
{
// ReSharper disable once CognitiveComplexity
protected override JsonProperty CreateProperty([NotNull] MemberInfo member, MemberSerialization memberSerialization)
{
var property = base.CreateProperty(member, memberSerialization);
Expand Down
17 changes: 0 additions & 17 deletions source/Nuke.Common.Tests/CITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ private static void AssertProperty(object instance, PropertyInfo property)
Guid.TryParse(strValue, out _).Should().BeFalse("Guid");
}

private static T CreateInstance<T>()
{
return (T) CreateInstance(typeof(T));
}

private static object CreateInstance(Type type)
{
var bindingFlags = BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.OptionalParamBinding;
Expand All @@ -141,17 +136,5 @@ public CITheoryAttribute(Type type)

public override string Skip => !IsRunning(_type) ? $"Only applies to {_type.Name}." : null;
}

private class BuildServerFactAttribute : FactAttribute
{
private readonly Type _type;

public BuildServerFactAttribute(Type type)
{
_type = type;
}

public override string Skip => !IsRunning(_type) ? $"Only applies to {_type.Name}." : null;
}
}
}
12 changes: 1 addition & 11 deletions source/Nuke.Common.Tests/Execution/BuildExecutorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void TestDynamicCondition()

private void ExecuteBuild(ExecutableTarget[] skippedTargets = null)
{
string[] SelectNames(ExecutableTarget[] targets) => targets?.Select(x => x.Name).ToArray();
static string[] SelectNames(ExecutableTarget[] targets) => targets?.Select(x => x.Name).ToArray();

var build = new TestBuild();
build.ExecutableTargets = new[] { A, B, C };
Expand All @@ -115,16 +115,6 @@ private static void AssertSkipped(params ExecutableTarget[] targets)
targets.ForEach(x => x.Status.Should().Be(ExecutionStatus.Skipped));
}

private static void AssertUnscheduled(params ExecutableTarget[] targets)
{
targets.ForEach(x => x.Status.Should().BeNull());
}

private static void AssertNotRun(params ExecutableTarget[] targets)
{
targets.ForEach(x => x.Status.Should().Be(ExecutionStatus.NotRun));
}

private class TestBuild : NukeBuild
{
}
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common.Tests/Execution/ExecutionPlannerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void TestMixedDependencies()

private IEnumerable<ExecutableTarget> GetPlan(ExecutableTarget[] invokedTargets = null)
{
string[] SelectNames(ExecutableTarget[] targets) => targets?.Select(x => x.Name).ToArray();
static string[] SelectNames(ExecutableTarget[] targets) => targets?.Select(x => x.Name).ToArray();

return ExecutionPlanner.GetExecutionPlan(new[] { A, B, C }, SelectNames(invokedTargets));
}
Expand Down
1 change: 0 additions & 1 deletion source/Nuke.Common.Tests/ProjectModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Xunit;
using static Nuke.Common.IO.PathConstruction;

namespace Nuke.Common.Tests
{
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common.Tests/SerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static IEnumerable<object[]> Serializers
[UsedImplicitly]
get
{
object[] GetSerialization(string name, Func<Data, Data> serialization) => new object[] { name, serialization };
static object[] GetSerialization(string name, Func<Data, Data> serialization) => new object[] { name, serialization };

yield return GetSerialization("Json", x => SerializationTasks.JsonDeserialize<Data>(SerializationTasks.JsonSerialize(x)));
yield return GetSerialization("Yaml", x => SerializationTasks.YamlDeserialize<Data>(SerializationTasks.YamlSerialize(x)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Nuke.Common.Tooling;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.IO.PathConstruction;

namespace Nuke.Common.CI.GitHubActions
{
Expand Down Expand Up @@ -122,7 +121,7 @@ private IEnumerable<GitHubActionsStep> GetSteps(GitHubActionsImage image, IReadO

protected virtual IEnumerable<(string key, string value)> GetImports()
{
string GetSecretValue(string secret) => $"${{{{ secrets.{secret} }}}}";
static string GetSecretValue(string secret) => $"${{{{ secrets.{secret} }}}}";

if (ImportGitHubTokenAs != null)
yield return (ImportGitHubTokenAs, GetSecretValue("GITHUB_TOKEN"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TeamCitySnapshotDependency : TeamCityDependency

public override void Write(CustomFileWriter writer)
{
string FormatAction(TeamCityDependencyFailureAction action)
static string FormatAction(TeamCityDependencyFailureAction action)
=> "FailureAction." +
action.ToString().SplitCamelHumpsWithSeparator("_").ToUpperInvariant();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Linq;
using Microsoft.Azure.KeyVault.Models;
using Nuke.Common.Utilities;

namespace Nuke.Common.CI.TeamCity.Configuration
Expand Down
1 change: 0 additions & 1 deletion source/Nuke.Common/CI/TeamCity/TeamCityAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using JetBrains.Annotations;
using Nuke.Common.CI.TeamCity.Configuration;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand Down
6 changes: 3 additions & 3 deletions source/Nuke.Common/ChangeLog/ChangeLogTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ public static IEnumerable<string> ExtractChangelogSectionNotes(string changelogF

private static IEnumerable<ReleaseSection> GetReleaseSections(List<string> content)
{
bool IsReleaseHead(string str)
static bool IsReleaseHead(string str)
=> str.StartsWith("## ");

bool IsReleaseContent(string str)
static bool IsReleaseContent(string str)
=> str.StartsWith("###") || str.Trim().StartsWith("-");

string GetCaption(string str)
static string GetCaption(string str)
=> str
.TrimStart('#', ' ', '[')
.Split(' ')
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/Execution/BuildExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void TryMarkTargetSkipped(ExecutableTarget target)
private static bool HasSkippingCondition(ExecutableTarget target, IEnumerable<Expression<Func<bool>>> conditions)
{
// TODO: trim outer parenthesis
string GetSkipReason(Expression<Func<bool>> condition) =>
static string GetSkipReason(Expression<Func<bool>> condition) =>
condition.Body.ToString()
.Replace("False", "false")
.Replace("True", "true")
Expand Down
8 changes: 3 additions & 5 deletions source/Nuke.Common/Execution/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using Nuke.Common.OutputSinks;
using Nuke.Common.Tooling;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;
Expand All @@ -18,7 +16,7 @@ namespace Nuke.Common.Execution
{
internal static class BuildManager
{
private const int c_errorExitCode = -1;
private const int ErrorExitCode = -1;

private static readonly LinkedList<Action> s_cancellationHandlers = new LinkedList<Action>();

Expand Down Expand Up @@ -85,14 +83,14 @@ void ExecuteExtension<TExtension>(Action<TExtension> action)
build,
EnvironmentInfo.GetParameter<string[]>(() => build.SkippedTargets));

return build.IsSuccessful ? 0 : c_errorExitCode;
return build.IsSuccessful ? 0 : ErrorExitCode;
}
catch (Exception exception)
{
if (!(exception is TargetExecutionException))
Logger.Error(exception);

return c_errorExitCode;
return ErrorExitCode;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CheckBuildProjectConfigurationsAttribute : Attribute, IOnAfterLogo
ControlFlow.AssertWarn(Task.Run(CheckConfiguration).Wait(TimeoutInMilliseconds),
$"Could not complete checking build configurations within {TimeoutInMilliseconds} milliseconds.");

Task CheckConfiguration()
static Task CheckConfiguration()
{
var rootDirectory = new DirectoryInfo(NukeBuild.RootDirectory);
new[] { rootDirectory }
Expand Down
8 changes: 4 additions & 4 deletions source/Nuke.Common/Execution/ExecutionPlanHtmlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ namespace Nuke.Common.Execution
{
internal class ExecutionPlanHtmlService
{
private const string c_htmlFileName = "execution-plan.html";
private const string HtmlFileName = "execution-plan.html";

public static void ShowPlan(IReadOnlyCollection<ExecutableTarget> executableTargets)
{
var resourceText = ResourceUtility.GetResourceAllText<ExecutionPlanHtmlService>(c_htmlFileName);
var resourceText = ResourceUtility.GetResourceAllText<ExecutionPlanHtmlService>(HtmlFileName);
var contents = resourceText
.Replace("__GRAPH__", GetGraphDefinition(executableTargets))
.Replace("__EVENTS__", GetEvents(executableTargets));

var path = Path.Combine(NukeBuild.TemporaryDirectory, c_htmlFileName);
var path = Path.Combine(NukeBuild.TemporaryDirectory, HtmlFileName);
File.WriteAllText(path, contents);

// Workaround for https://github.com/dotnet/corefx/issues/10361
Expand Down Expand Up @@ -67,7 +67,7 @@ private static string GetEvents(IReadOnlyCollection<ExecutableTarget> executable
// When not hovering anything, highlight the default plan
var defaultTarget = executableTargets.SingleOrDefault(x => x.IsDefault);
var defaultPlan = defaultTarget != null
? ExecutionPlanner.GetExecutionPlan(executableTargets, new[] { defaultTarget?.Name })
? ExecutionPlanner.GetExecutionPlan(executableTargets, new[] { defaultTarget.Name })
: new ExecutableTarget[0];
defaultPlan.ForEach(x => builder.AppendLine($@" $(""#{x.Name}"").addClass('highlight');"));

Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/Execution/ParameterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static IEnumerable<(string Text, object Object)> GetParameterValueSet(Mem
{
var enumType = memberType.IsEnum
? memberType
: Nullable.GetUnderlyingType(memberType) is Type underlyingType && underlyingType.IsEnum
: Nullable.GetUnderlyingType(memberType) is { } underlyingType && underlyingType.IsEnum
? underlyingType
: null;
return enumType != null
Expand Down
8 changes: 4 additions & 4 deletions source/Nuke.Common/Execution/TargetDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ internal class TargetDefinition : ITargetDefinition
internal bool IsProceedAfterFailure { get; private set; }
internal bool IsAssuredAfterFailure { get; private set; }
internal bool IsInternal { get; private set; }
internal List<Target> BeforeTargets { get; private set; } = new List<Target>();
internal List<Target> AfterTargets { get; private set; } = new List<Target>();
internal List<Target> TriggersTargets { get; private set; } = new List<Target>();
internal List<Target> TriggeredByTargets { get; private set; } = new List<Target>();
internal List<Target> BeforeTargets { get; } = new List<Target>();
internal List<Target> AfterTargets { get; } = new List<Target>();
internal List<Target> TriggersTargets { get; } = new List<Target>();
internal List<Target> TriggeredByTargets { get; } = new List<Target>();

ITargetDefinition ITargetDefinition.Description(string description)
{
Expand Down
4 changes: 2 additions & 2 deletions source/Nuke.Common/Execution/Vertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public Vertex(T value, IEnumerable<Vertex<T>> dependencies)

internal int LowLink { get; set; }

public T Value { get; set; }
public T Value { get; }

public ICollection<Vertex<T>> Dependencies { get; set; }
public ICollection<Vertex<T>> Dependencies { get; }
}
}
2 changes: 0 additions & 2 deletions source/Nuke.Common/Git/GitRepositoryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
// https://github.com/nuke-build/nuke/blob/master/LICENSE

using System;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Nuke.Common.IO;
using Nuke.Common.Utilities;

namespace Nuke.Common.Git
Expand Down
5 changes: 5 additions & 0 deletions source/Nuke.Common/IO/FileSystemGlobbingAttributeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using Nuke.Common.Execution;
using Nuke.Common.Utilities;
using Nuke.Common.Utilities.Collections;

namespace Nuke.Common.IO
{
// TODO: document
[PublicAPI]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class FileGlobbingAttribute : FileSystemGlobbingAttributeBase
{
Expand All @@ -21,6 +24,8 @@ public FileGlobbingAttribute(params string[] patterns)
}
}

// TODO: document
[PublicAPI]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class DirectoryGlobbingAttribute : FileSystemGlobbingAttributeBase
{
Expand Down
2 changes: 1 addition & 1 deletion source/Nuke.Common/IO/FileSystemTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private static bool ShouldCopyFile(string sourceFile, string targetFile, FileExi
FileExistsPolicy.Fail => throw new Exception($"File '{targetFile}' already exists."),
FileExistsPolicy.Skip => false,
FileExistsPolicy.Overwrite => true,
FileExistsPolicy.OverwriteIfNewer => (File.GetLastWriteTimeUtc(targetFile) < File.GetLastWriteTimeUtc(sourceFile)),
FileExistsPolicy.OverwriteIfNewer => File.GetLastWriteTimeUtc(targetFile) < File.GetLastWriteTimeUtc(sourceFile),
_ => throw new ArgumentOutOfRangeException(nameof(policy), policy, message: null)
};
}
Expand Down

0 comments on commit 8c26d94

Please sign in to comment.