Skip to content

Commit

Permalink
Update maxColumn to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
ruippeixotog committed Jul 6, 2020
1 parent 6e6a285 commit ebd766f
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
@@ -1,4 +1,4 @@
version = 2.5.2

align.preset = none
maxColumn = 100
maxColumn = 120
3 changes: 1 addition & 2 deletions core/src/main/scala/pureconfig/ConfigCursor.scala
Expand Up @@ -372,8 +372,7 @@ case class SimpleConfigCursor(value: ConfigValue, pathElems: List[String]) exten
/**
* A `ConfigCursor` pointing to a config list.
*/
case class ConfigListCursor(value: ConfigList, pathElems: List[String], offset: Int = 0)
extends ConfigCursor {
case class ConfigListCursor(value: ConfigList, pathElems: List[String], offset: Int = 0) extends ConfigCursor {

@inline private[this] def validIndex(idx: Int) = idx >= 0 && idx < size
@inline private[this] def indexKey(idx: Int) = (offset + idx).toString
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/scala/pureconfig/ConfigReader.scala
Expand Up @@ -120,11 +120,7 @@ trait ConfigReader[A] {
/**
* Provides methods to create [[ConfigReader]] instances.
*/
object ConfigReader
extends BasicReaders
with CollectionReaders
with ProductReaders
with ExportedReaders {
object ConfigReader extends BasicReaders with CollectionReaders with ProductReaders with ExportedReaders {

/**
* The type of most config PureConfig reading methods.
Expand Down
6 changes: 1 addition & 5 deletions core/src/main/scala/pureconfig/ConfigWriter.scala
Expand Up @@ -41,11 +41,7 @@ trait ConfigWriter[A] {
/**
* Provides methods to create [[ConfigWriter]] instances.
*/
object ConfigWriter
extends BasicWriters
with CollectionWriters
with ProductWriters
with ExportedWriters {
object ConfigWriter extends BasicWriters with CollectionWriters with ProductWriters with ExportedWriters {

def apply[A](implicit writer: Derivation[ConfigWriter[A]]): ConfigWriter[A] = writer.value

Expand Down
13 changes: 6 additions & 7 deletions core/src/main/scala/pureconfig/ConvertHelpers.scala
Expand Up @@ -51,13 +51,12 @@ trait ConvertHelpers {
* - `Success(t)` becomes `_ => Right(t)`
* - `Failure(e)` becomes `location => Left(CannotConvert(value, type, e.getMessage, location)`
*/
def tryF[A](f: String => Try[A])(implicit ct: ClassTag[A]): String => Either[FailureReason, A] = {
string =>
f(string) match {
case Success(t) => Right(t)
case Failure(e) =>
Left(CannotConvert(string, ct.runtimeClass.getName, e.getLocalizedMessage))
}
def tryF[A](f: String => Try[A])(implicit ct: ClassTag[A]): String => Either[FailureReason, A] = { string =>
f(string) match {
case Success(t) => Right(t)
case Failure(e) =>
Left(CannotConvert(string, ct.runtimeClass.getName, e.getLocalizedMessage))
}
}

/**
Expand Down
Expand Up @@ -81,7 +81,5 @@ object ConfigFactoryWrapper {

/** Utility methods that parse a file and then calls `ConfigFactory.load` */
def loadFile(path: Path): ConfigReader.Result[Config] =
parseFile(path.toFile).right.flatMap(rawConfig =>
unsafeToReaderResult(ConfigFactory.load(rawConfig))
)
parseFile(path.toFile).right.flatMap(rawConfig => unsafeToReaderResult(ConfigFactory.load(rawConfig)))
}
Expand Up @@ -69,8 +69,7 @@ case object NoFilesToRead extends ConfigReaderFailure {
* @param throwable the exception thrown
* @param origin the optional origin of the failure
*/
final case class ThrowableFailure(throwable: Throwable, origin: Option[ConfigOrigin])
extends ConfigReaderFailure {
final case class ThrowableFailure(throwable: Throwable, origin: Option[ConfigOrigin]) extends ConfigReaderFailure {

def description = s"${throwable.getMessage}."
}
Expand Down Expand Up @@ -135,8 +134,7 @@ final case class CannotReadUrl(url: URL, reason: Option[Throwable]) extends Cann
* @param resourceName the resource that couldn't be read
* @param reason an optional exception thrown when trying to read the resource
*/
final case class CannotReadResource(resourceName: String, reason: Option[Throwable])
extends CannotRead {
final case class CannotReadResource(resourceName: String, reason: Option[Throwable]) extends CannotRead {
val sourceType = "resource"
def sourceName = resourceName
}
Expand All @@ -147,7 +145,6 @@ final case class CannotReadResource(resourceName: String, reason: Option[Throwab
* @param msg the error message from the parser
* @param origin the optional origin of the failure
*/
final case class CannotParse(msg: String, origin: Option[ConfigOrigin])
extends ConfigReaderFailure {
final case class CannotParse(msg: String, origin: Option[ConfigOrigin]) extends ConfigReaderFailure {
def description = s"Unable to parse the configuration: $msg."
}
6 changes: 2 additions & 4 deletions core/src/main/scala/pureconfig/error/FailureReason.scala
Expand Up @@ -23,8 +23,7 @@ trait FailureReason {
* @param toType the target type that the value was requested to be converted to
* @param because the reason why the conversion was not possible
*/
final case class CannotConvert(value: String, toType: String, because: String)
extends FailureReason {
final case class CannotConvert(value: String, toType: String, because: String) extends FailureReason {
def description = s"Cannot convert '$value' to $toType: $because."
}

Expand Down Expand Up @@ -100,8 +99,7 @@ final case class UnknownKey(key: String) extends FailureReason {
* @param foundType the `ConfigValueType` that was found
* @param expectedTypes the `ConfigValueType`s that were expected
*/
final case class WrongType(foundType: ConfigValueType, expectedTypes: Set[ConfigValueType])
extends FailureReason {
final case class WrongType(foundType: ConfigValueType, expectedTypes: Set[ConfigValueType]) extends FailureReason {
def description =
s"""Expected type ${expectedTypes.mkString(" or ")}. Found $foundType instead."""
}
Expand Down
Expand Up @@ -16,10 +16,7 @@ import pureconfig.module.cats.arbitrary._
import pureconfig.module.cats.eq._
import pureconfig.module.cats.instances._

class CatsLawsSuite
extends AnyFunSuite
with ScalaCheckDrivenPropertyChecks
with FunSuiteDiscipline {
class CatsLawsSuite extends AnyFunSuite with ScalaCheckDrivenPropertyChecks with FunSuiteDiscipline {
checkAll(
"ConfigReader[Int]",
ApplicativeErrorTests[ConfigReader, ConfigReaderFailures].applicativeError[Int, Int, Int]
Expand Down
Expand Up @@ -20,11 +20,10 @@ object Greeting {

class EnumTest extends BaseSuite {

"enum config convert" should "parse an enum" in Inspectors.forAll(Greeting.EnumInstance.values) {
greeting =>
val conf = ConfigFactory.parseString(s"""{greeting:"$greeting"}""")
case class Conf(greeting: Greeting)
conf.to[Conf].right.value shouldEqual Conf(greeting)
"enum config convert" should "parse an enum" in Inspectors.forAll(Greeting.EnumInstance.values) { greeting =>
val conf = ConfigFactory.parseString(s"""{greeting:"$greeting"}""")
case class Conf(greeting: Greeting)
conf.to[Conf].right.value shouldEqual Conf(greeting)
}

it should "politely refuse an invalid member" in {
Expand Down
Expand Up @@ -20,11 +20,10 @@ class EnumeratumConvertTest extends BaseSuite {
case object ShoutGoodBye extends Greeting with Uppercase
}

"Enumeratum ConfigConvert" should "parse an enum" in Inspectors.forAll(Greeting.values) {
greeting =>
val conf = ConfigFactory.parseString(s"""{greeting:"${greeting.entryName}"}""")
case class Conf(greeting: Greeting)
conf.to[Conf].right.value shouldEqual Conf(greeting)
"Enumeratum ConfigConvert" should "parse an enum" in Inspectors.forAll(Greeting.values) { greeting =>
val conf = ConfigFactory.parseString(s"""{greeting:"${greeting.entryName}"}""")
case class Conf(greeting: Greeting)
conf.to[Conf].right.value shouldEqual Conf(greeting)
}

sealed abstract class IntLibraryItem(val value: Int, val name: String) extends IntEnumEntry
Expand Down Expand Up @@ -75,8 +74,7 @@ class EnumeratumConvertTest extends BaseSuite {
conf.to[Conf].right.value shouldEqual Conf(item)
}

sealed abstract class StringLibraryItem(val value: String, val number: Int)
extends StringEnumEntry
sealed abstract class StringLibraryItem(val value: String, val number: Int) extends StringEnumEntry

case object StringLibraryItem extends StringEnum[StringLibraryItem] {
val values = findValues
Expand Down
Expand Up @@ -26,8 +26,7 @@ object DerivedConfigReader extends DerivedConfigReader1 {
reader.from(value).right.map(unwrapped.wrap)
}

implicit def tupleReader[A: IsTuple, Repr <: HList, LabelledRepr <: HList, DefaultRepr <: HList](
implicit
implicit def tupleReader[A: IsTuple, Repr <: HList, LabelledRepr <: HList, DefaultRepr <: HList](implicit
g: Generic.Aux[A, Repr],
gcr: SeqShapedReader[Repr],
lg: LabelledGeneric.Aux[A, LabelledRepr],
Expand Down
Expand Up @@ -35,17 +35,16 @@ package object arbitrary {
new LocalDate(d.getYear, d.getMonthValue, d.getDayOfMonth)
})

implicit val localDateTimeArbitrary: Arbitrary[LocalDateTime] = Arbitrary(genLocalDateTime.map {
d =>
new LocalDateTime(
d.getYear,
d.getMonthValue,
d.getDayOfMonth,
d.getHour,
d.getMinute,
d.getSecond,
nanoToMilli(d.getNano)
)
implicit val localDateTimeArbitrary: Arbitrary[LocalDateTime] = Arbitrary(genLocalDateTime.map { d =>
new LocalDateTime(
d.getYear,
d.getMonthValue,
d.getDayOfMonth,
d.getHour,
d.getMinute,
d.getSecond,
nanoToMilli(d.getNano)
)
})

implicit val monthDayArbitrary: Arbitrary[MonthDay] = Arbitrary(genMonthDay.map { m =>
Expand Down
Expand Up @@ -34,8 +34,7 @@ object MagnoliaConfigReader {
(fieldHint, param.default) match {
case (UseOrDefault(cursor, _), Some(defaultValue)) if cursor.isUndefined =>
Right(defaultValue)
case (action, _)
if reader.isInstanceOf[ReadsMissingKeys] || !action.cursor.isUndefined =>
case (action, _) if reader.isInstanceOf[ReadsMissingKeys] || !action.cursor.isUndefined =>
reader.from(action.cursor)
case _ =>
cur.failed(KeyNotFound.forKeys(fieldHint.field, objCur.keys))
Expand Down
Expand Up @@ -25,9 +25,7 @@ package object arbitrary {
def genMap(depth: Int): Gen[Map[String, Any]] =
Gen
.choose(0, MaxCollectionLength)
.flatMap(n =>
Gen.mapOfN(n, for { k <- Gen.alphaStr; v <- Gen.lzy(genAny(depth - 1)) } yield (k, v))
)
.flatMap(n => Gen.mapOfN(n, for { k <- Gen.alphaStr; v <- Gen.lzy(genAny(depth - 1)) } yield (k, v)))

if (depth == 0) genScalar
else
Expand Down
17 changes: 8 additions & 9 deletions tests/src/test/scala/pureconfig/ConfigReaderSuite.scala
Expand Up @@ -46,15 +46,14 @@ class ConfigReaderSuite extends BaseSuite {
cr.from(ConfigValueFactory.fromAnyRef(1)) should failWith(ExceptionThrown(throwable))
}

it should "have a correct emap method" in forAll {
(conf: ConfigValue, f: Int => Either[FailureReason, String]) =>
def getReason[A](failures: ConfigReaderFailures): FailureReason =
failures match {
case ConfigReaderFailures(ConvertFailure(reason, _, _)) => reason
case _ => throw new Exception(s"Unexpected value: $failures")
}
intReader.emap(f).from(conf).left.map(getReason) shouldEqual
intReader.from(conf).left.map(getReason).right.flatMap(f)
it should "have a correct emap method" in forAll { (conf: ConfigValue, f: Int => Either[FailureReason, String]) =>
def getReason[A](failures: ConfigReaderFailures): FailureReason =
failures match {
case ConfigReaderFailures(ConvertFailure(reason, _, _)) => reason
case _ => throw new Exception(s"Unexpected value: $failures")
}
intReader.emap(f).from(conf).left.map(getReason) shouldEqual
intReader.from(conf).left.map(getReason).right.flatMap(f)
}

it should "have a correct flatMap method" in forAll { conf: ConfigValue =>
Expand Down

0 comments on commit ebd766f

Please sign in to comment.