Skip to content

Commit

Permalink
add GitAttributes to checks (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 9, 2024
1 parent 5357b9d commit d60b931
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;xUnit1026;xUnit1013;CS1573;VerifyTestsProjectDir;VerifySetParameters;PolyFillTargetsForNuget</NoWarn>
<Version>26.4.0</Version>
<Version>26.4.1</Version>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0</AssemblyVersion>
Expand Down
60 changes: 48 additions & 12 deletions src/Verify/InnerVerifyChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static async Task Run(Assembly assembly)
await CheckEditorConfig(directory);
await CheckGitIgnore(directory);
await CheckIncorrectlyImportedSnapshots(directory);
await CheckGitAttributes(directory);
}

static async Task CheckIncorrectlyImportedSnapshots(string solutionDirectory)
Expand Down Expand Up @@ -51,14 +52,14 @@ This occurs when a test file is copied in the IDE and the IDE incorrectly duplic

static async Task CheckEditorConfig(string solutionDirectory)
{
var editorConfigPath = Path.Combine(solutionDirectory, ".editorconfig");
if (!File.Exists(editorConfigPath))
var path = Path.Combine(solutionDirectory, ".editorconfig");
if (!File.Exists(path))
{
return;
}

editorConfigPath = Path.GetFullPath(editorConfigPath);
var text = await ReadText(editorConfigPath);
path = Path.GetFullPath(path);
var text = await ReadText(path);
if (text.Contains("{received,verified}") ||
text.Contains("# Verify"))
{
Expand All @@ -68,7 +69,7 @@ static async Task CheckEditorConfig(string solutionDirectory)
throw new(
$$"""
Expected .editorconfig to contain settings for Verify.
Path: {{editorConfigPath}}
Path: {{path}}
Recommended settings:

# Verify
Expand All @@ -84,21 +85,56 @@ static async Task CheckEditorConfig(string solutionDirectory)
""");
}

static async Task CheckGitAttributes(string solutionDirectory)
{
var path = Path.Combine(solutionDirectory, ".gitattributes");
if (!File.Exists(path))
{
path = Path.Combine(solutionDirectory, "../.gitattributes");
}

if (!File.Exists(path))
{
return;
}

path = Path.GetFullPath(path);
var text = await ReadText(path);
if (text.Contains("*.verified.") ||
text.Contains("# Verify"))
{
return;
}

throw new(
$"""
Expected .gitattributes to contain settings for Verify.
Path: {path}
Recommended settings:

# Verify
# Extensions should contain all the text files used by snapshots
*.verified.txt text eol=lf working-tree-encoding=UTF-8
*.verified.xml text eol=lf working-tree-encoding=UTF-8
*.verified.json text eol=lf working-tree-encoding=UTF-8
""");
}

static async Task CheckGitIgnore(string solutionDirectory)
{
var gitIgnorePath = Path.Combine(solutionDirectory, ".gitIgnore");
if (!File.Exists(gitIgnorePath))
var path = Path.Combine(solutionDirectory, ".gitIgnore");
if (!File.Exists(path))
{
gitIgnorePath = Path.Combine(solutionDirectory, "../.gitIgnore");
path = Path.Combine(solutionDirectory, "../.gitIgnore");
}

if (!File.Exists(gitIgnorePath))
if (!File.Exists(path))
{
return;
}

gitIgnorePath = Path.GetFullPath(gitIgnorePath);
var text = await ReadText(gitIgnorePath);
path = Path.GetFullPath(path);
var text = await ReadText(path);
if (text.Contains("*.received.*") ||
text.Contains("*.received/") ||
text.Contains("# Verify"))
Expand All @@ -109,7 +145,7 @@ static async Task CheckGitIgnore(string solutionDirectory)
throw new(
$"""
Expected .gitIgnore to contain settings for Verify.
Path: {gitIgnorePath}
Path: {path}
Recommended settings:

# Verify
Expand Down

0 comments on commit d60b931

Please sign in to comment.