Skip to content

Commit

Permalink
An existing csharpierrc file always takes priority over editorconfig (#…
Browse files Browse the repository at this point in the history
…991)

closes #987
  • Loading branch information
belav authored Nov 8, 2023
1 parent a8a6683 commit 93baf5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ CSharpier has support for a configuration file. You can use any of the following
- A ```.csharpierrc.json``` or ```.csharpierrc.yaml``` file.
- A ```.editorconfig``` file. See EditorConfig section below.

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.

The configuration file will be resolved based on the location of the file being formatted.
- If a `.csharpierrc` file exists somewhere at or above the given file, that will be used.
- Otherwise if an `.editorconfig` file exists somewhere at or above the given file, that will be used. Respecting editorconfig inheritance.
### Configuration Options
JSON
```json
Expand Down
5 changes: 1 addition & 4 deletions Src/CSharpier.Cli/Options/OptionsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ public PrinterOptions GetPrinterOptionsFor(string filePath)
return new PrinterOptions();
}

if (
(resolvedCSharpierConfig?.DirectoryName.Length ?? int.MinValue)
>= (resolvedEditorConfig?.DirectoryName.Length ?? int.MinValue)
)
if (resolvedCSharpierConfig is not null)
{
return ConfigurationFileOptions.ConvertToPrinterOptions(
resolvedCSharpierConfig!.CSharpierConfig
Expand Down
4 changes: 2 additions & 2 deletions Src/CSharpier.Tests/OptionsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public async Task Should_Prefer_CSharpierrc_In_SameFolder()
}

[Test]
public async Task Should_Prefer_Closer_EditorConfig()
public async Task Should_Not_Prefer_Closer_EditorConfig()
{
var context = new TestContext();
context.WhenAFileExists(
Expand All @@ -462,7 +462,7 @@ public async Task Should_Prefer_Closer_EditorConfig()
"c:/test",
"c:/test/subfolder/test.cs"
);
result.TabWidth.Should().Be(2);
result.TabWidth.Should().Be(1);
}

[Test]
Expand Down

0 comments on commit 93baf5a

Please sign in to comment.