DeepSource has joined Harness. Learn more
Dart Analyze logoDart Analyze/
DRT-W1209

Start the name of the method with to/_to or as/_as if applicableDRT-W1209

Major severityMajor
Anti-pattern categoryAnti-pattern

From Effective Dart:

PREFER naming a method to___() if it copies the object's state to a new object.

PREFER naming a method as___() if it returns a different representation backed by the original object.

BAD:

class Bar {
  Foo myMethod() {
    return Foo.from(this);
  }
}

GOOD:

class Bar {
  Foo toFoo() {
    return Foo.from(this);
  }
}

GOOD:

class Bar {
  Foo asFoo() {
    return Foo.from(this);
  }
}