From 805fa002a7b457a9325729ffd2224c09e608bf72 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sun, 17 Nov 2019 17:58:20 -0800 Subject: [PATCH] Only print unused setting warning if there are any --- .../main/scala/sbt/internal/LintUnused.scala | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/main/src/main/scala/sbt/internal/LintUnused.scala b/main/src/main/scala/sbt/internal/LintUnused.scala index 668693381..625db4ea1 100644 --- a/main/src/main/scala/sbt/internal/LintUnused.scala +++ b/main/src/main/scala/sbt/internal/LintUnused.scala @@ -70,26 +70,29 @@ object LintUnused { import scala.collection.mutable.ListBuffer val buffer = ListBuffer.empty[String] - val size = result.size - if (size == 1) buffer.append("there's a key that's not used by any other settings/tasks:") - else buffer.append(s"there are $size keys that are not used by any other settings/tasks:") - buffer.append(" ") - result foreach { - case (_, str, positions) => - buffer.append(s"* $str") - positions foreach { - case pos: FilePosition => buffer.append(s" +- ${pos.path}:${pos.startLine}") - case _ => () - } + if (result.isEmpty) Vector.empty + else { + val size = result.size + if (size == 1) buffer.append("there's a key that's not used by any other settings/tasks:") + else buffer.append(s"there are $size keys that are not used by any other settings/tasks:") + buffer.append(" ") + result foreach { + case (_, str, positions) => + buffer.append(s"* $str") + positions foreach { + case pos: FilePosition => buffer.append(s" +- ${pos.path}:${pos.startLine}") + case _ => () + } + } + buffer.append(" ") + buffer.append( + "note: a setting might still be used by a command; to exclude a key from this `lintUnused` check" + ) + buffer.append( + "either append it to `Global / excludeLintKeys` or call .withRank(KeyRanks.Invisible) on the key" + ) + buffer.toVector } - buffer.append(" ") - buffer.append( - "note: a setting might still be used by a command; to exclude a key from this `lintUnused` check" - ) - buffer.append( - "either append it to `Global / excludeLintKeys` or call .withRank(KeyRanks.Invisible) on the key" - ) - buffer.toVector } def lintUnused(