use_to_and_as_if_applicable

Group: style

Maturity: stable

Linter v0.1.31

Since info is static, may be stale

View all Lint Rules

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

GOOD:

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

GOOD:

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