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

We started experimenting with Scala and the Play platform in my work. Set up our automatic casting and testing system first, and deployed Scalastyle to handle the first.

This was very useful, except that we are getting this particular lint error, which is hard for us to solve in a good way. A simple example:

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

Although often this can be much more complicated, of course (to the point where it’s hard to understand what the type really is).

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

Unfortunately, setting the expected explicit type here usually causes a syntax error.

Any suggestions for a good solution for this? Or do we just need to enable this check for Play projects?

+5
source share
3 answers

Any suggestions on a good solution for this? Or do we just need to disable this check for Play projects?

I would suggest either to completely disable the rule org.scalastyle.scalariform.PublicMethodsHaveTypeCheckerfor your project, or mark your controllers as ignored by this rule ( here you will find information on how to do this).

, , ( API). , "" , , , , .

+5

enter image description here , . → → Scala → . "" " " . IDE .

+2

" ", .

When defining these methods, you can set body [type] and [ implicit] [type] ; for example, Action [JsValue] and implicit RequestHeader.

Code example:

def helloWorld:Action[JsValue] = Action { 
    implicit req: RequestHeader =>
      Ok("Hello World!")
  }

or

 def helloWorld:Action[AnyContent] = Action { 
    implicit req: RequestHeader =>
      Ok("Hello World!")
  }
0
source

All Articles