Skip to content

Commit 30eca5f

Browse files
committed
Fix: Quick code cleanup
1 parent ce25222 commit 30eca5f

File tree

17 files changed

+54
-54
lines changed

17 files changed

+54
-54
lines changed

src/CodeOfChaos.CliArgsParser.Generators.Sample/Example.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task ExecuteAsync(CommandParameters parameters) {
4343
}
4444

4545
// Simulate some asynchronous work
46-
await Task.Delay(100);// Example of an asynchronous operation
46+
await Task.Delay(100); // Example of an asynchronous operation
4747

4848
Console.WriteLine("Command executed successfully.");
4949
}

src/CodeOfChaos.CliArgsParser.Generators/CodeOfChaos.CliArgsParser.Generators.csproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
<PackageReadmeFile>README.md</PackageReadmeFile>
2525
<PackageIcon>icon.png</PackageIcon>
2626
</PropertyGroup>
27-
27+
2828
<ItemGroup>
29-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
30-
<None Include="..\..\README.md" Pack="true" PackagePath="" />
31-
<None Include="../../assets/icon.png" Pack="true" PackagePath="" />
29+
<None Include="..\..\LICENSE" Pack="true" PackagePath=""/>
30+
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
31+
<None Include="../../assets/icon.png" Pack="true" PackagePath=""/>
3232
</ItemGroup>
33-
33+
3434
<ItemGroup>
3535
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
3636
<PrivateAssets>all</PrivateAssets>
3737
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3838
</PackageReference>
39-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0" />
40-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
39+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.12.0"/>
40+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
4141
</ItemGroup>
4242
<ItemGroup>
43-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
43+
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
4444
</ItemGroup>
4545
</Project>

