Skip to content

Commit

Permalink
cleanup after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Dec 26, 2024
1 parent ee07a7d commit 32a343f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 70 deletions.
27 changes: 8 additions & 19 deletions Src/CSharpier.Cli/EditorConfig/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
29 changes: 0 additions & 29 deletions Src/CSharpier.Playground/Controllers/FormatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ public class FormatError
[Route("[controller]")]
public class FormatController : ControllerBase
{
private readonly ILogger logger;

public FormatController(ILogger<FormatController> logger)
{
this.logger = logger;
}

public class PostModel
{
public string Code { get; set; } = string.Empty;
Expand Down Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions Src/CSharpier/CodeFormatterResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Diagnostic> CompilationErrors { get; internal init; } =
Enumerable.Empty<Diagnostic>();
public IEnumerable<Diagnostic> CompilationErrors { get; internal init; } = [];

internal string FailureMessage { get; init; } = string.Empty;

Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier/Formatters/Xml/XNodePrinters/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 1 addition & 4 deletions Src/SyntaxFinder/Walkers/ModifiersWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
10 changes: 2 additions & 8 deletions Src/SyntaxFinder/Walkers/ObjectInitializerWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> matchingFiles = new();

public ObjectInitializerWalker(string file)
{
this.file = file;
}

public override void VisitInitializerExpression(InitializerExpressionSyntax node)
{
if (node.Kind() is SyntaxKind.ObjectInitializerExpression)
Expand All @@ -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
);
}
}
Expand Down
9 changes: 2 additions & 7 deletions Src/SyntaxFinder/Walkers/SpreadWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 32a343f

Please sign in to comment.