-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4a5c35
commit 9ae6071
Showing
8 changed files
with
70 additions
and
42 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
scalafix-core/shared/src/main/scala/scalafix/config/CustomMessage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package scalafix | ||
package config | ||
|
||
import metaconfig.{Conf, ConfError, ConfDecoder, Configured, Metaconfig} | ||
import org.langmeta._ | ||
import scalafix.internal.config.MetaconfigPendingUpstream.XtensionConfScalafix | ||
|
||
import scala.language.implicitConversions | ||
|
||
class CustomMessage[T]( | ||
val value: T, | ||
val message: Option[String], | ||
val id: Option[String]) | ||
|
||
object CustomMessage { | ||
def getOption[T](obj: Conf.Obj, path: String)( | ||
implicit ev: ConfDecoder[T]): Configured[Option[T]] = | ||
Metaconfig | ||
.getKey(obj, Seq(path)) | ||
.map( | ||
value => ev.read(value).map(Some(_)) | ||
) | ||
.getOrElse(Configured.Ok(None)) | ||
|
||
def decoder[T](field: String)( | ||
implicit ev: ConfDecoder[T]): ConfDecoder[CustomMessage[T]] = | ||
ConfDecoder.instance[CustomMessage[T]] { | ||
case obj: Conf.Obj => { | ||
(obj.get[T](field) |@| | ||
getOption[String](obj, "message") |@| | ||
getOption[String](obj, "id")).map { | ||
case ((value, message0), id) => | ||
val message = | ||
message0.map(msg => | ||
if (msg.isMultiline) { | ||
"\n" + msg.stripMargin | ||
} else { | ||
msg | ||
}) | ||
|
||
new CustomMessage(value, message, id) | ||
} | ||
} | ||
case els => | ||
ev.read(els).map(value => new CustomMessage(value, None, None)) | ||
} | ||
} |
31 changes: 0 additions & 31 deletions
31
scalafix-core/shared/src/main/scala/scalafix/internal/config/CustomMessage.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
scalafix-core/shared/src/main/scala/scalafix/internal/config/DisableSyntaxConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters