Skip to content

Commit 93baf5a

Browse files
authored
An existing csharpierrc file always takes priority over editorconfig (#991)
closes #987
1 parent a8a6683 commit 93baf5a

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

Docs/Configuration.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ CSharpier has support for a configuration file. You can use any of the following
77
- A ```.csharpierrc.json``` or ```.csharpierrc.yaml``` file.
88
- A ```.editorconfig``` file. See EditorConfig section below.
99

10-
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found.
11-
10+
The configuration file will be resolved based on the location of the file being formatted.
11+
- If a `.csharpierrc` file exists somewhere at or above the given file, that will be used.
12+
- Otherwise if an `.editorconfig` file exists somewhere at or above the given file, that will be used. Respecting editorconfig inheritance.
1213
### Configuration Options
1314
JSON
1415
```json

Src/CSharpier.Cli/Options/OptionsProvider.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ public PrinterOptions GetPrinterOptionsFor(string filePath)
8080
return new PrinterOptions();
8181
}
8282

83-
if (
84-
(resolvedCSharpierConfig?.DirectoryName.Length ?? int.MinValue)
85-
>= (resolvedEditorConfig?.DirectoryName.Length ?? int.MinValue)
86-
)
83+
if (resolvedCSharpierConfig is not null)
8784
{
8885
return ConfigurationFileOptions.ConvertToPrinterOptions(
8986
resolvedCSharpierConfig!.CSharpierConfig

Src/CSharpier.Tests/OptionsProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public async Task Should_Prefer_CSharpierrc_In_SameFolder()
446446
}
447447

448448
[Test]
449-
public async Task Should_Prefer_Closer_EditorConfig()
449+
public async Task Should_Not_Prefer_Closer_EditorConfig()
450450
{
451451
var context = new TestContext();
452452
context.WhenAFileExists(
@@ -462,7 +462,7 @@ public async Task Should_Prefer_Closer_EditorConfig()
462462
"c:/test",
463463
"c:/test/subfolder/test.cs"
464464
);
465-
result.TabWidth.Should().Be(2);
465+
result.TabWidth.Should().Be(1);
466466
}
467467

468468
[Test]

0 commit comments

Comments
 (0)