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

add GitAttributes to checks #1286

Merged
merged 1 commit into from
Sep 9, 2024
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
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
Loading