Documentation should not just repeat the member name
Configure these rules in your .editorconfig:
[*.cs]# Require summaries to start with capital lettercomment_sense.require_capitalization = true# Require summaries to end with punctuation (. ! ?)comment_sense.require_ending_punctuation = true# Minimum length for summary text (excluding punctuation)comment_sense.min_summary_length = 10# Flag documentation that's too similar to the member namecomment_sense.similarity_threshold = 0.8
Leverage XML documentation tags for semantic meaning:
/// <summary>/// Returns <see langword="true" /> if the value is <see langword="null" />;/// otherwise, <see langword="false" />./// </summary>public bool IsNull(object value) => value == null;
When overriding or implementing base members, prefer <inheritdoc /> to avoid duplication:
public interface IRepository<T>{ /// <summary> /// Retrieves an entity by its unique identifier. /// </summary> /// <param name="id">The unique identifier.</param> /// <returns>The entity, or <see langword="null" /> if not found.</returns> T GetById(int id);}
By default, CommentSense allows implicit documentation inheritance. To require explicit <inheritdoc /> tags:
CommentSense enforces parameter documentation via CSENSE002 and CSENSE004:
/// <summary>/// Calculates the area of a rectangle./// </summary>/// <param name="width">The width of the rectangle in units.</param>/// <param name="height">The height of the rectangle in units.</param>/// <returns>The area in square units.</returns>public double CalculateArea(double width, double height){ return width * height;}
Keep parameter documentation in the same order as the method signature. CommentSense’s CSENSE008 and CSENSE010 enforce this.
CSENSE006 requires <returns> tags for methods that return values (excluding void, Task, and ValueTask):
/// <summary>/// Parses a JSON string into an object./// </summary>/// <param name="json">The JSON string to parse.</param>/// <returns>/// A <typeparamref name="T" /> instance populated from the JSON data./// </returns>/// <exception cref="JsonException">Thrown when the JSON is malformed.</exception>public T Parse<T>(string json) { /* ... */ }
CommentSense scans method bodies for explicitly thrown exceptions (CSENSE012):
/// <summary>/// Divides two numbers./// </summary>/// <param name="dividend">The number to divide.</param>/// <param name="divisor">The number to divide by.</param>/// <returns>The result of the division.</returns>/// <exception cref="ArgumentException">/// Thrown when <paramref name="divisor" /> is zero./// </exception>public double Divide(double dividend, double divisor){ if (divisor == 0) throw new ArgumentException("Divisor cannot be zero.", nameof(divisor)); return dividend / divisor;}
Exclude common exceptions from documentation requirements:
[*.cs]# Ignore specific exception typescomment_sense.ignored_exceptions = ArgumentNullException, ArgumentOutOfRangeException# Ignore all exceptions in System namespacecomment_sense.ignore_system_exceptions = true# Ignore exceptions in specific namespacescomment_sense.ignored_exception_namespaces = MyApp.Internal, System.Data
Use exception ignoring for guard clauses and validation logic that throw standard framework exceptions.
/// <summary></summary>public class Empty { }/// <summary>TODO</summary>public class Todo { }/// <summary>UserRepository</summary>public class UserRepository { }/// <summary>gets the name</summary>public string Name { get; }
Configure low-quality detection:
[*.cs]# Flag these terms as low qualitycomment_sense.low_quality_terms = TODO, TBD, FixMe, None, N/A# Minimum summary length (excluding punctuation)comment_sense.min_summary_length = 15# Require proper capitalizationcomment_sense.require_capitalization = true# Require ending punctuationcomment_sense.require_ending_punctuation = true# Flag summaries too similar to member name (0.0 = off, 1.0 = exact match)comment_sense.similarity_threshold = 0.75
<PropertyGroup> <!-- Treat all warnings as errors in CI --> <TreatWarningsAsErrors Condition="'$(CI)' == 'true'">true</TreatWarningsAsErrors> <!-- Or treat only specific diagnostics as errors --> <WarningsAsErrors>CSENSE001;CSENSE002;CSENSE016</WarningsAsErrors></PropertyGroup>