avoid_returning_this

Group: style

Maturity: stable

Dart SDK: >= 2.0.0 • (Linter v0.1.31)

Since info is static, may be stale

View all Lint Rules

Using the Linter

AVOID returning this from methods just to enable a fluent interface.

Returning this from a method is redundant; Dart has a cascade operator which allows method chaining universally.

Returning this is allowed for:

BAD:

var buffer = StringBuffer()
  .write('one')
  .write('two')
  .write('three');

GOOD:

var buffer = StringBuffer()
  ..write('one')
  ..write('two')
  ..write('three');

Usage

To enable the avoid_returning_this lint, add avoid_returning_this under linter > rules in your analysis_options.yaml file:

linter:
  rules:
    - avoid_returning_this