fix #134 validate Configuration id

This commit is contained in:
xuwei-k 2018-08-01 22:45:02 +09:00
parent 3fcc9e3629
commit 326342cf32
2 changed files with 16 additions and 0 deletions

View File

@ -110,6 +110,9 @@ private[sbt] object ConfigurationMacro {
c,
methodName =>
s"""$methodName must be directly assigned to a val, such as `val Tooling = $methodName("tooling")`.""")
if (enclosingValName.head.isLower) {
c.error(c.enclosingPosition, "configuration id must be capitalized")
}
val id = c.Expr[String](Literal(Constant(enclosingValName)))
reify { Configuration.of(id.splice, name.splice) }
}

View File

@ -0,0 +1,13 @@
package sbt.librarymanagement
import sbt.librarymanagement.Configurations.config
import org.scalatest._
class ConfigMacroTest extends FunSpec with Matchers {
describe("Configurations.config") {
it("should validate the ID in compile time") {
"""val A = config("a")""" should compile
"""val b = config("b")""" shouldNot compile
}
}
}