src/CodeOfChaos.CliArgsParser.Generators/Content/CommandGenerator/ClassDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ClassDto(ISymbol symbol, ClassDeclarationSyntax syntax) {
2727

2828
private string CommandName =>
2929
_commandNameAttribute?.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString()
30-
?? ClassName.Replace("Command", "").ToLowerInvariant();// Maybe create a ToKebabCase method?
30+
?? ClassName.Replace("Command", "").ToLowerInvariant(); // Maybe create a ToKebabCase method?
3131

3232
private string Description => _descriptionAttribute?.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString() ?? string.Empty;
3333

src/CodeOfChaos.CliArgsParser.Library/CodeOfChaos.CliArgsParser.Library.csproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121
<PackageReadmeFile>README.md</PackageReadmeFile>
2222
<PackageIcon>icon.png</PackageIcon>
2323
</PropertyGroup>
24-
24+
2525
<ItemGroup>
26-
<None Include="..\..\LICENSE" Pack="true" PackagePath="" />
27-
<None Include="..\..\README.md" Pack="true" PackagePath="" />
28-
<None Include="..\..\assets/icon.png" Pack="true" PackagePath="" />
26+
<None Include="..\..\LICENSE" Pack="true" PackagePath=""/>
27+
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
28+
<None Include="..\..\assets/icon.png" Pack="true" PackagePath=""/>
2929
</ItemGroup>
30-
30+
3131
<ItemGroup>
32-
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
33-
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj" />
32+
<ProjectReference Include="..\CodeOfChaos.CliArgsParser.Generators\CodeOfChaos.CliArgsParser.Generators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
33+
<ProjectReference Include="..\CodeOfChaos.CliArgsParser\CodeOfChaos.CliArgsParser.csproj"/>
3434
</ItemGroup>
35-
35+
3636
<ItemGroup>
37-
<PackageReference Include="AterraEngine.Unions" Version="2.5.0" />
38-
<PackageReference Include="CodeOfChaos.Ansi" Version="0.1.7" />
37+
<PackageReference Include="AterraEngine.Unions" Version="2.5.0"/>
38+
<PackageReference Include="CodeOfChaos.Ansi" Version="0.1.7"/>
3939
</ItemGroup>
4040
</Project>

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/DownloadIcon/DownloadIconCommand.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.DownloadIcon;
1616
[CliArgsDescription("Downloads and assigns the icon, to be used as nuget package's icon, for the specified project.")]
1717
public partial class DownloadIconCommand : ICommand<DownloadIconParameters> {
1818

19+
[GeneratedRegex(@"^[^/\\\s]+$")]
20+
private static partial Regex IsEmptyFolderNameRegex { get; }
21+
1922
// -----------------------------------------------------------------------------------------------------------------
2023
// Methods
2124
// -----------------------------------------------------------------------------------------------------------------
@@ -25,7 +28,7 @@ public async Task ExecuteAsync(DownloadIconParameters parameters) {
2528
if (getResult is { IsFailure: true, AsFailure.Value: var getError }) {
2629
Console.WriteLine(getError);
2730
}
28-
31+
2932
Console.WriteLine("Icon downloaded successfully.");
3033
SuccessOrFailure applyResult = await ApplyIcon(parameters);
3134
if (applyResult is { IsFailure: true, AsFailure.Value: var applyError }) {
@@ -41,7 +44,7 @@ private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters arg
4144
}
4245

4346
await foreach (XDocument document in CsProjHelpers.GetProjectFiles(projectFiles)) {
44-
47+
4548
// Loop through each project file's XML document
4649
foreach (XElement propertyGroup in document.Root?.Elements("PropertyGroup")!) {
4750
XElement? iconElement = propertyGroup.Element("PackageIcon");
@@ -55,7 +58,7 @@ private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters arg
5558
// Update the value to ensure it's "icon.png"
5659
iconElement.Value = "icon.png";
5760
}
58-
61+
5962
// Look for ItemGroup containing Packable items
6063
XElement? packableItemGroup = document.Root?
6164
.Elements("ItemGroup")
@@ -76,11 +79,11 @@ private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters arg
7679

7780
IEnumerable<string> indents = Enumerable.Repeat(
7881
"../",
79-
1
82+
1
8083
+ (IsEmptyFolderNameRegex.IsMatch(args.SourceFolder) ? 1 : 0)
8184
+ args.SourceFolder.Count(c => c is '/' or '\\')
8285
);
83-
string includeString = Path.Combine(string.Join(string.Empty,indents),args.IconFolder, "icon.png");
86+
string includeString = Path.Combine(string.Join(string.Empty, indents), args.IconFolder, "icon.png");
8487

8588
// Add the icon.png reference if it doesn't exist
8689
var newIconElement = new XElement("None",
@@ -90,7 +93,7 @@ private static async Task<SuccessOrFailure> ApplyIcon(DownloadIconParameters arg
9093
packableItemGroup.Add(newIconElement);
9194
}
9295
}
93-
96+
9497
return new Success();
9598
}
9699

@@ -139,10 +142,7 @@ private static async Task<SuccessOrFailure> TryGetIcon(DownloadIconParameters pa
139142
}
140143
catch (Exception ex) {
141144
// Return any unexpected errors
142-
return$"Unexpected error: {ex.Message}";
145+
return $"Unexpected error: {ex.Message}";
143146
}
144147
}
145-
146-
[GeneratedRegex(@"^[^/\\\s]+$")]
147-
private static partial Regex IsEmptyFolderNameRegex { get; }
148148
}

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/VersionBump/VersionBumpCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static async Task<SuccessOrFailure<SemanticVersionDto>> BumpVersion(Vers
7373
.FirstOrDefault();
7474

7575
if (versionElement == null) {
76-
return new Failure<string>($"File did not contain a version element");
76+
return new Failure<string>("File did not contain a version element");
7777
}
7878

7979
if (versionDto is null) {

src/CodeOfChaos.CliArgsParser.Library/CommandAtlases/VersionBump/VersionBumpParameters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace CodeOfChaos.CliArgsParser.Library.CommandAtlases.VersionBump;
1414

1515
[CliArgsParameter("section", "s")] [CliArgsDescription("The section of the version to bump. One of: Major, Minor, Patch")]
1616
public required string? SectionStringValue { get; init; }
17+
1718
public VersionSection Section => Enum.Parse<VersionSection>(SectionStringValue ?? "None", true);
1819

1920
[CliArgsParameter("push", "p", ParameterType.Flag)] [CliArgsDescription("Push the changes to the remote repository")]

src/CodeOfChaos.CliArgsParser.Library/Shared/CsProjHelpers.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
using System.Xml.Linq;
66

77
namespace CodeOfChaos.CliArgsParser.Library.Shared;
8-
98
// ---------------------------------------------------------------------------------------------------------------------
109
// Code
1110
// ---------------------------------------------------------------------------------------------------------------------
1211
public static class CsProjHelpers {
1312
public static string[] AsProjectPaths(string root, string sourcefolder, string[] projectNames) {
1413
return projectNames.Select(x => Path.Combine(root, sourcefolder, x, x + ".csproj")).ToArray();
1514
}
16-
15+
1716
public static async IAsyncEnumerable<XDocument> GetProjectFiles(string[] projectPaths) {
1817
var settings = new XmlWriterSettings {
1918
Indent = true,
@@ -22,7 +21,7 @@ public static async IAsyncEnumerable<XDocument> GetProjectFiles(string[] project
2221
OmitXmlDeclaration = true,
2322
NewLineOnAttributes = false // Keeps attributes on the same line
2423
};
25-
24+
2625
foreach (string path in projectPaths) {
2726
if (!File.Exists(path)) {
2827
throw new FileNotFoundException($"Could not find project file {path}");
@@ -33,9 +32,9 @@ public static async IAsyncEnumerable<XDocument> GetProjectFiles(string[] project
3332
await using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)) {
3433
document = await XDocument.LoadAsync(stream, LoadOptions.PreserveWhitespace, CancellationToken.None);
3534
}
36-
35+
3736
yield return document;
38-
37+
3938
// Save using XmlWriter to apply consistent indentation, but preserve empty lines
4039
await using (var stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true)) {
4140
await using var writer = XmlWriter.Create(stream, settings);

src/CodeOfChaos.CliArgsParser.Library/Shared/GitHelpers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Diagnostics;
77

88
namespace CodeOfChaos.CliArgsParser.Library.Shared;
9-
109
// ---------------------------------------------------------------------------------------------------------------------
1110
// Code
1211
// ---------------------------------------------------------------------------------------------------------------------

src/CodeOfChaos.CliArgsParser/Attributes/CliArgsCommandAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ namespace CodeOfChaos.CliArgsParser.Attributes;
66
// Code
77
// ---------------------------------------------------------------------------------------------------------------------
88
[AttributeUsage(AttributeTargets.Class)]
9-
#pragma warning disable CS9113// Parameter is unread.
9+
#pragma warning disable CS9113 // Parameter is unread.
1010
public class CliArgsCommandAttribute(string name) : Attribute;
11-
#pragma warning restore CS9113// Parameter is unread.
11+
#pragma warning restore CS9113 // Parameter is unread.

0 commit comments

Comments
 (0)