Skip to content

Commit

Permalink
Update ScalaFix & Scalafmt (#80)
Browse files Browse the repository at this point in the history
* Update ScalaFix configuration and format the code.

* Update Scalafmt and format
  • Loading branch information
dagmendez authored Dec 27, 2023
1 parent fa430ff commit 84eafae
Show file tree
Hide file tree
Showing 65 changed files with 1,564 additions and 1,557 deletions.
27 changes: 20 additions & 7 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
rules = [
OrganizeImports
DisableSyntax,
LeakingImplicitClassVal,
NoAutoTupling,
NoValInForComprehension,
OrganizeImports,
RedundantSyntax
]

DisableSyntax {
noReturns = true
noXml = true
noFinalVal = true
}

OrganizeImports {
blankLines = Auto
expandRelative = true
groupedImports = Merge
importsOrder = SymbolsFirst
importSelectorsOrder = SymbolsFirst
removeUnused = false
groups = [
"re:(java?|scala)\\.",
"cats.",
"sbt.",
"*",
"com.sun."
"re:(cats|fs2)\\."
"re:(java|scala)\\."
"org.apache"
"com.fortyseven"
"*"
]
}
66 changes: 35 additions & 31 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
version = "3.7.4"
version = "3.7.17"

maxColumn = 150
maxColumn = 120

continuationIndent.callSite = 2
align.preset = none

runner {
dialect = scala3
}
assumeStandardLibraryStripMargin = true

fileOverride {
"glob:**.sbt" {
runner.dialect = scala213
}
"glob:**/project/**.scala" {
runner.dialect = scala213
}
}
importSelectors = singleLine

indentOperator.exemptScope = all

newlines {
sometimesBeforeColonInMethodReturnType = false
}
rewrite.redundantBraces.ifElseExpressions = true
rewrite.rules = [RedundantBraces, SortModifiers]
rewrite.scala3.convertToNewSyntax = true
rewrite.scala3.insertEndMarkerMinLines = 15
rewrite.scala3.removeEndMarkerMaxLines = 14
rewrite.scala3.removeOptionalBraces = oldSyntaxToo

align {
arrowEnumeratorGenerator = true
ifWhileOpenParen = false
openParenCallSite = true
openParenDefnSite = true
preset = more
}
newlines.afterCurlyLambdaParams = squash
newlines.inInterpolation = oneLine
newlines.selectChains = unfold
newlines.source = fold
newlines.topLevelStatementBlankLines = [{blanks = 1}]

docstrings.style = Asterisk
runner.dialect = scala3
runner.optimizer.forceConfigStyleMinArgCount = 3
runner.optimizer.forceConfigStyleOnOffset = 120

rewrite {
rules = [RedundantBraces]
redundantBraces.maxLines = 1
}
project.git = true
project.includePaths = [
"glob:**.scala"
"glob:**.sbt"
"glob:**.sc"
"glob:**.md"
]

optIn {
breaksInsideChains = true
fileOverride {
"glob:**/project/**" {
runner.dialect = scala212
}
"glob:**/*.sbt" {
runner.dialect = scala212
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,38 @@ import cats.implicits.*
import com.fortyseven.domain.codecs.ids.IdsCodecs.given
import com.fortyseven.domain.codecs.types.TypesCodecs.given
import com.fortyseven.domain.model.app.model.*

import vulcan.Codec

/**
* It contains the Vulcan codecs for the types (enums, case classes...) defined in the object [[com.fortyseven.domain.model.app.model]].
*/
/** It contains the Vulcan codecs for the types (enums, case classes...) defined in the object
* [[com.fortyseven.domain.model.app.model]].
*/
object AppCodecs:

private val _namespace = "app"

given totalDistanceByTripCodec: Codec[TotalDistanceByTrip] =
Codec.record("TotalDistanceByTrip", _namespace) { totalDistanceByTrip =>
(
totalDistanceByTrip("tripId", _.tripId),
totalDistanceByTrip("distance", _.distance)
).mapN(TotalDistanceByTrip.apply)
given totalDistanceByTripCodec: Codec[TotalDistanceByTrip] = Codec
.record("TotalDistanceByTrip", _namespace) { totalDistanceByTrip =>
(totalDistanceByTrip("tripId", _.tripId), totalDistanceByTrip("distance", _.distance))
.mapN(TotalDistanceByTrip.apply)
}

given totalDistanceByUserCodec: Codec[TotalDistanceByUser] =
Codec.record("TotalDistanceByUser", _namespace) { totalDistanceByUser =>
(
totalDistanceByUser("userId", _.userId),
totalDistanceByUser("distance", _.distance)
).mapN(TotalDistanceByUser.apply)
given totalDistanceByUserCodec: Codec[TotalDistanceByUser] = Codec
.record("TotalDistanceByUser", _namespace) { totalDistanceByUser =>
(totalDistanceByUser("userId", _.userId), totalDistanceByUser("distance", _.distance))
.mapN(TotalDistanceByUser.apply)
}

given currentSpeedCodec: Codec[CurrentSpeed] =
Codec.record("CurrentSpeed", _namespace) { currentSpeed =>
(
currentSpeed("tripId", _.tripId),
currentSpeed("speed", _.speed)
).mapN(CurrentSpeed.apply)
}
given currentSpeedCodec: Codec[CurrentSpeed] = Codec.record("CurrentSpeed", _namespace) { currentSpeed =>
(currentSpeed("tripId", _.tripId), currentSpeed("speed", _.speed)).mapN(CurrentSpeed.apply)
}

given totalRangeCodec: Codec[TotalRange] =
Codec.record("TotalRange", _namespace) { totalRange =>
(
totalRange("tripId", _.tripId),
totalRange("bicycleId", _.bicycleId),
totalRange("remainingRange", _.remainingRange)
).mapN(TotalRange.apply)
}
given totalRangeCodec: Codec[TotalRange] = Codec.record("TotalRange", _namespace) { totalRange =>
(
totalRange("tripId", _.tripId),
totalRange("bicycleId", _.bicycleId),
totalRange("remainingRange", _.remainingRange)
).mapN(TotalRange.apply)
}

end AppCodecs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

package com.fortyseven.domain.codecs.ids

import com.fortyseven.domain.model.types.ids.{BicycleId, TripId, UserId}
import com.fortyseven.domain.model.types.ids.BicycleId
import com.fortyseven.domain.model.types.ids.TripId
import com.fortyseven.domain.model.types.ids.UserId

import vulcan.Codec

/**
* It contains the Vulcan codecs for the types (enums, case classes...) defined in the object [[com.fortyseven.domain.model.types.ids]].
*/
/** It contains the Vulcan codecs for the types (enums, case classes...) defined in the object
* [[com.fortyseven.domain.model.types.ids]].
*/
object IdsCodecs:

given bicycleIdCodec: Codec[BicycleId] = Codec.uuid.imap(BicycleId.apply)(_.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,44 @@

package com.fortyseven.domain.codecs.iot

import scala.concurrent.duration.*

import cats.implicits.*

import scala.concurrent.duration.*

import com.fortyseven.domain.codecs.types.TypesCodecs.given
import com.fortyseven.domain.model.iot.model.*

import vulcan.Codec

/**
* It contains the Vulcan codecs for the types (enums, case classes...) defined in the object [[com.fortyseven.domain.model.iot.model]].
*/
/** It contains the Vulcan codecs for the types (enums, case classes...) defined in the object
* [[com.fortyseven.domain.model.iot.model]].
*/
object IotCodecs:

private val _namespace = "iot"

given gpsPositionCodec: Codec[GPSPosition] =
Codec.record(name = "GPSPosition", namespace = _namespace) { field =>
(
field("latitude", _.latitude),
field("longitude", _.longitude)
).mapN(GPSPosition.apply)
}
given gpsPositionCodec: Codec[GPSPosition] = Codec.record(name = "GPSPosition", namespace = _namespace) { field =>
(field("latitude", _.latitude), field("longitude", _.longitude)).mapN(GPSPosition.apply)
}

given wheelRotationCodec: Codec[WheelRotation] =
Codec.record(name = "WheelRotation", namespace = _namespace)(_("s", _.frequency).map(WheelRotation.apply))
given wheelRotationCodec: Codec[WheelRotation] = Codec
.record(name = "WheelRotation", namespace = _namespace)(_("s", _.frequency).map(WheelRotation.apply))

given batteryChargeCodec: Codec[BatteryCharge] =
Codec.record(name = "BatteryCharge", namespace = _namespace)(_("percentage", _.percentage).map(BatteryCharge.apply))
given batteryChargeCodec: Codec[BatteryCharge] = Codec
.record(name = "BatteryCharge", namespace = _namespace)(_("percentage", _.percentage).map(BatteryCharge.apply))

given batteryHealthCodec: Codec[BatteryHealth] =
Codec.record(name = "BatteryHealth", namespace = _namespace)(_("remaining", _.remaining).map(BatteryHealth.apply))
given batteryHealthCodec: Codec[BatteryHealth] = Codec
.record(name = "BatteryHealth", namespace = _namespace)(_("remaining", _.remaining).map(BatteryHealth.apply))

given pneumaticPressureCodec: Codec[PneumaticPressure] =
Codec.record(name = "PneumaticPressure", namespace = _namespace)(
_("pressure", _.pressure).map(PneumaticPressure.apply)
)
given pneumaticPressureCodec: Codec[PneumaticPressure] = Codec
.record(name = "PneumaticPressure", namespace = _namespace)(_("pressure", _.pressure).map(PneumaticPressure.apply))

given finiteDurationCodec: Codec[FiniteDuration] = Codec.long.imap(_.millis)(_.toMillis)

given breaksUsageCodec: Codec[BreaksUsage] =
Codec.record(name = "BreaksUsage", namespace = _namespace)(
_("finateDuration", _.finiteDuration).map(BreaksUsage.apply)
)
given breaksUsageCodec: Codec[BreaksUsage] = Codec
.record(name = "BreaksUsage", namespace = _namespace)(_("finateDuration", _.finiteDuration).map(BreaksUsage.apply))

given breaksHealthCodec: Codec[BreaksHealth] = Codec
.record(name = "BreaksHealth", namespace = _namespace)(_("remaining", _.remaining).map(BreaksHealth.apply))

given breaksHealthCodec: Codec[BreaksHealth] =
Codec.record(name = "BreaksHealth", namespace = _namespace)(_("remaining", _.remaining).map(BreaksHealth.apply))
end IotCodecs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package com.fortyseven.domain.codecs.iot

import com.fortyseven.domain.model.iot.errors.OutOfBoundsError

import vulcan.Codec

/**
* It contains the Vulcan codecs for the types (enums, case classes...) defined in the object [[com.fortyseven.domain.model.iot.errors]].
*/
/** It contains the Vulcan codecs for the types (enums, case classes...) defined in the object
* [[com.fortyseven.domain.model.iot.errors]].
*/
object IotErrorCodecs:

private val _namespace = "iot-error"

given outOfBoundsErrorCodec: Codec[OutOfBoundsError] =
Codec.record(name = "OutOfBoundsError", namespace = _namespace)(_("msg", _.message).map(OutOfBoundsError.apply))
given outOfBoundsErrorCodec: Codec[OutOfBoundsError] = Codec
.record(name = "OutOfBoundsError", namespace = _namespace)(_("msg", _.message).map(OutOfBoundsError.apply))
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,41 @@ package com.fortyseven.domain.codecs.types
import cats.implicits.*

import com.fortyseven.domain.model.types.refinedTypes.*
import vulcan.{AvroError, Codec}

/**
* It contains the Vulcan codecs for the types (enums, case classes...) defined in the object [[com.fortyseven.domain.model.types.refinedTypes]].
*/
import vulcan.AvroError
import vulcan.Codec

/** It contains the Vulcan codecs for the types (enums, case classes...) defined in the object
* [[com.fortyseven.domain.model.types.refinedTypes]].
*/
object TypesCodecs:

given latitudeCodec: Codec[Latitude] =
Codec.double.imapError(Latitude.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
given latitudeCodec: Codec[Latitude] = Codec
.double
.imapError(Latitude.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given longitudeCodec: Codec[Longitude] = Codec
.double
.imapError(Longitude.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given longitudeCodec: Codec[Longitude] =
Codec.double.imapError(Longitude.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
given percentageCodec: Codec[Percentage] = Codec
.double
.imapError(Percentage.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given percentageCodec: Codec[Percentage] =
Codec.double.imapError(Percentage.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
given speedCodec: Codec[Speed] = Codec
.double
.imapError(Speed.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given speedCodec: Codec[Speed] =
Codec.double.imapError(Speed.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
given hertzCodec: Codec[Hz] = Codec
.double
.imapError(Hz.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given hertzCodec: Codec[Hz] = Codec.double.imapError(Hz.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
given barCodec: Codec[Bar] = Codec
.double
.imapError(Bar.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given barCodec: Codec[Bar] = Codec.double.imapError(Bar.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
given metersCodec: Codec[Meters] = Codec
.int
.imapError(Meters.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)

given metersCodec: Codec[Meters] =
Codec.int.imapError(Meters.from(_).leftMap(e => AvroError(s"AvroError: ${e.message}")))(_.value)
end TypesCodecs
Loading

0 comments on commit 84eafae

Please sign in to comment.