Skip to content

Commit

Permalink
feat(#618): Filter empty and comment lines first
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Oct 23, 2022
1 parent ad68474 commit 99c5eb4
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/Testcontainers/Images/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
// Trim each line.
.Select(line => line.Trim())

// Remove empty line.
.Where(line => !string.IsNullOrEmpty(line))

// Remove comment.
.Where(line => !line.StartsWith("#", StringComparison.Ordinal))

// Exclude files and directories.
.Select(line => line.TrimEnd('/'))

Expand All @@ -45,12 +51,6 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
// Exclude all files and directories (https://github.com/testcontainers/testcontainers-dotnet/issues/618).
.Select(line => "*".Equals(line, StringComparison.OrdinalIgnoreCase) ? "**" : line)

// Remove empty line.
.Where(line => !string.IsNullOrEmpty(line))

// Remove comment.
.Where(line => !line.StartsWith("#", StringComparison.Ordinal))

// Check if the pattern contains an optional prefix ("!"), which negates the pattern.
.Aggregate(new List<KeyValuePair<string, bool>>(), (lines, line) =>
{
Expand Down Expand Up @@ -112,21 +112,7 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
}

/// <summary>
/// Replaces all occurrences of a defined pattern.
/// </summary>
/// <typeparam name="TToReplace">Type of element that is searched and replaced.</typeparam>
private interface ISearchAndReplace<TToReplace>
{
/// <summary>
/// Replaces all occurrences of a defined pattern.
/// </summary>
/// <param name="input">Is searched and replaced.</param>
/// <returns>Returns the input with all replaced occurrences of a defined pattern.</returns>
TToReplace Replace(TToReplace input);
}

/// <summary>
/// Returns true if the file path does not match any ignore pattern.
/// Returns true if the file path does not match any ignore pattern.
/// </summary>
/// <param name="file">Path to check.</param>
/// <returns>True if the file path does not match any ignore pattern, otherwise false.</returns>
Expand All @@ -137,7 +123,7 @@ public bool Accepts(string file)
}

/// <summary>
/// Returns true if the file path matches any ignore pattern.
/// Returns true if the file path matches any ignore pattern.
/// </summary>
/// <param name="file">Path to check.</param>
/// <returns>True if the file path matches any ignore pattern, otherwise false.</returns>
Expand All @@ -147,7 +133,21 @@ public bool Denies(string file)
}

/// <summary>
/// Escapes a set of of metacharacters (-, [, ], /, {, }, (, ), +, ?, ., \, ^, $, |) with their \ codes.
/// Replaces all occurrences of a defined pattern.
/// </summary>
/// <typeparam name="TToReplace">Type of element that is searched and replaced.</typeparam>
private interface ISearchAndReplace<TToReplace>
{
/// <summary>
/// Replaces all occurrences of a defined pattern.
/// </summary>
/// <param name="input">Is searched and replaced.</param>
/// <returns>Returns the input with all replaced occurrences of a defined pattern.</returns>
TToReplace Replace(TToReplace input);
}

/// <summary>
/// Escapes a set of of metacharacters (-, [, ], /, {, }, (, ), +, ?, ., \, ^, $, |) with their \ codes.
/// </summary>
private readonly struct EscapeRegex : ISearchAndReplace<string>
{
Expand All @@ -161,7 +161,7 @@ public string Replace(string input)
}

/// <summary>
/// Searches and replaces a string with recursive wildcards **.
/// Searches and replaces a string with recursive wildcards **.
/// </summary>
private readonly struct PrepareRecursiveWildcards : ISearchAndReplace<string>
{
Expand All @@ -173,7 +173,7 @@ public string Replace(string input)
}

/// <summary>
/// Searches and replaces a string with non recursive wildcards *.
/// Searches and replaces a string with non recursive wildcards *.
/// </summary>
private readonly struct PrepareNonRecursiveWildcards : ISearchAndReplace<string>
{
Expand Down Expand Up @@ -208,7 +208,7 @@ public string Replace(string input)
}

/// <summary>
/// Searches and replaces a string with zero-or-one quantifier ?.
/// Searches and replaces a string with zero-or-one quantifier ?.
/// </summary>
private readonly struct PrepareZeroOrOneQuantifier : ISearchAndReplace<string>
{
Expand Down

0 comments on commit 99c5eb4

Please sign in to comment.