Merge pull request #258 from xuwei-k/config-macro

fix #134 validate Configuration id
This commit is contained in:
eugene yokota 2018-08-01 12:35:56 -04:00 committed by GitHub
commit bb2c73e183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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
}
}
}