Skip to content

Commit 176eb45

Browse files
committed
refactor: make ScopeHandler a sealed class to drop untestable equality members
ScopeHandler was a readonly struct implementing IEquatable<T> with Equals, GetHashCode and ==/!= operators that no test can reach, since Scope() and ScopeLine() only expose IDisposable. They showed up as NoCoverage mutants in Stryker. A private sealed class needs none of them.
1 parent 0caae59 commit 176eb45

1 file changed

Lines changed: 4 additions & 40 deletions

File tree

‎src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Scope.cs‎

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ public IDisposable ScopeLine(string? value)
5050
}
5151

5252
/// <summary>
53-
/// A disposable struct that manages indentation scope for a <see cref="CSharpCodeBuilder"/>.
53+
/// A disposable class that manages indentation scope for a <see cref="CSharpCodeBuilder"/>.
5454
/// </summary>
5555
/// <remarks>
56-
/// This struct increments the indentation level when created and decrements it when disposed.
56+
/// This class increments the indentation level when created and decrements it when disposed.
5757
/// It is designed to work with the 'using' statement to provide automatic indentation management.
5858
/// </remarks>
59-
private readonly struct ScopeHandler : IDisposable, IEquatable<ScopeHandler>
59+
private sealed class ScopeHandler : IDisposable
6060
{
6161
private readonly CSharpCodeBuilder _builder;
6262

6363
/// <summary>
64-
/// Initializes a new instance of the <see cref="ScopeHandler"/> struct and increments the indentation level.
64+
/// Initializes a new instance of the <see cref="ScopeHandler"/> class and increments the indentation level.
6565
/// </summary>
6666
/// <param name="builder">The <see cref="CSharpCodeBuilder"/> instance to manage indentation for.</param>
6767
internal ScopeHandler(CSharpCodeBuilder builder)
@@ -77,41 +77,5 @@ internal ScopeHandler(CSharpCodeBuilder builder)
7777
/// This method is called automatically when the 'using' statement block ends.
7878
/// </remarks>
7979
public void Dispose() => _ = _builder.Append('}');
80-
81-
/// <summary>
82-
/// Determines whether the specified object is equal to the current instance.
83-
/// </summary>
84-
/// <param name="obj">The object to compare with the current instance.</param>
85-
/// <returns>Always returns <see langword="false"/> since ScopeHandler instances should not be compared.</returns>
86-
public override readonly bool Equals(object? obj) => false;
87-
88-
/// <summary>
89-
/// Determines whether the specified ScopeHandler is equal to the current instance.
90-
/// </summary>
91-
/// <param name="other">The ScopeHandler to compare with the current instance.</param>
92-
/// <returns>Always returns <see langword="false"/> since ScopeHandler instances should not be compared.</returns>
93-
public readonly bool Equals(ScopeHandler other) => false;
94-
95-
/// <summary>
96-
/// Returns the hash code for this instance.
97-
/// </summary>
98-
/// <returns>A hash code based on the internal builder reference.</returns>
99-
public override readonly int GetHashCode() => _builder?.GetHashCode() ?? 0;
100-
101-
/// <summary>
102-
/// Determines whether two ScopeHandler instances are equal.
103-
/// </summary>
104-
/// <param name="_">The first instance to compare.</param>
105-
/// <param name="__">The second instance to compare.</param>
106-
/// <returns>Always returns <see langword="false"/> since ScopeHandler instances should not be compared.</returns>
107-
public static bool operator ==(ScopeHandler _, ScopeHandler __) => false;
108-
109-
/// <summary>
110-
/// Determines whether two ScopeHandler instances are not equal.
111-
/// </summary>
112-
/// <param name="_">The first instance to compare.</param>
113-
/// <param name="__">The second instance to compare.</param>
114-
/// <returns>Always returns <see langword="true"/> since ScopeHandler instances should not be compared.</returns>
115-
public static bool operator !=(ScopeHandler _, ScopeHandler __) => true;
11680
}
11781
}

0 commit comments

Comments
 (0)