From 0f2024771572e6c687eedf1c52f8458dd39955e5 Mon Sep 17 00:00:00 2001 From: Bela VanderVoort Date: Thu, 26 Dec 2024 11:49:40 -0600 Subject: [PATCH] toss in some more analyzers --- .editorconfig | 26 ++++++++++++- Src/CSharpier.Cli/CommandLineOptions.cs | 39 +++++++------------ Src/CSharpier.Cli/ConsoleLogger.cs | 25 ++++-------- Src/CSharpier.Cli/EditorConfig/GlobMatcher.cs | 34 +++++++--------- Src/CSharpier.Cli/EditorConfig/Section.cs | 27 ++++--------- Src/CSharpier.Cli/FileIssueLogger.cs | 17 ++------ Src/CSharpier.Cli/FormattingCache.cs | 39 +++++++------------ Src/CSharpier.Cli/IgnoreFile.cs | 13 ++----- Src/CSharpier.Cli/Options/ConfigFileParser.cs | 2 +- .../PhysicalFileInfoAndWriter.cs | 9 +---- .../PipeMultipleFilesFormatter.cs | 12 +++--- Src/CSharpier.Cli/Program.cs | 4 +- .../StdOutFormattedFileWriter.cs | 11 +----- Src/CSharpier.FakeGenerators/CodeContext.cs | 9 +---- Src/CSharpier.FakeGenerators/Ignored.cs | 26 +++++-------- .../Controllers/FormatController.cs | 35 +---------------- .../Pages/Error.cshtml.cs | 7 ---- Src/CSharpier.Playground/Startup.cs | 9 +---- .../CommandLineFormatterTests.cs | 12 +++--- Src/CSharpier.Tests/DocUtilitiesTests.cs | 4 +- Src/CSharpier.Tests/MissingTypeChecker.cs | 6 +-- Src/CSharpier/CodeFormatterResult.cs | 3 +- Src/CSharpier/DocPrinter/DocPrinter.cs | 2 +- Src/CSharpier/DocPrinter/Indent.cs | 13 ++----- Src/CSharpier/DocTypes/AlwaysFits.cs | 9 +---- Src/CSharpier/DocTypes/Concat.cs | 9 +---- Src/CSharpier/DocTypes/Region.cs | 9 +---- Src/CSharpier/DocTypes/StringDoc.cs | 12 ++---- .../Formatters/CSharp/PreprocessorSymbols.cs | 10 ++--- Src/CSharpier/GeneratedCodeUtilities.cs | 6 +-- Src/CSharpier/SyntaxPrinter/Modifiers.cs | 4 +- .../SyntaxNodePrinters/BinaryExpression.cs | 6 +-- .../InterpolatedStringExpression.cs | 2 +- Src/CSharpier/SyntaxPrinter/Token.cs | 2 +- .../SyntaxPrinter/UsingDirectives.cs | 5 ++- .../Utilities/StringBuilderExtensions.cs | 4 +- Src/SyntaxFinder/Ignored.cs | 6 +-- Src/SyntaxFinder/Walkers/ModifiersWalker.cs | 5 +-- .../Walkers/ObjectInitializerWalker.cs | 10 +---- Src/SyntaxFinder/Walkers/SpreadWalker.cs | 9 +---- 40 files changed, 168 insertions(+), 324 deletions(-) diff --git a/.editorconfig b/.editorconfig index c06f455ce..cc3b0ea87 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,31 @@ indent_size = 2 indent_style = space +csharp_using_directive_placement = outside_namespace +csharp_style_inlined_variable_declaration = true +csharp_style_pattern_matching_over_is_with_cast_check = true +csharp_style_var_elsewhere = true +csharp_style_var_for_built_in_types = true +csharp_style_var_when_type_is_apparent = true + [*.{cs,vb}] dotnet_diagnostic.RS0041.severity = warning +dotnet_diagnostic.IDE0007.severity = warning +dotnet_diagnostic.IDE0018.severity = warning +dotnet_diagnostic.IDE0019.severity = warning +dotnet_diagnostic.IDE0020.severity = warning +dotnet_diagnostic.IDE0029.severity = warning +dotnet_diagnostic.IDE0030.severity = warning +dotnet_diagnostic.IDE0031.severity = warning +dotnet_diagnostic.IDE0032.severity = warning +dotnet_diagnostic.IDE0036.severity = warning +dotnet_diagnostic.IDE0038.severity = warning dotnet_diagnostic.IDE0065.severity = warning -csharp_using_directive_placement = outside_namespace +dotnet_diagnostic.IDE0075.severity = warning +dotnet_diagnostic.IDE0078.severity = warning +dotnet_diagnostic.IDE0150.severity = warning +dotnet_diagnostic.IDE0290.severity = warning +dotnet_diagnostic.IDE0300.severity = warning +dotnet_diagnostic.IDE0301.severity = warning + + diff --git a/Src/CSharpier.Cli/CommandLineOptions.cs b/Src/CSharpier.Cli/CommandLineOptions.cs index 3f72b9850..1ed067ca0 100644 --- a/Src/CSharpier.Cli/CommandLineOptions.cs +++ b/Src/CSharpier.Cli/CommandLineOptions.cs @@ -5,7 +5,7 @@ namespace CSharpier.Cli; internal class CommandLineOptions { - public string[] DirectoryOrFilePaths { get; init; } = Array.Empty(); + public string[] DirectoryOrFilePaths { get; init; } = []; public bool Check { get; init; } public bool Fast { get; init; } public bool SkipWrite { get; init; } @@ -16,7 +16,7 @@ internal class CommandLineOptions public bool IncludeGenerated { get; init; } public string? StandardInFileContents { get; init; } public string? ConfigPath { get; init; } - public string[] OriginalDirectoryOrFilePaths { get; init; } = Array.Empty(); + public string[] OriginalDirectoryOrFilePaths { get; init; } = []; internal delegate Task Handler( string[] directoryOrFile, @@ -46,57 +46,48 @@ public static RootCommand Create() Description = "One or more paths to a directory containing C# files to format or a C# file to format. It may be ommited when piping data via stdin.", }.LegalFilePathsOnly(), - new Option( - new[] { "--check" }, - "Check that files are formatted. Will not write any changes." - ), + new Option(["--check"], "Check that files are formatted. Will not write any changes."), new Option( - new[] { "--loglevel" }, + ["--loglevel"], () => LogLevel.Information.ToString(), "Specify the log level - Debug, Information (default), Warning, Error, None" ), new Option( - new[] { "--no-cache" }, + ["--no-cache"], "Bypass the cache to determine if a file needs to be formatted." ), new Option( - new[] { "--no-msbuild-check" }, + ["--no-msbuild-check"], "Bypass the check to determine if a csproj files references a different version of CSharpier.MsBuild." ), new Option( - new[] { "--include-generated" }, + ["--include-generated"], "Include files generated by the SDK and files that begin with comments" ), new Option( - new[] { "--fast" }, + ["--fast"], "Skip comparing syntax tree of formatted file to original file to validate changes." ), new Option( - new[] { "--skip-write" }, + ["--skip-write"], "Skip writing changes. Generally used for testing to ensure csharpier doesn't throw any errors or cause syntax tree validation failures." ), + new Option(["--write-stdout"], "Write the results of formatting any files to stdout."), new Option( - new[] { "--write-stdout" }, - "Write the results of formatting any files to stdout." - ), - new Option( - new[] { "--pipe-multiple-files" }, + ["--pipe-multiple-files"], "Keep csharpier running so that multiples files can be piped to it via stdin." ), new Option( - new[] { "--server" }, + ["--server"], "Run CSharpier as a server so that multiple files may be formatted." ), new Option( - new[] { "--server-port" }, + ["--server-port"], "Specify the port that CSharpier should start on. Defaults to a random unused port." ), - new Option( - new[] { "--config-path" }, - "Path to the CSharpier configuration file" - ), + new Option(["--config-path"], "Path to the CSharpier configuration file"), new Option( - new[] { "--compilation-errors-as-warnings" }, + ["--compilation-errors-as-warnings"], "Treat compilation errors from files as warnings instead of errors." ), }; diff --git a/Src/CSharpier.Cli/ConsoleLogger.cs b/Src/CSharpier.Cli/ConsoleLogger.cs index c4783b86e..aa314d505 100644 --- a/Src/CSharpier.Cli/ConsoleLogger.cs +++ b/Src/CSharpier.Cli/ConsoleLogger.cs @@ -2,19 +2,10 @@ namespace CSharpier.Cli; -internal class ConsoleLogger : ILogger +internal class ConsoleLogger(IConsole console, LogLevel loggingLevel) : ILogger { private static readonly object ConsoleLock = new(); - private readonly IConsole console; - private readonly LogLevel loggingLevel; - - public ConsoleLogger(IConsole console, LogLevel loggingLevel) - { - this.console = console; - this.loggingLevel = loggingLevel; - } - public virtual void Log( LogLevel logLevel, EventId eventId, @@ -23,7 +14,7 @@ public virtual void Log( Func formatter ) { - if (logLevel < this.loggingLevel) + if (logLevel < loggingLevel) { return; } @@ -32,11 +23,11 @@ void Write(string value) { if (logLevel >= LogLevel.Error) { - this.console.WriteError(value); + console.WriteError(value); } else { - this.console.Write(value); + console.Write(value); } } @@ -44,11 +35,11 @@ void WriteLine(string? value = null) { if (logLevel >= LogLevel.Error) { - this.console.WriteErrorLine(value); + console.WriteErrorLine(value); } else { - this.console.WriteLine(value); + console.WriteLine(value); } } @@ -63,9 +54,9 @@ void WriteLine(string? value = null) if (logLevel >= LogLevel.Warning) { - this.console.ForegroundColor = GetColorLevel(logLevel); + console.ForegroundColor = GetColorLevel(logLevel); Write($"{logLevel} "); - this.console.ResetColor(); + console.ResetColor(); } var stringReader = new StringReader(message); diff --git a/Src/CSharpier.Cli/EditorConfig/GlobMatcher.cs b/Src/CSharpier.Cli/EditorConfig/GlobMatcher.cs index 0b9b80112..68b0ebdfd 100644 --- a/Src/CSharpier.Cli/EditorConfig/GlobMatcher.cs +++ b/Src/CSharpier.Cli/EditorConfig/GlobMatcher.cs @@ -87,8 +87,8 @@ private GlobMatcher( this.myEmpty = empty; } - private static readonly char[] ourUnixPathSeparators = { '/' }; - private static readonly char[] ourWinPathSeparators = { '/', '\\' }; + private static readonly char[] ourUnixPathSeparators = ['/']; + private static readonly char[] ourWinPathSeparators = ['/', '\\']; ///Checks whether a given string matches this pattern. public bool IsMatch(string input) @@ -646,7 +646,7 @@ public void Build() for (var i = 0; i < this.Count; i++) { var item = this[i]; - if (item is PathSeparator || item is DoubleAsterisk) + if (item is PathSeparator or DoubleAsterisk) { this.HasPathSeparators = true; } @@ -697,27 +697,19 @@ public void Build() private interface IPatternElement { } - private class Literal : IPatternElement + private class Literal(string source) : IPatternElement { - public Literal(string source) => this.Source = source; - - public string Source { get; } + public string Source { get; } = source; } - private class OneChar : IPatternElement + private class OneChar(string possibleChars, bool negate) : IPatternElement { static OneChar() { } public static readonly OneChar EmptyInstance = new OneChar(null, false); - public OneChar(string possibleChars, bool negate) - { - this.PossibleChars = possibleChars; - this.Negate = negate; - } - - private string PossibleChars { get; } - private bool Negate { get; } + private string PossibleChars { get; } = possibleChars; + private bool Negate { get; } = negate; public bool CheckChar(GlobMatcherOptions options, char c, StringComparison comparison) { @@ -848,7 +840,7 @@ private static IList BraceExpand(string pattern, GlobMatcherOptions opti if (options.NoBrace || !ourHasBraces.IsMatch(pattern)) { // shortcut. no need to expand. - return new[] { pattern }; + return [pattern]; } var escaping = false; @@ -894,7 +886,7 @@ private static IList BraceExpand(string pattern, GlobMatcherOptions opti if (prefix == null) { // console.error("no sets") - return new[] { pattern }; + return [pattern]; } var braceExpand = BraceExpand(pattern.Substring(i), options); @@ -1051,7 +1043,7 @@ private static IList BraceExpand(string pattern, GlobMatcherOptions opti private static PatternCase Parse(GlobMatcherOptions options, string pattern) { if (pattern == "") - return new PatternCase(); + return []; var result = new PatternCase(); var sb = new StringBuilder(); @@ -1123,7 +1115,7 @@ void AppendChar(char c1) FinishLiteral(); - if (!(result.LastOrDefault() is PathSeparator)) + if (result.LastOrDefault() is not PathSeparator) { result.Add(PathSeparator.Instance); } @@ -1175,7 +1167,7 @@ void AppendChar(char c1) result.RemoveAt(result.Count - 1); result.Add(new DoubleAsterisk()); } - else if (!(result.LastOrDefault() is SimpleAsterisk)) + else if (result.LastOrDefault() is not SimpleAsterisk) { result.Add(new SimpleAsterisk()); } 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.Cli/FileIssueLogger.cs b/Src/CSharpier.Cli/FileIssueLogger.cs index 5c4902af9..a3fc96994 100644 --- a/Src/CSharpier.Cli/FileIssueLogger.cs +++ b/Src/CSharpier.Cli/FileIssueLogger.cs @@ -2,29 +2,20 @@ namespace CSharpier.Cli; -internal class FileIssueLogger +internal class FileIssueLogger(string filePath, ILogger logger) { - private readonly string filePath; - private readonly ILogger logger; - - public FileIssueLogger(string filePath, ILogger logger) - { - this.filePath = filePath; - this.logger = logger; - } - public void WriteError(string value, Exception? exception = null) { - this.logger.LogError(exception, $"{this.GetPath()} - {value}"); + logger.LogError(exception, $"{this.GetPath()} - {value}"); } public void WriteWarning(string value) { - this.logger.LogWarning($"{this.GetPath()} - {value}"); + logger.LogWarning($"{this.GetPath()} - {value}"); } private string GetPath() { - return this.filePath; + return filePath; } } diff --git a/Src/CSharpier.Cli/FormattingCache.cs b/Src/CSharpier.Cli/FormattingCache.cs index b6ca28ba9..8dc4f0cf5 100644 --- a/Src/CSharpier.Cli/FormattingCache.cs +++ b/Src/CSharpier.Cli/FormattingCache.cs @@ -88,37 +88,26 @@ CancellationToken cancellationToken return new FormattingCache(optionsProvider, CacheFilePath, cacheDictionary, fileSystem); } - private class FormattingCache : IFormattingCache + private class FormattingCache( + OptionsProvider optionsProvider, + string cacheFile, + ConcurrentDictionary cacheDictionary, + IFileSystem fileSystem + ) : IFormattingCache { - private readonly string optionsHash; - private readonly string cacheFile; - private readonly ConcurrentDictionary cacheDictionary; - private readonly IFileSystem fileSystem; - - public FormattingCache( - OptionsProvider optionsProvider, - string cacheFile, - ConcurrentDictionary cacheDictionary, - IFileSystem fileSystem - ) - { - this.optionsHash = GetOptionsHash(optionsProvider); - this.cacheFile = cacheFile; - this.cacheDictionary = cacheDictionary; - this.fileSystem = fileSystem; - } + private readonly string optionsHash = GetOptionsHash(optionsProvider); public bool CanSkipFormatting(FileToFormatInfo fileToFormatInfo) { var currentHash = Hash(fileToFormatInfo.FileContents) + this.optionsHash; - if (this.cacheDictionary.TryGetValue(fileToFormatInfo.Path, out var cachedHash)) + if (cacheDictionary.TryGetValue(fileToFormatInfo.Path, out var cachedHash)) { if (currentHash == cachedHash) { return true; } - this.cacheDictionary.TryRemove(fileToFormatInfo.Path, out _); + cacheDictionary.TryRemove(fileToFormatInfo.Path, out _); } return false; @@ -126,7 +115,7 @@ public bool CanSkipFormatting(FileToFormatInfo fileToFormatInfo) public void CacheResult(string code, FileToFormatInfo fileToFormatInfo) { - this.cacheDictionary[fileToFormatInfo.Path] = Hash(code) + this.optionsHash; + cacheDictionary[fileToFormatInfo.Path] = Hash(code) + this.optionsHash; } private static string GetOptionsHash(OptionsProvider optionsProvider) @@ -143,12 +132,12 @@ private static string Hash(string input) public async Task ResolveAsync(CancellationToken cancellationToken) { - this.fileSystem.FileInfo.New(this.cacheFile).EnsureDirectoryExists(); + fileSystem.FileInfo.New(cacheFile).EnsureDirectoryExists(); async Task WriteFile() { - await using var fileStream = this.fileSystem.File.Open( - this.cacheFile, + await using var fileStream = fileSystem.File.Open( + cacheFile, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None @@ -156,7 +145,7 @@ async Task WriteFile() await using var streamWriter = new StreamWriter(fileStream); await streamWriter.WriteAsync( JsonSerializer.Serialize( - this.cacheDictionary + cacheDictionary #if DEBUG , new JsonSerializerOptions { WriteIndented = true } diff --git a/Src/CSharpier.Cli/IgnoreFile.cs b/Src/CSharpier.Cli/IgnoreFile.cs index 5542f77c3..eb370742e 100644 --- a/Src/CSharpier.Cli/IgnoreFile.cs +++ b/Src/CSharpier.Cli/IgnoreFile.cs @@ -6,11 +6,7 @@ internal class IgnoreFile { protected Ignore.Ignore Ignore { get; } protected string IgnoreBaseDirectoryPath { get; } - private static readonly string[] alwaysIgnored = - { - "**/node_modules/**/*.cs", - "**/obj/**/*.cs", - }; + private static readonly string[] alwaysIgnored = ["**/node_modules/**/*.cs", "**/obj/**/*.cs"]; protected IgnoreFile(Ignore.Ignore ignore, string ignoreBaseDirectoryPath) { @@ -105,8 +101,5 @@ var line in await fileSystem.File.ReadAllLinesAsync(ignoreFilePath, cancellation } } -internal class InvalidIgnoreFileException : Exception -{ - public InvalidIgnoreFileException(string message, Exception exception) - : base(message, exception) { } -} +internal class InvalidIgnoreFileException(string message, Exception exception) + : Exception(message, exception); diff --git a/Src/CSharpier.Cli/Options/ConfigFileParser.cs b/Src/CSharpier.Cli/Options/ConfigFileParser.cs index 954fdc31e..80d924ba2 100644 --- a/Src/CSharpier.Cli/Options/ConfigFileParser.cs +++ b/Src/CSharpier.Cli/Options/ConfigFileParser.cs @@ -8,7 +8,7 @@ namespace CSharpier.Cli.Options; internal static class ConfigFileParser { - private static readonly string[] validExtensions = { ".csharpierrc", ".json", ".yml", ".yaml" }; + private static readonly string[] validExtensions = [".csharpierrc", ".json", ".yml", ".yaml"]; /// Finds all configs above the given directory as well as within the subtree of this directory internal static List FindForDirectoryName( diff --git a/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs b/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs index 751156fa3..7796f754c 100644 --- a/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs +++ b/Src/CSharpier.Cli/PhysicalFileInfoAndWriter.cs @@ -2,14 +2,9 @@ namespace CSharpier.Cli; -internal class FileSystemFormattedFileWriter : IFormattedFileWriter +internal class FileSystemFormattedFileWriter(IFileSystem fileSystem) : IFormattedFileWriter { - public IFileSystem FileSystem { get; } - - public FileSystemFormattedFileWriter(IFileSystem fileSystem) - { - this.FileSystem = fileSystem; - } + public IFileSystem FileSystem { get; } = fileSystem; public void WriteResult(CodeFormatterResult result, FileToFormatInfo fileToFormatInfo) { diff --git a/Src/CSharpier.Cli/PipeMultipleFilesFormatter.cs b/Src/CSharpier.Cli/PipeMultipleFilesFormatter.cs index f20df6b91..9e4cee613 100644 --- a/Src/CSharpier.Cli/PipeMultipleFilesFormatter.cs +++ b/Src/CSharpier.Cli/PipeMultipleFilesFormatter.cs @@ -52,16 +52,16 @@ CancellationToken cancellationToken { var commandLineOptions = new CommandLineOptions { - DirectoryOrFilePaths = new[] - { + DirectoryOrFilePaths = + [ Path.Combine(Directory.GetCurrentDirectory(), fileName), - }, - OriginalDirectoryOrFilePaths = new[] - { + ], + OriginalDirectoryOrFilePaths = + [ Path.IsPathRooted(fileName) ? fileName : fileName.StartsWith(".") ? fileName : "./" + fileName, - }, + ], StandardInFileContents = stringBuilder.ToString(), Fast = true, WriteStdout = true, diff --git a/Src/CSharpier.Cli/Program.cs b/Src/CSharpier.Cli/Program.cs index b26db8d4f..ca941719e 100644 --- a/Src/CSharpier.Cli/Program.cs +++ b/Src/CSharpier.Cli/Program.cs @@ -75,8 +75,8 @@ CancellationToken cancellationToken #endif ); - directoryOrFile = new[] { Directory.GetCurrentDirectory() }; - originalDirectoryOrFile = new[] { Directory.GetCurrentDirectory() }; + directoryOrFile = [Directory.GetCurrentDirectory()]; + originalDirectoryOrFile = [Directory.GetCurrentDirectory()]; } else { diff --git a/Src/CSharpier.Cli/StdOutFormattedFileWriter.cs b/Src/CSharpier.Cli/StdOutFormattedFileWriter.cs index 8c21b43ab..09610eaa4 100644 --- a/Src/CSharpier.Cli/StdOutFormattedFileWriter.cs +++ b/Src/CSharpier.Cli/StdOutFormattedFileWriter.cs @@ -1,16 +1,9 @@ namespace CSharpier.Cli; -internal class StdOutFormattedFileWriter : IFormattedFileWriter +internal class StdOutFormattedFileWriter(IConsole console) : IFormattedFileWriter { - private readonly IConsole console; - - public StdOutFormattedFileWriter(IConsole console) - { - this.console = console; - } - public void WriteResult(CodeFormatterResult result, FileToFormatInfo fileToFormatInfo) { - this.console.Write(result.Code); + console.Write(result.Code); } } diff --git a/Src/CSharpier.FakeGenerators/CodeContext.cs b/Src/CSharpier.FakeGenerators/CodeContext.cs index 940957c7a..821c3d1af 100644 --- a/Src/CSharpier.FakeGenerators/CodeContext.cs +++ b/Src/CSharpier.FakeGenerators/CodeContext.cs @@ -1,13 +1,8 @@ namespace CSharpier.FakeGenerators; -public class CodeContext +public class CodeContext(string folder) { - public string Folder { get; set; } - - public CodeContext(string folder) - { - this.Folder = folder; - } + public string Folder { get; set; } = folder; public void AddSource(string name, string source) { diff --git a/Src/CSharpier.FakeGenerators/Ignored.cs b/Src/CSharpier.FakeGenerators/Ignored.cs index 05b0c4051..88e5db60b 100644 --- a/Src/CSharpier.FakeGenerators/Ignored.cs +++ b/Src/CSharpier.FakeGenerators/Ignored.cs @@ -7,7 +7,7 @@ namespace CSharpier.FakeGenerators; public static class Ignored { public static readonly string[] Properties = - { + [ "language", "parent", "parentTrivia", @@ -19,26 +19,18 @@ public static class Ignored "hasStructuredTrivia", "containsSkippedText", "containsAnnotations", - }; + ]; - public static readonly Type[] Types = { typeof(TextSpan), typeof(SyntaxTree) }; + public static readonly Type[] Types = [typeof(TextSpan), typeof(SyntaxTree)]; public static readonly Dictionary PropertiesByType = new() { - { typeof(PropertyDeclarationSyntax), new[] { "semicolon" } }, - { typeof(IndexerDeclarationSyntax), new[] { "semicolon" } }, - { typeof(SyntaxTrivia), new[] { "token" } }, - { typeof(SyntaxToken), new[] { "value", "valueText" } }, - { typeof(ParameterSyntax), new[] { "exclamationExclamationToken" } }, + { typeof(PropertyDeclarationSyntax), ["semicolon"] }, + { typeof(IndexerDeclarationSyntax), ["semicolon"] }, + { typeof(SyntaxTrivia), ["token"] }, + { typeof(SyntaxToken), ["value", "valueText"] }, + { typeof(ParameterSyntax), ["exclamationExclamationToken"] }, }; - public static readonly HashSet UnsupportedNodes = new() - { - // if new versions of c# add node types, we need to ignore them in the generators - // until codeAnalysis + sdks are updated - // global.json doesn't seem to always be respected for builds (namely VS but rider started having the same problem) - // which causes the generators to generate code for the new node types - // but then the build fails because those types don't exist in the packages the actual project references - // "ListPatternSyntax", "SlicePatternSyntax" - }; + public static readonly HashSet UnsupportedNodes = []; } diff --git a/Src/CSharpier.Playground/Controllers/FormatController.cs b/Src/CSharpier.Playground/Controllers/FormatController.cs index a8de73daf..20f992ba0 100644 --- a/Src/CSharpier.Playground/Controllers/FormatController.cs +++ b/Src/CSharpier.Playground/Controllers/FormatController.cs @@ -27,20 +27,9 @@ public class FormatError [ApiController] [Route("[controller]")] -public class FormatController : ControllerBase +public class FormatController() : ControllerBase { - private readonly IWebHostEnvironment webHostEnvironment; - private readonly ILogger logger; - // ReSharper disable once SuggestBaseTypeForParameter - public FormatController( - IWebHostEnvironment webHostEnvironment, - ILogger logger - ) - { - this.webHostEnvironment = webHostEnvironment; - this.logger = logger; - } public class PostModel { @@ -99,26 +88,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.Playground/Pages/Error.cshtml.cs b/Src/CSharpier.Playground/Pages/Error.cshtml.cs index 79688e481..6852aad3e 100644 --- a/Src/CSharpier.Playground/Pages/Error.cshtml.cs +++ b/Src/CSharpier.Playground/Pages/Error.cshtml.cs @@ -8,13 +8,6 @@ namespace CSharpier.Playground.Pages; [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public class ErrorModel : PageModel { - private readonly ILogger _logger; - - public ErrorModel(ILogger logger) - { - this._logger = logger; - } - public string? RequestId { get; set; } public bool ShowRequestId => !string.IsNullOrEmpty(this.RequestId); diff --git a/Src/CSharpier.Playground/Startup.cs b/Src/CSharpier.Playground/Startup.cs index 969c4520d..4e320156d 100644 --- a/Src/CSharpier.Playground/Startup.cs +++ b/Src/CSharpier.Playground/Startup.cs @@ -8,14 +8,9 @@ namespace CSharpier.Playground; -public class Startup +public class Startup(IConfiguration configuration) { - public Startup(IConfiguration configuration) - { - this.Configuration = configuration; - } - - public IConfiguration Configuration { get; } + public IConfiguration Configuration { get; } = configuration; public void ConfigureServices(IServiceCollection services) { diff --git a/Src/CSharpier.Tests/CommandLineFormatterTests.cs b/Src/CSharpier.Tests/CommandLineFormatterTests.cs index bcc4b5c53..c489514b0 100644 --- a/Src/CSharpier.Tests/CommandLineFormatterTests.cs +++ b/Src/CSharpier.Tests/CommandLineFormatterTests.cs @@ -511,7 +511,7 @@ public void Multiple_Files_Should_Use_Root_Ignore() var result = this.Format( context, - directoryOrFilePaths: new[] { unformattedFilePath1, unformattedFilePath2 } + directoryOrFilePaths: [unformattedFilePath1, unformattedFilePath2] ); result.OutputLines.FirstOrDefault().Should().StartWith("Formatted 0 files in "); @@ -530,7 +530,7 @@ public void Multiple_Files_Should_Use_Multiple_Ignores() var result = this.Format( context, - directoryOrFilePaths: new[] { unformattedFilePath1, unformattedFilePath2 } + directoryOrFilePaths: [unformattedFilePath1, unformattedFilePath2] ); result.OutputLines.FirstOrDefault().Should().StartWith("Formatted 0 files in "); @@ -730,8 +730,8 @@ params string[] directoryOrFilePaths var originalDirectoryOrFilePaths = directoryOrFilePaths; if (directoryOrFilePaths.Length == 0) { - directoryOrFilePaths = new[] { context.GetRootPath() }; - originalDirectoryOrFilePaths = new[] { "." }; + directoryOrFilePaths = [context.GetRootPath()]; + originalDirectoryOrFilePaths = ["."]; } else { @@ -801,8 +801,8 @@ IList ErrorOutputLines private class TestConsole : IConsole { - private readonly List lines = new(); - private readonly List errorLines = new(); + private readonly List lines = []; + private readonly List errorLines = []; public List GetLines() { diff --git a/Src/CSharpier.Tests/DocUtilitiesTests.cs b/Src/CSharpier.Tests/DocUtilitiesTests.cs index 58815b68f..d1852fd63 100644 --- a/Src/CSharpier.Tests/DocUtilitiesTests.cs +++ b/Src/CSharpier.Tests/DocUtilitiesTests.cs @@ -48,7 +48,7 @@ public void RemoveInitialDoubleHardLine_Should_Not_Remove_Concated_HardLine() DocUtilities.RemoveInitialDoubleHardLine(doc); - concat.Contents.Should().BeEquivalentTo(new[] { Doc.HardLine }); + concat.Contents.Should().BeEquivalentTo([Doc.HardLine]); } [Test] @@ -70,7 +70,7 @@ public void RemoveInitialDoubleHardLine_Should_Not_Remove_Deep_Concated_HardLine DocUtilities.RemoveInitialDoubleHardLine(doc); - concat.Contents.Should().BeEquivalentTo(new[] { Doc.HardLine }); + concat.Contents.Should().BeEquivalentTo([Doc.HardLine]); } [Test] diff --git a/Src/CSharpier.Tests/MissingTypeChecker.cs b/Src/CSharpier.Tests/MissingTypeChecker.cs index 77c211b30..78a784793 100644 --- a/Src/CSharpier.Tests/MissingTypeChecker.cs +++ b/Src/CSharpier.Tests/MissingTypeChecker.cs @@ -70,8 +70,8 @@ public void Ensure_There_Are_No_Missing_Types() missingTypes.Should().BeEmpty(); } - private readonly HashSet ignored = new() - { + private readonly HashSet ignored = + [ "AccessorDeclarationSyntax", "AccessorListSyntax", "AttributeArgumentListSyntax", @@ -113,5 +113,5 @@ public void Ensure_There_Are_No_Missing_Types() "XmlNameSyntax", "XmlPrefixSyntax", "XmlTextAttributeSyntax", - }; + ]; } diff --git a/Src/CSharpier/CodeFormatterResult.cs b/Src/CSharpier/CodeFormatterResult.cs index 253cf151c..2a7ab18fd 100644 --- a/Src/CSharpier/CodeFormatterResult.cs +++ b/Src/CSharpier/CodeFormatterResult.cs @@ -7,8 +7,7 @@ internal CodeFormatterResult() { } public string Code { get; internal init; } = string.Empty; internal string DocTree { get; init; } = string.Empty; internal string AST { 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/DocPrinter/DocPrinter.cs b/Src/CSharpier/DocPrinter/DocPrinter.cs index 8354fd47d..57474ebbe 100644 --- a/Src/CSharpier/DocPrinter/DocPrinter.cs +++ b/Src/CSharpier/DocPrinter/DocPrinter.cs @@ -56,7 +56,7 @@ private void EnsureOutputEndsWithSingleNewLine() var trimmed = 0; for (; trimmed < this.Output.Length; trimmed++) { - if (this.Output[^(trimmed + 1)] != '\r' && this.Output[^(trimmed + 1)] != '\n') + if (this.Output[^(trimmed + 1)] is not '\r' and not '\n') { break; } diff --git a/Src/CSharpier/DocPrinter/Indent.cs b/Src/CSharpier/DocPrinter/Indent.cs index 1fe31d3d1..3de44af1a 100644 --- a/Src/CSharpier/DocPrinter/Indent.cs +++ b/Src/CSharpier/DocPrinter/Indent.cs @@ -23,14 +23,9 @@ internal class AlignType : IIndentType public int Width { get; init; } } -internal class Indenter +internal class Indenter(PrinterOptions printerOptions) { - protected readonly PrinterOptions PrinterOptions; - - public Indenter(PrinterOptions printerOptions) - { - this.PrinterOptions = printerOptions; - } + protected readonly PrinterOptions PrinterOptions = printerOptions; public static Indent GenerateRoot() { @@ -88,7 +83,7 @@ private Indent MakeIndentWithTypesForTabs(Indent indent, IIndentType nextIndentT // if it doesn't exist yet, then all values on it are regular indents, not aligns if (indent.TypesForTabs == null) { - types = new List(); + types = []; for (var x = 0; x < indent.Value.Length; x++) { types.Add(IndentType.Instance); @@ -99,7 +94,7 @@ private Indent MakeIndentWithTypesForTabs(Indent indent, IIndentType nextIndentT else { var placeTab = false; - types = new List(indent.TypesForTabs) { nextIndentType }; + types = [.. indent.TypesForTabs, nextIndentType]; for (var x = types.Count - 1; x >= 0; x--) { if (types[x] == IndentType.Instance) diff --git a/Src/CSharpier/DocTypes/AlwaysFits.cs b/Src/CSharpier/DocTypes/AlwaysFits.cs index ba876d817..aff4b0848 100644 --- a/Src/CSharpier/DocTypes/AlwaysFits.cs +++ b/Src/CSharpier/DocTypes/AlwaysFits.cs @@ -1,11 +1,6 @@ namespace CSharpier.DocTypes; -internal class AlwaysFits : Doc +internal class AlwaysFits(Doc printedTrivia) : Doc { - public readonly Doc Contents; - - public AlwaysFits(Doc printedTrivia) - { - this.Contents = printedTrivia; - } + public readonly Doc Contents = printedTrivia; } diff --git a/Src/CSharpier/DocTypes/Concat.cs b/Src/CSharpier/DocTypes/Concat.cs index 9ee46c3ba..dad293294 100644 --- a/Src/CSharpier/DocTypes/Concat.cs +++ b/Src/CSharpier/DocTypes/Concat.cs @@ -1,11 +1,6 @@ namespace CSharpier.DocTypes; -internal class Concat : Doc +internal class Concat(IList contents) : Doc { - public IList Contents { get; set; } - - public Concat(IList contents) - { - this.Contents = contents; - } + public IList Contents { get; set; } = contents; } diff --git a/Src/CSharpier/DocTypes/Region.cs b/Src/CSharpier/DocTypes/Region.cs index ff5ffb372..4d5a7f477 100644 --- a/Src/CSharpier/DocTypes/Region.cs +++ b/Src/CSharpier/DocTypes/Region.cs @@ -1,12 +1,7 @@ namespace CSharpier.DocTypes; -internal class Region : Doc +internal class Region(string text) : Doc { - public Region(string text) - { - this.Text = text; - } - - public string Text { get; } + public string Text { get; } = text; public bool IsEnd { get; init; } } diff --git a/Src/CSharpier/DocTypes/StringDoc.cs b/Src/CSharpier/DocTypes/StringDoc.cs index 80cb08844..e1b84f9a5 100644 --- a/Src/CSharpier/DocTypes/StringDoc.cs +++ b/Src/CSharpier/DocTypes/StringDoc.cs @@ -1,13 +1,7 @@ namespace CSharpier.DocTypes; -internal class StringDoc : Doc +internal class StringDoc(string value, bool isDirective = false) : Doc { - public string Value { get; } - public bool IsDirective { get; } - - public StringDoc(string value, bool isDirective = false) - { - this.Value = value; - this.IsDirective = isDirective; - } + public string Value { get; } = value; + public bool IsDirective { get; } = isDirective; } diff --git a/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs b/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs index 834b4f498..c89b0de18 100644 --- a/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs +++ b/Src/CSharpier/Formatters/CSharp/PreprocessorSymbols.cs @@ -2,8 +2,8 @@ namespace CSharpier.Formatters.CSharp; internal class PreprocessorSymbols : CSharpSyntaxWalker { - private readonly List symbolSets = new(); - private readonly HashSet squashedSymbolSets = new(); + private readonly List symbolSets = []; + private readonly HashSet squashedSymbolSets = []; private SymbolContext CurrentContext = new() { ParentContext = new SymbolContext { ParentContext = null! }, @@ -136,7 +136,7 @@ private string[] GetSymbols(BooleanExpression booleanExpression) ); return possibleParameters == null - ? Array.Empty() + ? [] : possibleParameters.Where(o => o.Value).Select(o => o.Key).OrderBy(o => o).ToArray(); } @@ -154,7 +154,7 @@ private static List> GenerateCombinations(List { if (!parameterNames.Any()) { - return new List> { new() }; + return [new()]; } var subCombinations = GenerateCombinations(parameterNames.Skip(1).ToList()); @@ -181,6 +181,6 @@ private static List> GenerateCombinations(List private class SymbolContext { public required SymbolContext ParentContext { get; init; } - public List booleanExpressions { get; } = new(); + public List booleanExpressions { get; } = []; } } diff --git a/Src/CSharpier/GeneratedCodeUtilities.cs b/Src/CSharpier/GeneratedCodeUtilities.cs index 638126326..8c386fa51 100644 --- a/Src/CSharpier/GeneratedCodeUtilities.cs +++ b/Src/CSharpier/GeneratedCodeUtilities.cs @@ -23,11 +23,7 @@ public static bool IsGeneratedCodeFile(string filePath) || fileNameWithoutExtension.EndsWithIgnoreCase(".g.i"); } - private static readonly string[] AutoGeneratedStrings = new[] - { - " { // use the default order from https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0036 private static readonly string[] DefaultOrdered = - { + [ "public", "private", "protected", @@ -24,7 +24,7 @@ private class DefaultOrder : IComparer "required", "volatile", "async", - }; + ]; public int Compare(string? x, string? y) { diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BinaryExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BinaryExpression.cs index a86ca5e90..6e4672a8f 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BinaryExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/BinaryExpression.cs @@ -52,7 +52,7 @@ private static List PrintBinaryExpression(SyntaxNode node, PrintingContext { if (node is not BinaryExpressionSyntax binaryExpressionSyntax) { - return new List { Doc.Group(Node.Print(node, context)) }; + return [Doc.Group(Node.Print(node, context))]; } if (context.State.PrintingDepth > 200) @@ -112,9 +112,7 @@ possibleBinary is BinaryExpressionSyntax childBinary if (binaryOnTheRight) { - return shouldGroup - ? new List { docs[0], Doc.Group(docs.Skip(1).ToList()) } - : docs; + return shouldGroup ? [docs[0], Doc.Group(docs.Skip(1).ToList())] : docs; } var right = Doc.Concat( diff --git a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs index 9c165a581..30cc21d0c 100644 --- a/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs +++ b/Src/CSharpier/SyntaxPrinter/SyntaxNodePrinters/InterpolatedStringExpression.cs @@ -2,7 +2,7 @@ namespace CSharpier.SyntaxPrinter.SyntaxNodePrinters; internal static class InterpolatedStringExpression { - internal static readonly string[] lineSeparators = new[] { "\r\n", "\r", "\n" }; + internal static readonly string[] lineSeparators = ["\r\n", "\r", "\n"]; public static Doc Print(InterpolatedStringExpressionSyntax node, PrintingContext context) { diff --git a/Src/CSharpier/SyntaxPrinter/Token.cs b/Src/CSharpier/SyntaxPrinter/Token.cs index 7e652e94f..f21becad8 100644 --- a/Src/CSharpier/SyntaxPrinter/Token.cs +++ b/Src/CSharpier/SyntaxPrinter/Token.cs @@ -29,7 +29,7 @@ public static Doc PrintWithSuffix( return PrintSyntaxToken(syntaxToken, context, suffixDoc, skipLeadingTrivia); } - internal static readonly string[] lineSeparators = new[] { "\r\n", "\r", "\n" }; + internal static readonly string[] lineSeparators = ["\r\n", "\r", "\n"]; private static Doc PrintSyntaxToken( SyntaxToken syntaxToken, diff --git a/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs b/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs index 9a7b6917d..74e20a342 100644 --- a/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs +++ b/Src/CSharpier/SyntaxPrinter/UsingDirectives.cs @@ -35,8 +35,9 @@ bool printExtraLines break; } if ( - leadingTrivia.RawSyntaxKind() == SyntaxKind.DefineDirectiveTrivia - || leadingTrivia.RawSyntaxKind() == SyntaxKind.UndefDirectiveTrivia + leadingTrivia.RawSyntaxKind() + is SyntaxKind.DefineDirectiveTrivia + or SyntaxKind.UndefDirectiveTrivia ) { initialComments = usings.First().GetLeadingTrivia().ToList(); diff --git a/Src/CSharpier/Utilities/StringBuilderExtensions.cs b/Src/CSharpier/Utilities/StringBuilderExtensions.cs index 3a8a295ee..8cbb4b9fe 100644 --- a/Src/CSharpier/Utilities/StringBuilderExtensions.cs +++ b/Src/CSharpier/Utilities/StringBuilderExtensions.cs @@ -9,7 +9,7 @@ public static bool EndsWithNewLineAndWhitespace(this StringBuilder stringBuilder for (var index = 1; index <= stringBuilder.Length; index++) { var next = stringBuilder[^index]; - if (next == ' ' || next == '\t') + if (next is ' ' or '\t') { continue; } @@ -36,7 +36,7 @@ public static int TrimTrailingWhitespace(this StringBuilder stringBuilder) var trimmed = 0; for (; trimmed < stringBuilder.Length; trimmed++) { - if (stringBuilder[^(trimmed + 1)] != ' ' && stringBuilder[^(trimmed + 1)] != '\t') + if (stringBuilder[^(trimmed + 1)] is not ' ' and not '\t') { break; } diff --git a/Src/SyntaxFinder/Ignored.cs b/Src/SyntaxFinder/Ignored.cs index 37be8cfab..e8ecd11d4 100644 --- a/Src/SyntaxFinder/Ignored.cs +++ b/Src/SyntaxFinder/Ignored.cs @@ -7,8 +7,8 @@ public static bool Is(string file) return ignored.Any(file.Replace("\\", "/").Contains); } - private static string[] ignored = new[] - { + private static string[] ignored = + [ "roslyn/src/Compilers/Test/Core/Assert/ConditionalFactAttribute.cs", "roslyn/src/Compilers/Test/Core/Compilation/RuntimeUtilities.cs", "runtime/src/libraries/System.Net.Primitives/tests/FunctionalTests/SocketAddressTest.cs", @@ -81,5 +81,5 @@ public static bool Is(string file) "runtime/src/tests/Loader/classloader/generics/Instantiation/Nesting/NestedGenericClasses.cs", "runtime/src/tests/Loader/classloader/generics/Instantiation/Nesting/NestedGenericTypesMix.cs", "runtime/src/tests/Loader/classloader/generics/Instantiation/Nesting/NestedGenericStructs.cs", - }; + ]; } 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) {