scalaplayframeworkplayframework-2.0scalastyle

Scalastyle "Public method must have explicit type" in Play Framework


We've started experimenting with Scala and the Play framework at my work. Setup our auto-linting and testing framework as the first thing, and have deployed Scalastyle to handle the former.

That has been very useful, except that we are getting this specific lint error that we are finding it difficult to resolve in a good way. A simple example is this:

  def helloWorld = Action {
    req =>
      Ok("Hello World!")
  }

Though often it can be much more complex, of course (to the point where it can difficult to figure out what the type actually is).

In either case, this gives us the "Public method must have explicit type" error from Scalastyle.

Unfortunately, setting the expected explicit type here seems typically to cause a syntax error.

Any suggestions on a good solution for this? Or do we just have to turn of this check for Play projects?


Solution

  • Any suggestions on a good solution for this? Or do we just have to turn of this check for Play projects?

    I'd suggest to either turn org.scalastyle.scalariform.PublicMethodsHaveTypeChecker rule off completely for your project or mark your controllers to be ignored by this rule (here you'll find info on how to do this).

    In the end this check benefit more to people who write libraries (as it helps to be more explicit about api one provide). I found that when you're working on "real" projects check like this does nothing but adding some boilerplate and stops you from leveraging type inference.