Skip to content

Commit

Permalink
Merge branch 'fix-extension-convention-checks'
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Sep 10, 2024
2 parents b8dc334 + 4560dd1 commit 22a1257
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/Verify.Tests/InnerVerifyChecksTests/Superset/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true
# EditorConfig: http://EditorConfig.org

# top-most EditorConfig file

# Verify settings
[*.{received,verified}.{html,txt,xml}]
charset = "utf-8-bom"
end_of_line = lf
indent_size = unset
indent_style = unset
insert_final_newline = false
tab_width = unset
trim_trailing_whitespace = false
12 changes: 12 additions & 0 deletions src/Verify.Tests/InnerVerifyChecksTests/Superset/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* text
*.snk binary
*.png binary
*.bmp binary
*.tif binary
*.zip binary


*.verified.txt text eol=lf working-tree-encoding=UTF-8
*.verified.html text eol=lf working-tree-encoding=UTF-8
*.verified.xml text eol=lf working-tree-encoding=UTF-8

10 changes: 10 additions & 0 deletions src/Verify.Tests/InnerVerifyChecksTests/Superset/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.suo
*.user
bin/
obj/
.vs/
*.DotSettings.user
.idea/
*.received.*

*.received/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

</Project>
4 changes: 4 additions & 0 deletions src/Verify.Tests/InnerVerifyChecksTests/VerifyChecksTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ static VerifyChecksTests()
partialDirectory = GetDirectory("Partial");
}

[Fact]
public Task Superset() =>
InnerVerifyChecks.Run(GetDirectory("Superset"));

[Fact]
public Task Valid() =>
InnerVerifyChecks.Run(GetDirectory("Valid"));
Expand Down
27 changes: 23 additions & 4 deletions src/Verify/ConventionCheck/InnerVerifyChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ internal static async Task CheckEditorConfig(string solutionDirectory, List<stri
}

path = Path.GetFullPath(path);
var text = await ReadText(path);
var lines = await ReadLines(path);

var headerLine = $"[*.{{received,verified}}.{{{StringPolyfill.Join(',', extensions)}}}]";
if (text.Contains(headerLine))
if (HasAllExtensions(extensions, lines))
{
return;
}
Expand All @@ -93,7 +92,7 @@ internal static async Task CheckEditorConfig(string solutionDirectory, List<stri
Recommended settings:
# Verify
{headerLine}
{$"[*.{{received,verified}}.{{{StringPolyfill.Join(',', extensions)}}}]"}
charset = "utf-8-bom"
end_of_line = lf
indent_size = unset
Expand All @@ -104,6 +103,26 @@ internal static async Task CheckEditorConfig(string solutionDirectory, List<stri
""");
}

static bool HasAllExtensions(List<string> extensions, string[] lines)
{
var line = lines.SingleOrDefault(_ => _.StartsWith("[*.{received,verified}."));
if (line == null)
{
return false;
}

var suffix = line[24..^2].Split(',');
foreach (var extension in extensions)
{
if (!suffix.Contains(extension))
{
return false;
}
}

return true;
}

internal static async Task CheckGitAttributes(string solutionDirectory, List<string> extensions)
{
var path = Path.Combine(solutionDirectory, ".gitattributes");
Expand Down

0 comments on commit 22a1257

Please sign in to comment.