Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An existing csharpierrc file always takes priority over editorconfig #991

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading