Skip to main content

missing-use-result-annotation

added in: 1.16.0
⚙️🛠
Pro+

Warns when a method or function declaration is missing the @useResult annotation.

@useResult annotation is used by the Dart analyzer to indicate that the value obtained by invoking a declaration should be used.

note

This rule requires configuration in order to highlight any issues.

⚙️ Config

Set type-pattern (default is none) to configure a regular expression for return types that should have the annotation.

Set methods (default is empty) to configure the list of declarations that should have the annotation.

analysis_options.yaml
dart_code_metrics:
rules:
- missing-use-result-annotation:
type-pattern: ^Either<
methods:
- toJson

Example

❌ Bad:

// LINT: Missing a 'useResult' annotation. Try adding it.
Either<Left, Right> either() => ...;

✅ Good:


Either<Left, Right> either() => ...;