Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: bash scripts/run-version-check.sh

- name: Build Project
run: ./gradlew --refresh-dependencies clean assemble spotlessCheck
run: ./gradlew --refresh-dependencies clean assemble spotlessCheck scalafixMain scalafixTest

- name: Run Tests
run: ./gradlew test reportScoverage checkScoverage
Expand Down
94 changes: 94 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
rules = [
DisableSyntax,
LeakingImplicitClassVal,
# from scalafix-scapegoat
ArrayEquals,
ArraysInFormat,
ArraysToString,
AvoidSizeEqualsZero,
AvoidSizeNotEqualsZero,
AvoidToMinusOne,
BigDecimalDoubleConstructor,
BigDecimalScaleWithoutRoundingMode,
BooleanParameter,
BoundedByFinalType,
BrokenOddness,
CatchException,
CatchExceptionImmediatelyRethrown,
CatchFatal,
CatchNpe,
CatchThrowable,
ClassNames,
CollectionIndexOnNonIndexedSeq,
CollectionNamingConfusion,
CollectionNegativeIndex,
CollectionPromotionToAny,
ComparingFloatingPointTypes,
ComparisonToEmptyList,
ComparisonToEmptySet,
ComparisonWithSelf,
ConstantIf,
DivideByOne,
DoubleNegation,
DuplicateImport,
DuplicateMapKey,
DuplicateSetValue,
EitherGet,
EmptyCaseClass,
EmptyFor,
EmptyIfBlock,
#EmptyInterpolatedString,
EmptyMethod,
EmptySynchronizedBlock,
EmptyTryBlock,
EmptyWhileBlock,
ExistsSimplifiableToContains,
FilterDotHead,
FilterDotHeadOption,
FilterDotIsEmpty,
FilterDotSize,
FilterOptionAndGet,
FinalModifierOnCaseClass,
FinalizerWithoutSuper,
FindAndNotEqualsNoneReplaceWithExists,
FindDotIsDefined,
IllegalFormatString,
ImpossibleOptionSizeCondition,
#IncorrectNumberOfArgsToFormat, # with this the addition of timestamps fails
IncorrectlyNamedExceptions,
InterpolationToString,
InvalidRegexTest,
#LonelySealedTrait,
LooksLikeInterpolatedString,
MapGetAndGetOrElse,
MethodReturningAny,
NanComparison,
NullAssignment,
NullParameter,
OptionGet,
OptionSize,
RepeatedCaseBody,
RepeatedIfElseBody,
StripMarginOnRegex,
SwallowedException,
#TryGet, # was disabled in scapegoat
UnnecessaryConversion,
UnreachableCatch,
UnsafeContains,
UnsafeStringContains,
UnsafeTraversableMethods,
UnusedMethodParameter,
VarCouldBeVal,
VariableShadowing,
WhileTrue
]

DisableSyntax {
noWhileLoops = true
#noIsInstanceOf = true # FIXME can be enabled once pureconfig is in use
#noAsInstanceOf = true # FIXME same
noXml = true
noFinalize = true
noValPatterns = true
}

18 changes: 5 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'signing'
id 'maven-publish' // publish to a maven repo (local or mvn central, has to be defined)
id 'com.diffplug.spotless' version '7.2.1' // code format
id 'io.github.cosmicsilence.scalafix' version '0.2.4'
id "com.github.ben-manes.versions" version '0.52.0'
id "de.undercouch.download" version "5.6.0" // downloads plugin
id "kr.motd.sphinx" version "2.10.1" // documentation generation
Expand Down Expand Up @@ -145,9 +146,8 @@ dependencies {
exclude group: 'junit', module: 'junit'
}

/* Scala compiler plugin for static code analysis */
implementation "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:${scapegoatVersion}"
scalaCompilerPlugin "com.sksamuel.scapegoat:scalac-scapegoat-plugin_${scalaBinaryVersion}:${scapegoatVersion}"
/* Scalafix plugin for static code analysis */
scalafix "io.github.dedis:scapegoat-scalafix_${scalaVersion}:1.1.4"

/* Kafka */
implementation "org.apache.kafka:kafka-clients:${confluentKafkaVersion}-ccs"
Expand Down Expand Up @@ -201,11 +201,7 @@ tasks.shadowJar {
// using compileScala instead of tasks.withType(ScalaCompile) prevents applying scapegoat to scala test classes
// see https://docs.gradle.org/current/userguide/scala_plugin.html#sec:configure_scala_classpath for details
tasks.withType(ScalaCompile).configureEach {
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/src/",
"-P:scapegoat:disabledInspections:TryGet"
]
scalaCompileOptions.additionalParameters = scala3compilerOptions
scalaCompileOptions.forkOptions.jvmArgs = [
'-Xss2m',
'-XX:-UseGCOverheadLimit'
Expand All @@ -214,11 +210,7 @@ tasks.withType(ScalaCompile).configureEach {

// separate scapegoat report for test classes
compileTestScala {
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/testsrc/",
"-P:scapegoat:disabledInspections:TryGet"
]
scalaCompileOptions.additionalParameters = scala3compilerOptions
}

tasks.register("printVersion") {
Expand Down
1 change: 1 addition & 0 deletions docs/readthedocs/developersguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ In short, mergeable PRs have to meet our standards in several areas:
- Automated checks
- GitHub Actions run succeeds, i.e.
- The code needs to be properly formatted (`gradle spotlessApply`)
- The code needs to adhere to some standards regarding import order etc. (`gradle scalafix`)
- The code needs to compile
- All tests need to succeed
- [SonarQube](https://simona.ie3.e-technik.tu-dortmund.de/sonar/dashboard?id=edu.ie3%3Asimona) run succeeds, i.e.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions gradle/scripts/scalafix.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
scalafix {
configFile = file(".scalafix.conf")
includes = ["/edu/**/*.scala"]
excludes = ["**/generated/**"]
ignoreSourceSets = ["scoverage"]
semanticdb {
autoConfigure = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private[weather] final case class WeatherSourceWrapper private (
case EMPTY_WEATHER_DATA.diffIrr =>
// Some data sets do not provide diffuse irradiance, so we do not
// warn here
logger.debug("Diffuse solar irradiance not available at $point.")
logger.debug(s"Diffuse solar irradiance not available at $point.")
(averagedWeather.diffIrr, 0d)
case nonEmptyDiffIrr =>
(averagedWeather.diffIrr + nonEmptyDiffIrr * weight, weight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object ScalaReflectionSerde {
Option(maybeData)
.filter(_.nonEmpty)
.map(data => fromRecord.from(inner.deserialize(topic, data)))
.getOrElse(null.asInstanceOf[T])
.orNull

override def close(): Unit = inner.close()
}
Expand Down
Loading