From 2e027640d337e860529afc8b599f01021343f42e Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Mon, 10 Dec 2018 15:20:39 -0800 Subject: [PATCH] Add solutions for dynamic task evaluation There are many cases where one would want to force evaluation of the task even when contained in a lambda (see https://github.com/sbt/sbt/issues/3266). The @sbtUnchecked annotation is one way to disable the linter that prevents this, but it is obscure. If the annotation is to exist, I think it should be presented as a solution. --- main-settings/src/main/scala/sbt/std/TaskLinterDSL.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main-settings/src/main/scala/sbt/std/TaskLinterDSL.scala b/main-settings/src/main/scala/sbt/std/TaskLinterDSL.scala index 7d037db39..ef535f274 100644 --- a/main-settings/src/main/scala/sbt/std/TaskLinterDSL.scala +++ b/main-settings/src/main/scala/sbt/std/TaskLinterDSL.scala @@ -189,6 +189,7 @@ object TaskLinterDSLFeedback { |$SolutionHeader: | 1. Make `$task` evaluation explicit outside of the function body if you don't care about its evaluation. | 2. Use a dynamic task to evaluate `$task` and pass that value as a parameter to an anonymous function. + | 3. Annotate the `$task` evaluation with `@sbtUnchecked`, e.g. `($task.value: @sbtUnchecked)`. """.stripMargin def useOfValueInsideIfExpression(task: String): String = @@ -198,7 +199,8 @@ object TaskLinterDSLFeedback { | Regular tasks always evaluate task inside the bodies of if expressions. |$SolutionHeader: | 1. If you only want to evaluate it when the if predicate is true or false, use a dynamic task. - | 2. Otherwise, make the static evaluation explicit by evaluating `$task` outside the if expression. + | 2. Make the static evaluation explicit by evaluating `$task` outside the if expression. + | 3. If you still want to force the static evaluation, you may annotate the task evaluation with `@sbtUnchecked`, e.g. `($task.value: @sbtUnchecked)`. """.stripMargin def missingValueForKey(key: String): String =