diff --git a/Src/CSharpier.Cli/CommandLineFormatter.cs b/Src/CSharpier.Cli/CommandLineFormatter.cs index 350097f6f..c03481a23 100644 --- a/Src/CSharpier.Cli/CommandLineFormatter.cs +++ b/Src/CSharpier.Cli/CommandLineFormatter.cs @@ -49,7 +49,7 @@ CancellationToken cancellationToken fileSystem, logger, cancellationToken, - limitEditorConfigSearch: true + limitConfigSearch: true ); if ( diff --git a/Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs b/Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs index 010f7443f..e5ea7888b 100644 --- a/Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs +++ b/Src/CSharpier.Cli/Options/ConfigurationFileOptions.cs @@ -46,14 +46,20 @@ ConfigurationFileOptions configurationFileOptions internal static List FindForDirectoryName( string directoryName, IFileSystem fileSystem, - ILogger logger + ILogger logger, + bool limitEditorConfigSearch ) { var results = new List(); var directoryInfo = fileSystem.DirectoryInfo.New(directoryName); var filesByDirectory = directoryInfo - .EnumerateFiles(".csharpierrc*", SearchOption.AllDirectories) + .EnumerateFiles( + ".csharpierrc*", + limitEditorConfigSearch + ? SearchOption.TopDirectoryOnly + : SearchOption.AllDirectories + ) .GroupBy(o => o.DirectoryName); foreach (var group in filesByDirectory) diff --git a/Src/CSharpier.Cli/Options/OptionsProvider.cs b/Src/CSharpier.Cli/Options/OptionsProvider.cs index 20437448a..3cd7b0e79 100644 --- a/Src/CSharpier.Cli/Options/OptionsProvider.cs +++ b/Src/CSharpier.Cli/Options/OptionsProvider.cs @@ -36,7 +36,7 @@ public static async Task Create( IFileSystem fileSystem, ILogger logger, CancellationToken cancellationToken, - bool limitEditorConfigSearch = false + bool limitConfigSearch = false ) { var specifiedPrinterOptions = configPath is not null @@ -44,7 +44,12 @@ public static async Task Create( : null; var csharpierConfigs = configPath is null - ? ConfigurationFileOptions.FindForDirectoryName(directoryName, fileSystem, logger) + ? ConfigurationFileOptions.FindForDirectoryName( + directoryName, + fileSystem, + logger, + limitConfigSearch + ) : Array.Empty().ToList(); IList? editorConfigSections = null; @@ -56,7 +61,7 @@ public static async Task Create( editorConfigSections = EditorConfigParser.FindForDirectoryName( directoryName, fileSystem, - limitEditorConfigSearch, + limitConfigSearch, ignoreFile ); } diff --git a/Src/CSharpier.Tests/OptionsProviderTests.cs b/Src/CSharpier.Tests/OptionsProviderTests.cs index 6f63fc91a..f5ff96962 100644 --- a/Src/CSharpier.Tests/OptionsProviderTests.cs +++ b/Src/CSharpier.Tests/OptionsProviderTests.cs @@ -647,6 +647,28 @@ public async Task Should_Not_Look_For_Subfolders_EditorConfig_When_Limited() result.TabWidth.Should().Be(4); } + [Test] + public async Task Should_Not_Look_For_Subfolders_CSharpierRc_When_Limited() + { + var context = new TestContext(); + context.WhenAFileExists( + "c:/test/subfolder/.csharpierrc", + @" + [*] + tabWidth: 1 + " + ); + + // this shouldn't happen in the real world, but validates we correctly limit + // the search to the top directory only + var result = await context.CreateProviderAndGetOptionsFor( + "c:/test/", + "c:/test/subfolder/test.cs", + limitEditorConfigSearch: true + ); + result.TabWidth.Should().Be(4); + } + [Test] public async Task Should_Look_For_Subfolders_When_Limited() {