Filter all watch settings for unused key check

Rather than enumerate all of the watch keys that may appear unused
though they can be used by the `~` command, rework lintUnused to take a
function `String => Boolean` instead of `Set[String] => Boolean`.
This commit is contained in:
Ethan Atkins 2020-06-23 15:51:52 -07:00
parent e323f1f713
commit 33d5bce75a
2 changed files with 16 additions and 6 deletions

View File

@ -534,6 +534,8 @@ object Keys {
@deprecated("No longer used", "1.3.0")
private[sbt] val executeProgress = settingKey[State => TaskProgress]("Experimental task execution listener.").withRank(DTask)
val lintUnused = inputKey[Unit]("Check for keys unused by other settings and tasks.")
val lintIncludeFilter = settingKey[String => Boolean]("Filters key names that should be included in the lint check.")
val lintExcludeFilter = settingKey[String => Boolean]("Filters key names that should be excluded in the lint check.")
val excludeLintKeys = settingKey[Set[Def.KeyedInitialize[_]]]("Keys excluded from lintUnused task")
val includeLintKeys = settingKey[Set[Def.KeyedInitialize[_]]]("Task keys that are included into lintUnused task")
val lintUnusedKeysOnLoad = settingKey[Boolean]("Toggles whether or not to check for unused keys during startup")

View File

@ -17,6 +17,14 @@ import sbt.Def._
object LintUnused {
lazy val lintSettings: Seq[Setting[_]] = Seq(
lintIncludeFilter := {
val includes = includeLintKeys.value.map(_.scopedKey.key.label)
keyName => includes(keyName)
},
lintExcludeFilter := {
val excludes = excludeLintKeys.value.map(_.scopedKey.key.label)
keyName => excludes(keyName) || keyName.startsWith("watch")
},
excludeLintKeys := Set(
aggregate,
concurrentRestrictions,
@ -50,8 +58,8 @@ object LintUnused {
val _ = Def.spaceDelimited().parsed // not used yet
val state = Keys.state.value
val log = streams.value.log
val includeKeys = (includeLintKeys in Global).value map { _.scopedKey.key.label }
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
val includeKeys = (lintIncludeFilter in Global).value
val excludeKeys = (lintExcludeFilter in Global).value
val result = lintUnused(state, includeKeys, excludeKeys)
if (result.isEmpty) log.success("ok")
else lintResultLines(result) foreach { log.warn(_) }
@ -61,8 +69,8 @@ object LintUnused {
def lintUnusedFunc(s: State): State = {
val log = s.log
val extracted = Project.extract(s)
val includeKeys = extracted.get(includeLintKeys in Global) map { _.scopedKey.key.label }
val excludeKeys = extracted.get(excludeLintKeys in Global) map { _.scopedKey.key.label }
val includeKeys = extracted.get(lintIncludeFilter in Global)
val excludeKeys = extracted.get(lintExcludeFilter in Global)
if (extracted.get(lintUnusedKeysOnLoad in Global)) {
val result = lintUnused(s, includeKeys, excludeKeys)
lintResultLines(result) foreach { log.warn(_) }
@ -103,8 +111,8 @@ object LintUnused {
def lintUnused(
state: State,
includeKeys: Set[String],
excludeKeys: Set[String]
includeKeys: String => Boolean,
excludeKeys: String => Boolean
): Seq[(ScopedKey[_], String, Vector[SourcePosition])] = {
val extracted = Project.extract(state)
val structure = extracted.structure