use_to_and_as_if_applicable

Group: style

Maturity: stable

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

View the Project on GitHub dart-lang/linter

From the design guide:

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 new Foo.from(this);
  }
}

GOOD:

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

GOOD:

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