6

I'm trying to add Wartremover to my Play project, but it keeps reporting warts on the routes file, even if I exclude it. I'm using Wartremover 0.14 and Play Framework 2.4.6.

The relevant part from my build.sbt:

wartremoverErrors ++= Warts.all
wartremoverExcluded += crossTarget.value / "routes" / "main" / "router" / "Routes.scala"

(Note that I have to do it differently than the answers in this question suggest.)

Without the wartremoverExcluded line, Wartremover reports 13 errors in my routes file. With it, it still reports two: one about Wart.Var and one about Wart.ExplicitImplicitTypes. I can exclude these warts too, but using Warts.allBut(Wart.Var, Wart.ExplicitImplicitTypes), but I'd prefer not to, because that excludes these warts from my entire codebase, not just the routes file.

Is there a way to make Wartremover stop reporting these warts on the route file, without excluding these warts for every file?

Community
  • 1
  • 1
jqno
  • 15,133
  • 7
  • 57
  • 84

2 Answers2

8

Try adding these:

wartremoverExcluded += crossTarget.value / "routes" / "main" / "router" / "Routes.scala"
wartremoverExcluded += crossTarget.value / "routes" / "main" / "router" / "RoutesPrefix.scala"
wartremoverExcluded += crossTarget.value / "routes" / "main" / "controllers" / "ReverseRoutes.scala"
wartremoverExcluded += crossTarget.value / "routes" / "main" / "controllers" / "javascript" / "JavaScriptReverseRoutes.scala"

Edit: It's over a year since I first wrote this answer. wartremoverExcluded has been changed from a SettingKey to a TaskKey, so you can simplify the above to:

wartremoverExcluded ++= routes.in(Compile).value

For sbt 1.4+:

wartremoverExcluded ++= (Compile / routes).value

Or you could try this sbt plugin I wrote to do it for you.

Andrzej Jozwik
  • 14,331
  • 3
  • 59
  • 68
danielnixon
  • 4,178
  • 1
  • 27
  • 39
0

This works for me:

wartremoverExcluded ++= Seq(
  baseDirectory.value / "target" / "scala-2.11" / "src_managed" / "main" / "routes_routing.scala",
  baseDirectory.value / "target" / "scala-2.11" / "src_managed" / "main" / "routes_reverseRouting.scala"
)

(actually I'm on play 2.3, not sure if it's the same on 2.4.6)

Alvaro Carrasco
  • 6,103
  • 16
  • 24
  • I don't have the "src_managed" subdirectory. I guess Play 2.4.6 does it differently :). – jqno Jan 15 '16 at 13:14