wix-incubator / accord

Accord: A sane validation library for Scala
http://wix.github.io/accord/
Other
530 stars 55 forks source link

Need to add "()" to imply discarded non-Unit value to suppress error when defining validator with DSL #160

Closed webblin034 closed 3 years ago

webblin034 commented 4 years ago

Library Dependencies :

libraryDependencies ++= Seq(
  "com.wix"                   %% "accord-core"                 % "0.7.6" % Test,
  "org.scalatest"             %% "scalatest"                   % "3.2.2"  % Test
)

Input Data :

case class InputData(
  id: String,
  name: Option[String] = None,
  description: Option[String] = None,
  items: Seq[String] = Seq.empty
)

Test Compilation Pass With () !

  implicit val inputDataValidator: Validator[InputData] = validator[InputData] { request =>
    request.id is notBlank
    request.name.mkString is notBlank
    request.description.mkString is notBlank
    request.items is notEmpty
    ()
  }

Test Compilation Failed Without () !

  implicit val inputDataValidator: Validator[InputData] = validator[InputData] { request =>
    request.id is notBlank
    request.name.mkString is notBlank
    request.description.mkString is notBlank
    request.items is notEmpty
  }

Test Compilation Error :

  [error]  discarded non-Unit value
  [error]  request.items is notEmpty
  [error]                ^
  [error]  one error found
noam-almog commented 3 years ago

i'm not sure what you are trying to achieve here