diff --git a/main/src/main/scala/sbt/Keys.scala b/main/src/main/scala/sbt/Keys.scala index 2a75c9901..8170ecfc7 100644 --- a/main/src/main/scala/sbt/Keys.scala +++ b/main/src/main/scala/sbt/Keys.scala @@ -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") diff --git a/main/src/main/scala/sbt/internal/LintUnused.scala b/main/src/main/scala/sbt/internal/LintUnused.scala index ae33b6569..bb549918e 100644 --- a/main/src/main/scala/sbt/internal/LintUnused.scala +++ b/main/src/main/scala/sbt/internal/LintUnused.scala @@ -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