format_comment
This rule flags a comment that does not start with a capital letter or does not end with a period.
By default only doc comments (///) are checked. This rule is in the pedantic preset, since sentence-shaped comments are a house style.
Why use this rule
Section titled “Why use this rule”Effective Dart asks for exactly this of doc comments — start with a one-sentence summary, where a sentence is capitalised and terminated.
The value is not the punctuation itself but the discipline behind it: a fragment that cannot be punctuated as a sentence is usually a label restating the code (/// the user id), which is a comment worth deleting rather than fixing.
A great deal is deliberately exempt, because a comment is also where people legitimately put things that are not prose:
- A line whose first word a tool reads:
ignore,ignore_for_file,TODO,FIXME,HACK,NOTE,coverage,expect. Only the first word is compared, so prose such as “part of what happened.” is still prose. - A line that is a bare URL, a
{@template}macro, or an indented code sample. - A fenced code block inside a doc comment.
- A line opening on an identifier — backticked,
[bracketed], or bare. Capitalisingdart_frogorrunAppwould falsify the name. - Every line but the first and last of a block, since only the first starts the sentence and only the last ends it.
A sentence may end with ., !, ? or : followed by closing backticks, quotes, parentheses, brackets, * or _, so ... (see §3.5). and a sentence ending in a code span both pass.
See also: Effective Dart: documentation
/// a user of the system.class User {}
/// A user of the systemclass User {}/// A user of the system.class User {}
/// A user of the system, holding the identity that every other record/// in the database ultimately points back to.class User {}
/// dart_frog mounts a dynamic route before its static siblings.class Router {}Options
Section titled “Options”many_lints: rules: format_comment: check_regular_comments: truerules: format_comment: check_regular_comments: true| Option | Type | Default | Description |
|---|---|---|---|
check_regular_comments |
bool | false |
Also hold // comments to the same shape, not just /// |
Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: format_comment: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”double_literal_format— Write double literals with exactly one leading zero and no redundant trailing zeros.avoid_inconsistent_digit_separators— Group digit separators at a regular interval.format_test_name— Hold test descriptions to a house pattern.always_pass_global_key— Don’t create a GlobalKey inside build.