Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 406
Michael A. Avatar asked Feb 26 '15 12:02

Michael A.


2 Answers

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.

like image 163
Eugene Loy Avatar answered Nov 08 '22 16:11

Eugene Loy


enter image description here I hope this helps. To to Settings -> Editor -> Scala -> Type Annotations. Change the value to 'Add' instead of 'Add & Check' for Public value and method. Then it IDE will not show that warning anymore.

like image 23
Rajashree Gr Avatar answered Nov 08 '22 17:11

Rajashree Gr