Skip to content

Commit 65a5943

Browse files
committed
fix: IsFileDataLengthEqual and rename it to AreFilesEqual
1 parent 3ed0f17 commit 65a5943

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/Atc.CodingRules.Updater/DirectoryBuildPropsHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void HandleFile(
6868
return;
6969
}
7070

71-
if (FileHelper.IsFileDataLengthEqual(contentGit, contentFile) &&
71+
if (FileHelper.AreFilesEqual(contentGit, contentFile) &&
7272
contentGit.Equals(contentFile, StringComparison.Ordinal))
7373
{
7474
logger.LogInformation($"{EmojisConstants.FileNotUpdated} {descriptionPart} nothing to update");
@@ -141,7 +141,7 @@ private static void UpdateFile(
141141
if (useLatestMinorNugetVersion)
142142
{
143143
var newFileContent = EnsureLatestPackageReferencesVersion(logger, fileContent, LogCategoryType.Debug);
144-
if (!FileHelper.IsFileDataLengthEqual(fileContent, newFileContent) ||
144+
if (!FileHelper.AreFilesEqual(fileContent, newFileContent) ||
145145
!fileContent.Equals(newFileContent, StringComparison.Ordinal))
146146
{
147147
fileContent = newFileContent;

src/Atc.CodingRules.Updater/EditorConfigHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void HandleFile(
6767

6868
try
6969
{
70-
if (FileHelper.IsFileDataLengthEqual(contentGit, contentFile))
70+
if (FileHelper.AreFilesEqual(contentGit, contentFile))
7171
{
7272
logger.LogInformation($"{EmojisConstants.FileNotUpdated} {descriptionPart} nothing to update");
7373
return;
@@ -82,7 +82,7 @@ public static void HandleFile(
8282
var contentGitBasePart = ExtractContentBasePart(contentGit);
8383
var contentFileBasePart = ExtractContentBasePart(contentFile);
8484

85-
if (FileHelper.IsFileDataLengthEqual(contentGitBasePart, contentFileBasePart))
85+
if (FileHelper.AreFilesEqual(contentGitBasePart, contentFileBasePart))
8686
{
8787
logger.LogInformation($"{EmojisConstants.FileNotUpdated} {descriptionPart} nothing to update");
8888
return;

src/Atc.CodingRules.Updater/FileHelper.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ReSharper disable ConvertIfStatementToReturnStatement
12
namespace Atc.CodingRules.Updater;
23

34
public static class FileHelper
@@ -51,7 +52,7 @@ public static void CreateFile(
5152
logger.LogInformation($"{EmojisConstants.FileCreated} {descriptionPart} created");
5253
}
5354

54-
public static bool IsFileDataLengthEqual(
55+
public static bool AreFilesEqual(
5556
string dataA,
5657
string dataB)
5758
{
@@ -61,7 +62,35 @@ public static bool IsFileDataLengthEqual(
6162
var l1 = dataA.EnsureEnvironmentNewLines().Length;
6263
var l2 = dataB.EnsureEnvironmentNewLines().Length;
6364

64-
return l1.Equals(l2);
65+
var isSameFileLength = l1.Equals(l2);
66+
if (!isSameFileLength)
67+
{
68+
return false;
69+
}
70+
71+
var headerLinesA = dataA.ToLines().Take(10).ToList();
72+
var headerLinesB = dataB.ToLines().Take(10).ToList();
73+
74+
if (headerLinesA.Find(x => x.StartsWith("# Version", StringComparison.CurrentCultureIgnoreCase)) !=
75+
headerLinesB.Find(x => x.StartsWith("# Version", StringComparison.CurrentCultureIgnoreCase)))
76+
{
77+
return false;
78+
}
79+
80+
if (headerLinesA.Find(x => x.StartsWith("# Updated", StringComparison.CurrentCultureIgnoreCase)) !=
81+
headerLinesB.Find(x => x.StartsWith("# Updated", StringComparison.CurrentCultureIgnoreCase)))
82+
{
83+
return false;
84+
}
85+
86+
if (headerLinesA.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)) !=
87+
headerLinesB.Find(x => x.StartsWith("# Distribution", StringComparison.CurrentCultureIgnoreCase)))
88+
{
89+
return false;
90+
}
91+
92+
return true;
93+
6594
}
6695

6796
public static bool ContainsEditorConfigFile(

0 commit comments

Comments
 (0)