Skip to content

Commit 7b3c080

Browse files
authored
Don't ignore an editorconfig if it happens to be in the gitignore or … (#1668)
…csharpierignore closes #1582
1 parent 8a6fb62 commit 7b3c080

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

Src/CSharpier.Cli/EditorConfig/EditorConfigLocator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CancellationToken cancellationToken
3131
var file = fileSystem.FileInfo.New(
3232
fileSystem.Path.Combine(directoryInfo.FullName, ".editorconfig")
3333
);
34-
if (file.Exists && !ignoreFile.IsIgnored(file.FullName))
34+
if (file.Exists)
3535
{
3636
var dirName = fileSystem.Path.GetDirectoryName(file.FullName);
3737
ArgumentNullException.ThrowIfNull(dirName);

Src/CSharpier.Tests/CommandLineFormatterTests.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,44 @@ public void Should_Support_Config_Path_With_Editor_Config()
901901
context.GetFileContent(fileName).Should().Be("var myVariable =\n someLongValue;\n");
902902
}
903903

904+
[Test]
905+
public void Should_Not_Fail_With_Invalid_Editor_Config()
906+
{
907+
var context = new TestContext();
908+
context.WhenAFileExists(
909+
".editorconfig",
910+
"""
911+
[*
912+
max_line_length 10
913+
"""
914+
);
915+
var fileName = context.WhenAFileExists("file1.cs", "var myVariable = someLongValue;");
916+
917+
Format(context);
918+
919+
context.GetFileContent(fileName).Should().Be("var myVariable = someLongValue;\n");
920+
}
921+
922+
[TestCase(".gitignore")]
923+
[TestCase(".csharpierignore")]
924+
public void Should_Respect_Ignored_Editor_Config(string ignoreFileName)
925+
{
926+
var context = new TestContext();
927+
context.WhenAFileExists(
928+
".editorconfig",
929+
"""
930+
[*]
931+
max_line_length = 10
932+
"""
933+
);
934+
context.WhenAFileExists(ignoreFileName, ".editorconfig");
935+
var fileName = context.WhenAFileExists("file1.cs", "var myVariable = someLongValue;");
936+
937+
Format(context);
938+
939+
context.GetFileContent(fileName).Should().Be("var myVariable =\n someLongValue;\n");
940+
}
941+
904942
[TestCase("\r\n")]
905943
[TestCase("\n")]
906944
public void Format_XML_With_Multiline_Comment_Uses_Consistent_Line_Breaks(string lineBreak)

Src/CSharpier.Tests/OptionsProviderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ public async Task Should_Ignore_Invalid_EditorConfig_Lines()
719719
}
720720

721721
[Test]
722-
public async Task Should_Ignore_Ignored_EditorConfig()
722+
public async Task Should_Not_Ignore_Ignored_EditorConfig()
723723
{
724724
var context = new TestContext();
725725
context.WhenAFileExists(
@@ -744,7 +744,7 @@ public async Task Should_Ignore_Ignored_EditorConfig()
744744
"c:/test",
745745
"c:/test/subfolder/test.cs"
746746
);
747-
result.IndentSize.Should().Be(1);
747+
result.IndentSize.Should().Be(2);
748748
}
749749

750750
[Test]

0 commit comments

Comments
 (0)