diff --git a/Src/CSharpier.Cli/EditorConfig/Section.cs b/Src/CSharpier.Cli/EditorConfig/Section.cs index 51189760d..96017dff3 100644 --- a/Src/CSharpier.Cli/EditorConfig/Section.cs +++ b/Src/CSharpier.Cli/EditorConfig/Section.cs @@ -2,27 +2,16 @@ namespace CSharpier.Cli.EditorConfig; -internal class Section +internal class Section(SectionData section, string directory) { - private readonly GlobMatcher matcher; + private readonly GlobMatcher matcher = Globber.Create(section.SectionName, directory); - public string? IndentStyle { get; } - public string? IndentSize { get; } - public string? TabWidth { get; } - public string? MaxLineLength { get; } - public string? EndOfLine { get; } - public string? Formatter { get; } - - public Section(SectionData section, string directory) - { - this.matcher = Globber.Create(section.SectionName, directory); - this.IndentStyle = section.Keys["indent_style"]; - this.IndentSize = section.Keys["indent_size"]; - this.TabWidth = section.Keys["tab_width"]; - this.MaxLineLength = section.Keys["max_line_length"]; - this.EndOfLine = section.Keys["end_of_line"]; - this.Formatter = section.Keys["csharpier_formatter"]; - } + public string? IndentStyle { get; } = section.Keys["indent_style"]; + public string? IndentSize { get; } = section.Keys["indent_size"]; + public string? TabWidth { get; } = section.Keys["tab_width"]; + public string? MaxLineLength { get; } = section.Keys["max_line_length"]; + public string? EndOfLine { get; } = section.Keys["end_of_line"]; + public string? Formatter { get; } = section.Keys["csharpier_formatter"]; public bool IsMatch(string fileName) { diff --git a/Src/CSharpier.Playground/Controllers/FormatController.cs b/Src/CSharpier.Playground/Controllers/FormatController.cs index bc551ad97..f5df059aa 100644 --- a/Src/CSharpier.Playground/Controllers/FormatController.cs +++ b/Src/CSharpier.Playground/Controllers/FormatController.cs @@ -23,13 +23,6 @@ public class FormatError [Route("[controller]")] public class FormatController : ControllerBase { - private readonly ILogger logger; - - public FormatController(ILogger logger) - { - this.logger = logger; - } - public class PostModel { public string Code { get; set; } = string.Empty; @@ -89,26 +82,4 @@ private FormatError ConvertError(Diagnostic diagnostic) var lineSpan = diagnostic.Location.SourceTree!.GetLineSpan(diagnostic.Location.SourceSpan); return new FormatError { LineSpan = lineSpan, Description = diagnostic.ToString() }; } - - public string ExecuteApplication(string pathToExe, string workingDirectory, string args) - { - var processStartInfo = new ProcessStartInfo(pathToExe, args) - { - UseShellExecute = false, - RedirectStandardError = true, - WindowStyle = ProcessWindowStyle.Hidden, - WorkingDirectory = workingDirectory, - CreateNoWindow = true, - }; - - var process = Process.Start(processStartInfo); - var output = process!.StandardError.ReadToEnd(); - process.WaitForExit(); - - this.logger.LogInformation( - "Output from '" + pathToExe + " " + args + "' was: " + Environment.NewLine + output - ); - - return output; - } } diff --git a/Src/CSharpier/CodeFormatterResult.cs b/Src/CSharpier/CodeFormatterResult.cs index d8eab98ab..4123f9889 100644 --- a/Src/CSharpier/CodeFormatterResult.cs +++ b/Src/CSharpier/CodeFormatterResult.cs @@ -8,8 +8,7 @@ internal CodeFormatterResult() { } internal string DocTree { get; init; } = string.Empty; internal string AST { get; init; } = string.Empty; internal string WarningMessage { get; init; } = string.Empty; - public IEnumerable CompilationErrors { get; internal init; } = - Enumerable.Empty(); + public IEnumerable CompilationErrors { get; internal init; } = []; internal string FailureMessage { get; init; } = string.Empty; diff --git a/Src/CSharpier/Formatters/Xml/XNodePrinters/Element.cs b/Src/CSharpier/Formatters/Xml/XNodePrinters/Element.cs index d037b2dd1..4ac3d2f8c 100644 --- a/Src/CSharpier/Formatters/Xml/XNodePrinters/Element.cs +++ b/Src/CSharpier/Formatters/Xml/XNodePrinters/Element.cs @@ -70,6 +70,6 @@ private static bool ForceBreakContent(XElement node) { var childNode = node.Nodes().Count() == 1 ? node.Nodes().First() : null; - return childNode is not null && childNode is XCData or not XText; + return childNode is not null and (XCData or not XText); } } diff --git a/Src/SyntaxFinder/Walkers/ModifiersWalker.cs b/Src/SyntaxFinder/Walkers/ModifiersWalker.cs index a7ab5f0ba..bfd1da43e 100644 --- a/Src/SyntaxFinder/Walkers/ModifiersWalker.cs +++ b/Src/SyntaxFinder/Walkers/ModifiersWalker.cs @@ -2,11 +2,8 @@ namespace SyntaxFinder.Walkers; -public class ModifiersWalker : SyntaxFinderWalker +public class ModifiersWalker(string file) : SyntaxFinderWalker(file) { - public ModifiersWalker(string file) - : base(file) { } - public override void VisitParenthesizedLambdaExpression( ParenthesizedLambdaExpressionSyntax node ) diff --git a/Src/SyntaxFinder/Walkers/ObjectInitializerWalker.cs b/Src/SyntaxFinder/Walkers/ObjectInitializerWalker.cs index 81194aac3..e8a7a4df8 100644 --- a/Src/SyntaxFinder/Walkers/ObjectInitializerWalker.cs +++ b/Src/SyntaxFinder/Walkers/ObjectInitializerWalker.cs @@ -3,19 +3,13 @@ namespace SyntaxFinder.Walkers; -public class ObjectInitializerWalker : CSharpSyntaxWalker +public class ObjectInitializerWalker(string file) : CSharpSyntaxWalker { private static int total; private static int matching; private static double totalExpressions; - private readonly string file; private static HashSet matchingFiles = new(); - public ObjectInitializerWalker(string file) - { - this.file = file; - } - public override void VisitInitializerExpression(InitializerExpressionSyntax node) { if (node.Kind() is SyntaxKind.ObjectInitializerExpression) @@ -40,7 +34,7 @@ private void VisitNode(InitializerExpressionSyntax node) { Interlocked.Increment(ref matching); matchingFiles.Add( - node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line + " - " + this.file + node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line + " - " + file ); } } diff --git a/Src/SyntaxFinder/Walkers/SpreadWalker.cs b/Src/SyntaxFinder/Walkers/SpreadWalker.cs index 6f2c098b3..06cf6b1db 100644 --- a/Src/SyntaxFinder/Walkers/SpreadWalker.cs +++ b/Src/SyntaxFinder/Walkers/SpreadWalker.cs @@ -3,16 +3,11 @@ namespace SyntaxFinder.Walkers; -public class SpreadWalker : CSharpSyntaxWalker +public class SpreadWalker(string file) : CSharpSyntaxWalker { private static int total; private static int matching; - private readonly string file; - - public SpreadWalker(string file) - { - this.file = file; - } + private readonly string file = file; public override void VisitSpreadElement(SpreadElementSyntax node) {