Skip to main content

format-comment

added in: 1.6.0
⚙️🛠
Pro+

Suggests formatting comments like sentences.

⚙️ Config

Set ignored-patterns (default is empty) to ignore comments that match the given regular expressions.

Set only-doc-comments (default is false) to check only documentation comments (///).

analysis_options.yaml
dart_code_metrics:
rules:
- format-comment:
only-doc-comments: false
ignored-patterns:
- ^ cSpell.* # Ignores all the comments that start with 'cSpell' (for example: '// cSpell:disable-next-line').

Example

❌ Bad:

// prefer format comments like sentences // LINT: Prefer formatting comments like sentences.
class Test {
/// with start space with dot. // LINT: Prefer formatting comments like sentences.
Test() {
// with start space with dot. // LINT: Prefer formatting comments like sentences.
}

/// With start space without dot // LINT: Prefer formatting comments like sentences.
function() {
//Without start space without dot // LINT: Prefer formatting comments like sentences.
}
}
/* prefer format comments
like sentences */ // LINT: Prefer formatting comments like sentences.

✅ Good:

// Prefer format comments like sentences.
class Test {
/// With start space with dot.
Test() {
// With start space with dot.
}

/// With start space without dot.
function() {
// Without start space without dot.
}
}
/* Prefer format comments
like sentences. */