Skip to content

BRO1603: Documentation text should end with a period

Summary, remarks, parameter, type parameter, return value, value and exception text are sentences and end with a period. Replaces StyleCop SA1629.

Example

Before

public class Prices
{
    /// <summary>Applies a discount</summary>
    /// <param name="price">The full price</param>
    /// <returns>The discounted price, see <see cref="Prices"/></returns>
    public decimal Discount(decimal price) => price * 0.9m;
}

After

public class Prices
{
    /// <summary>Applies a discount.</summary>
    /// <param name="price">The full price.</param>
    /// <returns>The discounted price, see <see cref="Prices"/>.</returns>
    public decimal Discount(decimal price) => price * 0.9m;
}

Why

Consistent punctuation makes generated documentation and IntelliSense read as prose, and it's the convention in the .NET documentation.

How the fix works

A period is added right after the last text, or after an inline element at the end (<see cref="..."/>, <c>). A trailing space stays after the period.

An inline element at the end whose own text ends in ? or ! is a finished question or exclamation of its own. It is passed over, and the text before it is the sentence that is checked: Asks the user <c>Is it done?</c> becomes Asks the user. <c>Is it done?</c>. Closing quotes and one ) may follow the ? or ! (<c>"Really?"</c>, <i>(or is it?)</i>). <c> holds code, so there only text with a space in it or a quoted text counts: one word such as <c>int?</c> or <c>value!</c> is a type or an expression and stays the sentence's last word (Returns an <c>int?</c>.).

This rule reads documentation as XML, which the compiler only does when the project generates documentation (<GenerateDocumentationFile>true</GenerateDocumentationFile>).

Not reported

  • Text that ends with ?, ! or :. A question, an exclamation or an introduction is a finished sentence.
  • Text that ends with , or ; (1033 => "en",, value;): a line of code or a list that goes on.
  • A period followed only by closing punctuation: (see above.), "done.", 'done.', [note.].
  • Text that ends with a block element, like a list or a code sample.
  • Empty elements.
  • Text that is only a number (<summary>0</summary> on an enum member, 0x1F): a value, not a sentence.
  • Text whose last word ends in a period and digits (Supports HTML 5.0): a period after it reads as part of the number.
  • Text that ends with an inline element whose own text ends with a period: <paramref name="name">The name of the request.</paramref>. In <c>, which holds code, only a quoted sentence counts (<c>"User logged in."</c>); Calls <c>Done.</c> gets its period.
  • Text that is only an inline element ending in ? or ! (<summary><c>It works!</c></summary>), or where the text before such an element is a finished sentence already (Asks the user: <c>Is it done?</c>).
  • Events and finalizers: their documentation isn't checked.
  • Text that ends in code: its last word contains a bracket, brace, =, ;, :, a slash, |, $, #, _ or a backtick (digraph {, Example: A1:B10, Run(x), a URL), or it follows an operator on its line (=> 0, x == null). A period would read as part of the code. A closing ) without its ( in the word ends a parenthetical and still gets the period ((in ms).). A quoted literal at the end that reads as code is code too: followed by ;, with an escape, or a punctuation char (Default is ',';, Usually "\r\n", The separator ','); a quoted word (the word "done") still gets its period.
  • Unknown elements are passed over: the text before them counts. Text that ends with <devremarks>...</devremarks> (vs-threading) is checked where the sentence before it ends, and gets no period after the element. The period goes after an inline element: <c>, <see>, <paramref>, <typeparamref>, and HTML's <a>, <b>, <i>, <u>, <em>, <strong>, <sub>, <sup>, <span>, <tt>.
  • Tags named in stylebro_exclude_from_punctuation_check (see Configuration).
  • Documentation whose XML is malformed: IComparable<T> in prose opens an element T that takes the summary's end tag, and a bare < (when a < b) opens an element that never closes, so where the text ends is a guess. A bare & that starts no entity (this & that) is malformed too (the compiler reports CS1570). Write a &lt; b, &amp;, IComparable&lt;T&gt; or <see cref="IComparable{T}"/>, then the rule checks it again. The other rules that edit documentation (BRO1604-BRO1614, BRO1616-BRO1619) skip it too.

Text that ends in an XML entity (List&lt;T&gt;) gets the period after the entity. Spaces between the text and a closing tag on the same line make way for the period: evaluates to true </returns> becomes evaluates to true.</returns>, not true. </returns>.

Configuration

[*.cs]
# Tags whose text isn't checked, comma-separated (default: seealso)
stylebro_exclude_from_punctuation_check = seealso, example
# Enum members' documentation isn't checked (default: true, checked)
stylebro_punctuation_check_enum_members = false

stylebro_punctuation_check_enum_members = false leaves enum members' documentation alone; bro migrate writes it when the analyzer version it migrates from doesn't check them.

bro migrate writes stylebro_exclude_from_punctuation_check from stylecop.json when a team changed it. An excluded tag isn't checked at the top level or nested (an excluded para inside a summary). The rule checks summary, remarks, param, typeparam, returns, value and exception anyway, so seealso is never checked, set or not.