forked from scalacenter/scalafix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add id for CustomMessage (fix scalacenter#495)
- Loading branch information
1 parent
e4a5c35
commit 4d6c8a7
Showing
7 changed files
with
92 additions
and
24 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
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,44 @@ | ||
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](value: T, message: Option[String], 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)) | ||
} | ||
} |
42 changes: 29 additions & 13 deletions
42
scalafix-core/shared/src/main/scala/scalafix/internal/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 |
---|---|---|
@@ -1,31 +1,47 @@ | ||
package scalafix | ||
package internal.config | ||
|
||
import metaconfig.{Conf, ConfError, ConfDecoder, Configured} | ||
import metaconfig.{Conf, ConfError, ConfDecoder, Configured, Metaconfig} | ||
import org.langmeta._ | ||
import MetaconfigPendingUpstream.XtensionConfScalafix | ||
|
||
import scala.language.implicitConversions | ||
|
||
case class CustomMessage[T](value: T, message: Option[String]) | ||
case class CustomMessage[T]( | ||
value: T, | ||
message: Option[String], | ||
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) |@| obj.get[String]("message")).map { | ||
case (value, message0) => { | ||
case obj: Conf.Obj => { | ||
(obj.get[T](field) |@| | ||
getOption[String](obj, "message") |@| | ||
getOption[String](obj, "id")).map { | ||
case ((value, message0), id) => | ||
val message = | ||
if (message0.isMultiline) { | ||
"\n" + message0.stripMargin | ||
} else { | ||
message0 | ||
} | ||
CustomMessage(value, Some(message)) | ||
} | ||
message0.map(msg => | ||
if (msg.isMultiline) { | ||
"\n" + msg.stripMargin | ||
} else { | ||
msg | ||
}) | ||
|
||
CustomMessage(value, message, id) | ||
} | ||
} | ||
case els => | ||
ev.read(els).map(value => CustomMessage(value, None)) | ||
ev.read(els).map(value => CustomMessage(value, None, None)) | ||
} | ||
} |
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