mirror of https://github.com/sbt/sbt.git
Merge pull request #5645 from eatkins/watch-excludes
Filter all watch settings for unused key check
This commit is contained in:
commit
e7c3b675e9
|
|
@ -534,6 +534,8 @@ object Keys {
|
||||||
@deprecated("No longer used", "1.3.0")
|
@deprecated("No longer used", "1.3.0")
|
||||||
private[sbt] val executeProgress = settingKey[State => TaskProgress]("Experimental task execution listener.").withRank(DTask)
|
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 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 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 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")
|
val lintUnusedKeysOnLoad = settingKey[Boolean]("Toggles whether or not to check for unused keys during startup")
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,14 @@ import sbt.Def._
|
||||||
|
|
||||||
object LintUnused {
|
object LintUnused {
|
||||||
lazy val lintSettings: Seq[Setting[_]] = Seq(
|
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(
|
excludeLintKeys := Set(
|
||||||
aggregate,
|
aggregate,
|
||||||
concurrentRestrictions,
|
concurrentRestrictions,
|
||||||
|
|
@ -50,8 +58,8 @@ object LintUnused {
|
||||||
val _ = Def.spaceDelimited().parsed // not used yet
|
val _ = Def.spaceDelimited().parsed // not used yet
|
||||||
val state = Keys.state.value
|
val state = Keys.state.value
|
||||||
val log = streams.value.log
|
val log = streams.value.log
|
||||||
val includeKeys = (includeLintKeys in Global).value map { _.scopedKey.key.label }
|
val includeKeys = (lintIncludeFilter in Global).value
|
||||||
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
|
val excludeKeys = (lintExcludeFilter in Global).value
|
||||||
val result = lintUnused(state, includeKeys, excludeKeys)
|
val result = lintUnused(state, includeKeys, excludeKeys)
|
||||||
if (result.isEmpty) log.success("ok")
|
if (result.isEmpty) log.success("ok")
|
||||||
else lintResultLines(result) foreach { log.warn(_) }
|
else lintResultLines(result) foreach { log.warn(_) }
|
||||||
|
|
@ -61,8 +69,8 @@ object LintUnused {
|
||||||
def lintUnusedFunc(s: State): State = {
|
def lintUnusedFunc(s: State): State = {
|
||||||
val log = s.log
|
val log = s.log
|
||||||
val extracted = Project.extract(s)
|
val extracted = Project.extract(s)
|
||||||
val includeKeys = extracted.get(includeLintKeys in Global) map { _.scopedKey.key.label }
|
val includeKeys = extracted.get(lintIncludeFilter in Global)
|
||||||
val excludeKeys = extracted.get(excludeLintKeys in Global) map { _.scopedKey.key.label }
|
val excludeKeys = extracted.get(lintExcludeFilter in Global)
|
||||||
if (extracted.get(lintUnusedKeysOnLoad in Global)) {
|
if (extracted.get(lintUnusedKeysOnLoad in Global)) {
|
||||||
val result = lintUnused(s, includeKeys, excludeKeys)
|
val result = lintUnused(s, includeKeys, excludeKeys)
|
||||||
lintResultLines(result) foreach { log.warn(_) }
|
lintResultLines(result) foreach { log.warn(_) }
|
||||||
|
|
@ -103,8 +111,8 @@ object LintUnused {
|
||||||
|
|
||||||
def lintUnused(
|
def lintUnused(
|
||||||
state: State,
|
state: State,
|
||||||
includeKeys: Set[String],
|
includeKeys: String => Boolean,
|
||||||
excludeKeys: Set[String]
|
excludeKeys: String => Boolean
|
||||||
): Seq[(ScopedKey[_], String, Vector[SourcePosition])] = {
|
): Seq[(ScopedKey[_], String, Vector[SourcePosition])] = {
|
||||||
val extracted = Project.extract(state)
|
val extracted = Project.extract(state)
|
||||||
val structure = extracted.structure
|
val structure = extracted.structure
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue