From 5851f13b6175c515e5813a5671d803cda89389b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Ol=C4=99dzki?= Date: Wed, 14 Oct 2020 22:35:17 +0200 Subject: [PATCH] Fixes #340. Excusing arguments annotated with @unused --- .../inspections/unneccesary/UnusedMethodParameter.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala index 12f8d366..74fad3ed 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala @@ -43,6 +43,9 @@ class UnusedMethodParameter } } + private def isParameterExcused(param: ValDef): Boolean = + param.symbol.annotations.exists(_.atp.toString == "scala.annotation.unused") + /** * For constructor params, some params become vals / fields of the class: * 1. all params in the first argument list for case classes @@ -109,8 +112,9 @@ class UnusedMethodParameter for { vparams <- vparamss vparam <- vparams - } if (!usesParameter(vparam.name.toString, rhs)) + } if (!isParameterExcused(vparam) && !usesParameter(vparam.name.toString, rhs)) { context.warn(tree.pos, self, s"Unused method parameter ($vparam).") + } case _ => continue(tree) } }