Skip to content

Commit

Permalink
Refactor code for compliance to linting
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-delmas committed Dec 12, 2024
1 parent 320f87b commit 4217aec
Show file tree
Hide file tree
Showing 53 changed files with 285 additions and 198 deletions.
85 changes: 85 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
rules = [
DisableSyntax
LeakingImplicitClassVal
NoValInForComprehension
RedundantSyntax
NoAutoTupling
ArrayEquals,
ArraysInFormat,
ArraysToString,
AvoidSizeEqualsZero,
AvoidSizeNotEqualsZero,
AvoidToMinusOne,
BigDecimalScaleWithoutRoundingMode,
BoundedByFinalType,
BrokenOddness,
CatchException,
CatchExceptionImmediatelyRethrown,
CatchFatal,
CatchNpe,
CatchThrowable,
ClassNames,
CollectionNamingConfusion,
CollectionNegativeIndex,
ComparingFloatingPointTypes,
ComparisonToEmptyList,
ComparisonToEmptySet,
ComparisonWithSelf,
ConstantIf,
DivideByOne,
DoubleNegation,
DuplicateMapKey,
DuplicateSetValue,
EitherGet,
EmptyCaseClass,
EmptyFor,
EmptyIfBlock,
EmptyInterpolatedString,
EmptyMethod,
EmptySynchronizedBlock,
EmptyTryBlock,
EmptyWhileBlock,
FilterDotHead,
FilterDotHeadOption,
FilterDotIsEmpty,
FilterDotSize,
FilterOptionAndGet,
FinalModifierOnCaseClass,
FinalizerWithoutSuper,
FindAndNotEqualsNoneReplaceWithExists,
FindDotIsDefined,
IllegalFormatString,
ImpossibleOptionSizeCondition,
IncorrectNumberOfArgsToFormat,
IncorrectlyNamedExceptions,
InterpolationToString,
InvalidRegexTest,
//Not reliable with givens: LonelySealedTrait,
MapGetAndGetOrElse,
MethodReturningAny,
NanComparison,
NullAssignment,
NullParameter,
OptionGet,
OptionSize,
RepeatedCaseBody,
RepeatedIfElseBody,
StripMarginOnRegex,
SwallowedException,
TryGet,
UnreachableCatch,
UnsafeContains,
UnsafeStringContains,
//Would be nice to have: UnsafeTraversableMethods,
//Not reliable with implicits: UnusedMethodParameter,
VarCouldBeVal,
VariableShadowing,
WhileTrue
]
// Would be nice to add : DisableSyntax.noThrows = true
DisableSyntax.noNulls = true
DisableSyntax.noReturns = true
// Would be nice to add : DisableSyntax.noAsInstanceOf = true
// Would be nice to add : DisableSyntax.noIsInstanceOf = true
DisableSyntax.noFinalize = true
DisableSyntax.noValPatterns = true
8 changes: 6 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ lazy val commonSettings = Seq(
crossPaths := false,
publishTo := Some("releases" at "https://s01.oss.sonatype.org/" + "service/local/staging/deploy/maven2"),
publishMavenStyle := true,
version := "1.0.1",
version := "1.1.0",
scalaVersion := "3.2.2",
sbtVersion := "1.8.2",
scalacOptions := Seq("-unchecked", "-deprecation", "-feature"),
scalafixOnCompile := true,
semanticdbEnabled := true,
scalafixDependencies += "io.github.dedis" %% "scapegoat-scalafix" % "1.1.4",
semanticdbVersion := scalafixSemanticdb.revision,
scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "-Werror"),
resolvers ++= Resolver.sonatypeOssRepos("releases"),
resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
libraryDependencies ++= Seq(
Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.9.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MyProcPlatform(name: Symbol) extends Platform(name) {
/** Composite representing Keystone ARM cores and their internal L1 cache
* @group composite_def
*/
class ARMCore(name: Symbol) extends Composite(name) {
class ARMCore(armName: Symbol) extends Composite(armName) {

/**
* Enable to provide the name implicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SimpleKeystonePlatform(name: Symbol) extends Platform(name) {
/** Composite representing Keystone ARM cores and their internal L1 cache
* @group composite_def
*/
class ARMCore(name: Symbol) extends Composite(name) {
class ARMCore(armName: Symbol) extends Composite(armName) {

/**
* Enable to provide the name implicitly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class SimpleT1042Platform(name: Symbol) extends Platform(name) {
* ----------------------------------------------------------- */

// Composite representing cores and their internal L1 cache
class CachedCore(name: Symbol) extends Composite(name) {
class CachedCore(coreName: Symbol) extends Composite(coreName) {

def this()(implicit implicitName: Name) = {
this(implicitName.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ object FileManager {

/**
* find recursively a file by its name
* @param name name of the file to find
* @param fileName name of the file to find
* @return the java File if found
*/
def locate(name: String) : Option[File] =
OutputDirectory.recursiveLocateFirstFile(directory, (f: File) => f.getName == name)
def locate(fileName: String) : Option[File] =
OutputDirectory.recursiveLocateFirstFile(directory, (f: File) => f.getName == fileName)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ object RelationExporter {
* @param platform the platform providing the export features
*/
implicit class Ops(platform: Platform) {
import platform._

private val routingExportName: String = platform.fullName + "RouteTable.txt"
private val swAllocationExportName: String = platform.fullName + "AllocationTable.txt"
private val dataAllocationExportName: String = platform.fullName + "DataTable.txt"
Expand All @@ -79,7 +81,7 @@ object RelationExporter {
*/
def exportRouteTable(): Unit = {
val writer = getWriter(routingExportName)
writer.write(s"Initiator, TargetService, Router, NextService(s)\n")
writer.write("Initiator, TargetService, Router, NextService(s)\n")
platform.InitiatorRouting._values
.map(p => s"${p._1._1}, ${p._1._2}, ${p._1._3}, ${p._2.toSeq.sortBy(_.name.name).mkString(", ")}\n")
.toSeq
Expand All @@ -97,7 +99,7 @@ object RelationExporter {
*/
def exportAllocationTable(): Unit = {
val writer = getWriter(swAllocationExportName)
writer.write(s"Software, Initiator(s)\n")
writer.write("Software, Initiator(s)\n")
platform.SWUseInitiator._values
.map(p => s"${p._1}, ${p._2.toSeq.sortBy(_.name.name).mkString(", ")}\n")
.toSeq
Expand All @@ -115,8 +117,7 @@ object RelationExporter {
*/
def exportDataAllocationTable(): Unit = {
val writer = getWriter(dataAllocationExportName)
writer.write(s"Data, Target\n")
import platform._
writer.write("Data, Target\n")
for (d <- Data.all.toSeq.sortBy(_.name.name))
writer.write(s"$d, ${d.hostingTargets.mkString(",")}\n")
writer.flush()
Expand All @@ -131,7 +132,7 @@ object RelationExporter {
*/
def exportSWTargetUsageTable(): Unit = {
val writer = getWriter(swTargetUsage)
writer.write(s"Software, Target Service(s)\n")
writer.write("Software, Target Service(s)\n")
platform.SWUseService._values
.map(p => s"${p._1}, ${p._2.toSeq.sortBy(_.name.name).mkString(", ")}\n")
.toSeq
Expand All @@ -153,8 +154,7 @@ object RelationExporter {
*/
def exportDeactivatedComponents(): Unit = {
val writer = getWriter(componentStatus)
writer.write(s"Component, Activated, Used\n")
import platform._
writer.write("Component, Activated, Used\n")
val restricted = platform.hardwareGraph()
val hwLinks = restricted flatMap { p => p._2 map { x => (p._1, x) } }
val used = hwLinks.flatMap { p => Set(p._1, p._2) }.toSet
Expand Down Expand Up @@ -193,7 +193,7 @@ object RelationExporter {
*/
def exportPhysicalTransactions(): Unit = {
val writer = getWriter(transactionTable)
writer.write(s"Transaction Name, Transaction Path\n")
writer.write("Transaction Name, Transaction Path\n")
import platform._
for {
(n,t) <- transactionsByName.toSeq.sortBy(_.toString())
Expand All @@ -210,6 +210,8 @@ object RelationExporter {
* @param platform the configured platform with a library
*/
implicit class OpsLibrary(platform: Platform with TransactionLibrary) {

import platform._

private def getWriter(name: String): FileWriter = {
val file = FileManager.exportDirectory.getFile(name)
Expand All @@ -227,8 +229,7 @@ object RelationExporter {
*/
def exportUserTransactions(): Unit = {
val writer = getWriter(transactionTable)
writer.write(s"Transaction Name, Transaction Path\n")
import platform._
writer.write("Transaction Name, Transaction Path\n")
for {
(n,t) <- transactionByUserName.toSeq.sortBy(_.toString())
} yield
Expand All @@ -245,8 +246,7 @@ object RelationExporter {
*/
def exportUserScenarios(): Unit = {
val writer = getWriter(scenarioTable)
writer.write(s"Scenario Name, Scenario Path\n")
import platform._
writer.write("Scenario Name, Scenario Path\n")
for {
(n,s) <- scenarioByUserName.toSeq.sortBy(_._1.toString)
t = s.map(transactionsByName).map( x =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ abstract class Composite(n: Symbol, _owner:Owner) extends Hardware {

/**
* Alternative constructor without implicit owner
* @param name the name of the composite
* @param compositeName the name of the composite
* @param dummy dummy argument to avoid method signature conflict
* @param owner the implicit owner
* @param implicitOwner the implicit owner
*/
def this(name: Symbol, dummy: Int = 0)(implicit owner: Owner) = {
this(name, owner)
def this(compositeName: Symbol, dummy: Int = 0)(implicit implicitOwner: Owner) = {
this(compositeName, implicitOwner)
}

/**
* Alternative constructor without name, nor owner
* @param implicitName the implicit name provided by the enclosing object
* @param owner the implicit owner
* @param implicitOwner the implicit owner
*/
def this()(implicit implicitName: Name, owner: Owner) = {
this(Symbol(implicitName.value), owner)
def this()(implicit implicitName: Name, implicitOwner: Owner) = {
this(Symbol(implicitName.value), implicitOwner)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import onera.pmlanalyzer.pml.model.software.Application
* @tparam L the left type
* @tparam R the right type
*/
case class AuthorizeRelation[L, R] private(iniValues: Map[L, Set[R]]) extends Relation[L, R](iniValues)
final case class AuthorizeRelation[L, R] private(iniValues: Map[L, Set[R]]) extends Relation[L, R](iniValues)

object AuthorizeRelation {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import sourcecode.Name
* @param iniValues initial values of the relation
* @tparam A the elements type
*/
case class LinkRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends Endomorphism[A](iniValues)
final case class LinkRelation[A] private(iniValues: Map[A, Set[A]])(using n:Name) extends Endomorphism[A](iniValues)

object LinkRelation {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import sourcecode.Name
* @tparam L the left type
* @tparam R the right type
*/
case class ProvideRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues)
final case class ProvideRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues)

object ProvideRelation {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import sourcecode.Name
* @tparam L the left type
* @tparam R the right type
*/
case class RoutingRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues)
final case class RoutingRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues)

object RoutingRelation {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import sourcecode.Name
* @tparam L the left type
* @tparam R the right type
*/
case class UseRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues)
final case class UseRelation[L, R] private(iniValues: Map[L, Set[R]])(using n:Name) extends Relation[L, R](iniValues)

object UseRelation {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object Message {
s"[WARNING] The physical transaction $userName is not possible, check your link and route constraints"

inline def impossibleRouteWarning(t:Service, from:Option[Application]): String =
s"""[WARNING] The target service $t cannot be reached ${if (from.isDefined) s"from ${from.get}" else ""}"""
s"""[WARNING] The target service $t cannot be reached ${if (from.isDefined) s"from ${from.getOrElse("unknown application")}" else ""}"""

inline def multiPathTransactionWarning(userName: UserTransactionId, list: Iterable[(PhysicalTransactionId, PhysicalTransaction)]): String =
s"""[WARNING] The transaction $userName addresses multiple physical transactions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ package onera.pmlanalyzer.pml.model.utils
*
* @param s the owner's name
*/
case class Owner(s: Symbol)
final case class Owner(s: Symbol)
9 changes: 2 additions & 7 deletions src/main/scala/onera/pmlanalyzer/pml/operators/Provided.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

package onera.pmlanalyzer.pml.operators

import onera.pmlanalyzer.pml.model.hardware.{Composite, Hardware, Initiator, Platform, SimpleTransporter, Target, Transporter, Virtualizer}
import onera.pmlanalyzer.pml.model.relations.ProvideRelation
import onera.pmlanalyzer.pml.model.service.{Load, Service, Store}
import onera.pmlanalyzer.pml.model.software.Data
import onera.pmlanalyzer.pml.model.utils.Owner
import onera.pmlanalyzer.pml.model.hardware.*
import onera.pmlanalyzer.pml.model.relations.ProvideRelation
import onera.pmlanalyzer.pml.model.service.{Load, Service, Store}
Expand Down Expand Up @@ -133,7 +128,7 @@ object Provided {
* @return set of declared component
*/
def directHardware: Set[Hardware] = {
import self._
import self.*
Initiator.allDirect ++ Target.allDirect ++ Virtualizer.allDirect ++ SimpleTransporter.allDirect ++ Composite.allDirect
}
}
Expand Down Expand Up @@ -205,7 +200,7 @@ object Provided {
given[L <: Platform: Typeable]: Provided[L, Hardware] with {

def apply(a: L): Set[Hardware] = {
import a._
import a.*
Initiator.all ++ Target.all ++ Virtualizer.all ++ SimpleTransporter.all
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/onera/pmlanalyzer/pml/operators/Route.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object Route {
* @param a the initiator
* @param targets the set of targets
*/
case class SimpleRouteIdentifyRouter(a: Initiator, targets: Iterable[Target]) {
final case class SimpleRouteIdentifyRouter(a: Initiator, targets: Iterable[Target]) {

/**
* PML keyword to specify the hardware routing the transactions
Expand Down Expand Up @@ -148,7 +148,7 @@ object Route {
* @param router the router
* @param forbid if it is a blocking or routing constraint
*/
case class SimpleRouterIdentifyNext(a: Initiator, targets: Iterable[Target], router: Hardware, forbid:Boolean) {
final case class SimpleRouterIdentifyNext(a: Initiator, targets: Iterable[Target], router: Hardware, forbid:Boolean) {

/**
* PML keyword to specify the link from [[router]] that is routed or blocked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ object Simulator {
}
}

val immediate = fireable.collect { case e@DetermisticEvent(_, _, 0) => e }
val immediate = fireable.collect { case e@DeterministicEvent(_, _, 0) => e }
if (immediate.isEmpty) {
val det = fireable.collect { case e@DetermisticEvent(_, _, i) if i != 0 => e }
val det = fireable.collect { case e@DeterministicEvent(_, _, i) if i != 0 => e }
if (det.nonEmpty) {
val min = det.minBy(_.delay).delay
det.filter(_.delay == min) match {
Expand Down
Loading

0 comments on commit 4217aec

Please sign in to comment.