mirror of https://github.com/sbt/sbt.git
Rename to lintUnused for clarification
Address other review comments
This commit is contained in:
parent
3a96ffa2cf
commit
460d1f5aa7
|
|
@ -351,7 +351,7 @@ object Defaults extends BuildCommon {
|
||||||
sys.env.contains("CI") || SysProp.ci,
|
sys.env.contains("CI") || SysProp.ci,
|
||||||
// watch related settings
|
// watch related settings
|
||||||
pollInterval :== Watch.defaultPollInterval,
|
pollInterval :== Watch.defaultPollInterval,
|
||||||
) ++ LintBuild.lintSettings
|
) ++ LintUnused.lintSettings
|
||||||
)
|
)
|
||||||
|
|
||||||
def defaultTestTasks(key: Scoped): Seq[Setting[_]] =
|
def defaultTestTasks(key: Scoped): Seq[Setting[_]] =
|
||||||
|
|
|
||||||
|
|
@ -491,9 +491,9 @@ object Keys {
|
||||||
private[sbt] val postProgressReports = settingKey[Unit]("Internally used to modify logger.").withRank(DTask)
|
private[sbt] val postProgressReports = settingKey[Unit]("Internally used to modify logger.").withRank(DTask)
|
||||||
@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 lintBuild = inputKey[Unit]("Stop a background job by providing its ID.")
|
val lintUnused = inputKey[Unit]("Check for keys unused by other settings and tasks.")
|
||||||
val excludeLintKeys = settingKey[Set[Def.KeyedInitialize[_]]]("Keys excluded from lintBuild task")
|
val excludeLintKeys = settingKey[Set[Def.KeyedInitialize[_]]]("Keys excluded from lintUnused task")
|
||||||
val includeLintKeys = settingKey[Set[Def.KeyedInitialize[_]]]("Task keys that are included into lintBuild task")
|
val includeLintKeys = settingKey[Set[Def.KeyedInitialize[_]]]("Task keys that are included into lintUnused task")
|
||||||
|
|
||||||
val stateStreams = AttributeKey[Streams]("stateStreams", "Streams manager, which provides streams for different contexts. Setting this on State will override the default Streams implementation.")
|
val stateStreams = AttributeKey[Streams]("stateStreams", "Streams manager, which provides streams for different contexts. Setting this on State will override the default Streams implementation.")
|
||||||
val resolvedScoped = Def.resolvedScoped
|
val resolvedScoped = Def.resolvedScoped
|
||||||
|
|
|
||||||
|
|
@ -852,7 +852,7 @@ object BuiltinCommands {
|
||||||
.setProject(session, structure, s2)
|
.setProject(session, structure, s2)
|
||||||
.put(sbt.nio.Keys.hasCheckedMetaBuild, new AtomicBoolean(false))
|
.put(sbt.nio.Keys.hasCheckedMetaBuild, new AtomicBoolean(false))
|
||||||
)
|
)
|
||||||
LintBuild.lintBuildFunc(s3)
|
LintUnused.lintUnusedFunc(s3)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val addCacheStoreFactoryFactory: State => State = (s: State) => {
|
private val addCacheStoreFactoryFactory: State => State = (s: State) => {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import java.io.File
|
||||||
import Scope.Global
|
import Scope.Global
|
||||||
import sbt.Def._
|
import sbt.Def._
|
||||||
|
|
||||||
object LintBuild {
|
object LintUnused {
|
||||||
lazy val lintSettings: Seq[Setting[_]] = Seq(
|
lazy val lintSettings: Seq[Setting[_]] = Seq(
|
||||||
excludeLintKeys := Set(
|
excludeLintKeys := Set(
|
||||||
aggregate,
|
aggregate,
|
||||||
|
|
@ -32,31 +32,34 @@ object LintBuild {
|
||||||
incOptions,
|
incOptions,
|
||||||
compileOptions,
|
compileOptions,
|
||||||
packageOptions,
|
packageOptions,
|
||||||
|
mainClass,
|
||||||
mappings,
|
mappings,
|
||||||
testOptions,
|
testOptions,
|
||||||
|
classpathConfiguration,
|
||||||
|
ivyConfiguration,
|
||||||
),
|
),
|
||||||
lintBuild := lintBuildTask.evaluated,
|
Keys.lintUnused := lintUnusedTask.evaluated,
|
||||||
)
|
)
|
||||||
|
|
||||||
// input task version of the lintBuild
|
// input task version of the lintUnused
|
||||||
def lintBuildTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
|
def lintUnusedTask: Def.Initialize[InputTask[Unit]] = Def.inputTask {
|
||||||
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 = (includeLintKeys in Global).value map { _.scopedKey.key.label }
|
||||||
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
|
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
|
||||||
val result = lint(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(_) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// function version of the lintBuild, based on just state
|
// function version of the lintUnused, based on just state
|
||||||
def lintBuildFunc(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(includeLintKeys in Global) map { _.scopedKey.key.label }
|
||||||
val excludeKeys = extracted.get(excludeLintKeys in Global) map { _.scopedKey.key.label }
|
val excludeKeys = extracted.get(excludeLintKeys in Global) map { _.scopedKey.key.label }
|
||||||
val result = lint(s, includeKeys, excludeKeys)
|
val result = lintUnused(s, includeKeys, excludeKeys)
|
||||||
lintResultLines(result) foreach { log.warn(_) }
|
lintResultLines(result) foreach { log.warn(_) }
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
@ -81,15 +84,15 @@ object LintBuild {
|
||||||
}
|
}
|
||||||
buffer.append(" ")
|
buffer.append(" ")
|
||||||
buffer.append(
|
buffer.append(
|
||||||
"note: a setting might still be used by a command; to exclude a key from this `lintBuild` check"
|
"note: a setting might still be used by a command; to exclude a key from this `lintUnused` check"
|
||||||
)
|
)
|
||||||
buffer.append(
|
buffer.append(
|
||||||
"either append it to `Global / excludeLintKeys` or set call .withRank(KeyRanks.Invisible) on the key"
|
"either append it to `Global / excludeLintKeys` or call .withRank(KeyRanks.Invisible) on the key"
|
||||||
)
|
)
|
||||||
buffer.toVector
|
buffer.toVector
|
||||||
}
|
}
|
||||||
|
|
||||||
def lint(
|
def lintUnused(
|
||||||
state: State,
|
state: State,
|
||||||
includeKeys: Set[String],
|
includeKeys: Set[String],
|
||||||
excludeKeys: Set[String]
|
excludeKeys: Set[String]
|
||||||
|
|
@ -128,14 +131,14 @@ object LintBuild {
|
||||||
case _ => false
|
case _ => false
|
||||||
}
|
}
|
||||||
def isInvisible(u: UnusedKey): Boolean = u.scoped.key.rank == KeyRanks.Invisible
|
def isInvisible(u: UnusedKey): Boolean = u.scoped.key.rank == KeyRanks.Invisible
|
||||||
val unusedSettingKeys = withDefinedAts collect {
|
val unusedKeys = withDefinedAts collect {
|
||||||
case u
|
case u
|
||||||
if !isExcludeKey(u) && !isInvisible(u)
|
if !isExcludeKey(u) && !isInvisible(u)
|
||||||
&& (isSettingKey(u) || isIncludeKey(u))
|
&& (isSettingKey(u) || isIncludeKey(u))
|
||||||
&& isLocallyDefined(u) =>
|
&& isLocallyDefined(u) =>
|
||||||
u
|
u
|
||||||
}
|
}
|
||||||
(unusedSettingKeys map { u =>
|
(unusedKeys map { u =>
|
||||||
(u.scoped, display.show(u.scoped), u.positions)
|
(u.scoped, display.show(u.scoped), u.positions)
|
||||||
}).sortBy(_._2)
|
}).sortBy(_._2)
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ lazy val root = (project in file("."))
|
||||||
val state = Keys.state.value
|
val state = Keys.state.value
|
||||||
val includeKeys = (includeLintKeys in Global).value map { _.scopedKey.key.label }
|
val includeKeys = (includeLintKeys in Global).value map { _.scopedKey.key.label }
|
||||||
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
|
val excludeKeys = (excludeLintKeys in Global).value map { _.scopedKey.key.label }
|
||||||
val result = sbt.internal.LintBuild.lint(state, includeKeys, excludeKeys)
|
val result = sbt.internal.LintUnused.lintUnused(state, includeKeys, excludeKeys)
|
||||||
assert(result.size == 1)
|
assert(result.size == 1)
|
||||||
assert(result(0)._2 == "ThisBuild / doc / scalacOptions", result(0)._2)
|
assert(result(0)._2 == "ThisBuild / doc / scalacOptions", result(0)._2)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue