Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

build(deps-dev): bump vsce from 1.100.1 to 2.15.0 in /src/projektanker.code-butler #28

33 changes: 33 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2
updates:
- package-ecosystem: "nuget"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
commit-message:
prefix: "build"
include: "scope"
groups:
xunit:
patterns:
- "xunit*"
- package-ecosystem: "npm"
directory: "src/projektanker.code-butler"
schedule:
interval: "weekly"
labels:
- "dependencies"
commit-message:
prefix: "build"
include: "scope"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "dependencies"
commit-message:
prefix: "build"
include: "scope"
21 changes: 8 additions & 13 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ jobs:
uses: actions/checkout@v3

- name: 🟣 Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
uses: actions/setup-dotnet@v4

- name: 🛠️ Build
run: dotnet build

- name: ✔ Test
run: dotnet test --verbosity normal
run: dotnet test --no-build --verbosity normal

- name: 📯 Publish
run: dotnet publish ./CodeButler.Console/CodeButler.Console.csproj --output ./publish
Expand All @@ -50,9 +51,7 @@ jobs:
uses: actions/setup-node@v3

- name: 🟣 Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
uses: actions/setup-dotnet@v4

- name: 🛠 Install NPM packages
run: npm ci
Expand Down Expand Up @@ -83,9 +82,7 @@ jobs:
uses: actions/setup-node@v3

- name: 🟣 Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
uses: actions/setup-dotnet@v4

- name: 🛠 Install NPM packages
run: npm ci
Expand All @@ -110,9 +107,7 @@ jobs:
uses: actions/setup-node@v3

- name: 🟣 Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
uses: actions/setup-dotnet@v4

- name: 🛠 Install NPM packages
run: npm ci
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestFeature"
}
}
19 changes: 16 additions & 3 deletions src/CodeButler/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ dotnet_diagnostic.IDE0072.severity = suggestion
# SA0001: XML comment analysis is disabled due to project configuration
dotnet_diagnostic.SA0001.severity = none

# SA1000: The keyword 'new' should be followed by a space
dotnet_diagnostic.SA1000.severity = none

# SA1009: Closing parenthesis must be spaced correctly
dotnet_diagnostic.SA1009.severity = silent

# SA1101: Prefix local calls with this
dotnet_diagnostic.SA1101.severity = none

# SA1111: Closing parenthesis must be on line of last parameter
dotnet_diagnostic.SA1111.severity = silent

# SA1123: Region should not be located within a code element
dotnet_diagnostic.SA1123.severity = suggestion

Expand Down Expand Up @@ -93,18 +102,22 @@ dotnet_naming_symbols.private_constant.required_modifiers = const
dotnet_naming_style.underscore_camel_case.required_prefix = _
dotnet_naming_style.underscore_camel_case.capitalization = camel_case

#upper_case
# upper_case
dotnet_naming_style.upper_case.capitalization = all_upper
dotnet_naming_style.upper_case.word_separator = _

#.NET naming rule:
#private_fields_underscore_camelcase
# private_fields_underscore_camelcase
dotnet_naming_rule.private_fields_underscore_camelcase.symbols = private_field
dotnet_naming_rule.private_fields_underscore_camelcase.style = underscore_camel_case
dotnet_naming_rule.private_fields_underscore_camelcase.severity = suggestion

#private_constants_upper_case
# private_constants_upper_case
dotnet_naming_rule.private_constants_upper_case.symbols = private_field
dotnet_naming_rule.private_constants_upper_case.style = underscore_camel_case
dotnet_naming_rule.private_constants_upper_case.severity = suggestion

# Enforce file-scoped namespace
csharp_style_namespace_declarations = file_scoped:error
dotnet_diagnostic.IDE0161.severity = error

9 changes: 5 additions & 4 deletions src/CodeButler/CodeButler.Console/CodeButler.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CodeButler</RootNamespace>
<Nullable>enable</Nullable>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Version>2.2.1</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.5.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions src/CodeButler/CodeButler.Console/InputOutputMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace CodeButler;

public enum InputOutputMode
{
Console,
File,
}
8 changes: 0 additions & 8 deletions src/CodeButler/CodeButler.Console/Mode.cs

This file was deleted.

32 changes: 18 additions & 14 deletions src/CodeButler/CodeButler.Console/Padding/PaddingCleaner.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
using System.Linq;
using System.Text.RegularExpressions;
using System.Text.RegularExpressions;

namespace CodeButler.Padding
namespace CodeButler.Padding;

public partial class PaddingCleaner
{
public class PaddingCleaner
{
private static readonly Regex _dirtyNewLine = new Regex(@"[\t ]+(\r\n|\n)", RegexOptions.Multiline);
private static readonly Regex _multiEmptyLine = new Regex(@"^(\r\n|\n)+", RegexOptions.Multiline);
private static readonly Regex _dirtyNewLine = GenerateDirtyNewLineRegex();
private static readonly Regex _multiEmptyLine = GenerateMultiEmptyLineRegex();

public string Clean(string input)
{
string output = _dirtyNewLine.Replace(input, match => match.Groups.Values.Last().Value);
output = _multiEmptyLine.Replace(output, match => match.Groups.Values.Last().Value);
return output;
}
public virtual string Clean(string input)
{
string output = _dirtyNewLine.Replace(input, match => match.Groups[^1].Value);
output = _multiEmptyLine.Replace(output, match => match.Groups[^1].Value);
return output;
}
}

[GeneratedRegex(@"[\t ]+(\r\n|\n)", RegexOptions.Multiline)]
private static partial Regex GenerateDirtyNewLineRegex();

[GeneratedRegex(@"^(\r\n|\n)+", RegexOptions.Multiline)]
private static partial Regex GenerateMultiEmptyLineRegex();
}
116 changes: 38 additions & 78 deletions src/CodeButler/CodeButler.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,88 +1,48 @@
using System;
using System.CommandLine;
using System.IO;
using System.Threading.Tasks;
using CodeButler.Padding;
using CodeButler.Syntax;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace CodeButler
namespace CodeButler;

public class Program
{
public class Program
public static async Task<int> Main(string[] args)
{
public static async Task<int> Main(string[] args)
{
Mode mode;
if (Console.IsInputRedirected)
{
mode = Mode.Console;
}
else if (args.Length > 0)
{
mode = Mode.File;
}
else
{
Console.Error.WriteLine("No input provided.");
return -1;
}

string input = await GetInput(mode, args).ConfigureAwait(false);
CompilationUnitSyntax root = Parse(input);
var organizedRoot = Reorganize(root);

await SetOutput(organizedRoot, mode, args).ConfigureAwait(false);
return 0;
}
var rootCommand = new RootCommand("Reorganises, sorts and cleans up the provided C# file.");

public static CompilationUnitSyntax Parse(string input)
{
var paddingCleaner = new PaddingCleaner();
string cleanInput = paddingCleaner.Clean(input);
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(cleanInput);
CompilationUnitSyntax root = syntaxTree.GetCompilationUnitRoot();
return root;
}

public static CompilationUnitSyntax Reorganize(CompilationUnitSyntax compilationUnit)
{
return compilationUnit.Reorganize();
}
var noSortMemberByAlphabetOption = new Option<bool>(
name: "--no-sort-member-by-alphabet",
description: "Disables sorting members by alphabet.",
getDefaultValue: () => false
);

private static async Task<string> GetInput(Mode mode, string[] args)
var inputFileArgMeta = new
{
switch (mode)
{
case Mode.Console:
using (var reader = new StreamReader(Console.OpenStandardInput(), Console.InputEncoding))
{
return await reader.ReadToEndAsync().ConfigureAwait(false);
}

case Mode.File:
return await File.ReadAllTextAsync(args[0]).ConfigureAwait(false);

default:
throw new NotImplementedException($"Mode \"{mode}\" not implemented.");
}
}

private static async Task SetOutput(CompilationUnitSyntax compilationUnit, Mode mode, string[] args)
{
switch (mode)
{
case Mode.Console:
Console.Write(compilationUnit.ToFullString());
break;

case Mode.File:
await File.WriteAllTextAsync(args[0], compilationUnit.ToFullString()).ConfigureAwait(false);
break;

default:
throw new NotImplementedException($"Mode \"{mode}\" not implemented.");
}
}
Name = "input",
Description = "Path to input file or piped input."
};

var inputFileArg = Console.IsInputRedirected
? new Argument<FileInfo?>(
name: inputFileArgMeta.Name,
description: inputFileArgMeta.Description,
getDefaultValue: () => null
)
: new Argument<FileInfo?>(
name: inputFileArgMeta.Name,
description: inputFileArgMeta.Description
);

rootCommand.AddOption(noSortMemberByAlphabetOption);
rootCommand.AddArgument(inputFileArg);

rootCommand.SetHandler(
RootCommandHandler.Handle,
new RootCommandConfigurationBinder(noSortMemberByAlphabetOption, inputFileArg)
);

var exitCode = await rootCommand.InvokeAsync(args);
return exitCode;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"profiles": {
"CodeButler.Console": {
"commandName": "Project",
"commandLineArgs": "TypeDefaultOrder.cs"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
namespace CodeButler.Reorganizing
namespace CodeButler.Reorganizing;

public enum MemberAccessModifier
{
public enum MemberAccessModifier
{
Public,
Internal,
Protected,
ProtectedInternal,
PrivateProtected,
Private,
None,
}
}
Public,
Internal,
Protected,
ProtectedInternal,
PrivateProtected,
Private,
None,
}
Loading
Loading