Skip to content

Commit

Permalink
Merge pull request #270 from mdedetrich/add-scalafix
Browse files Browse the repository at this point in the history
Add scalafix
  • Loading branch information
raboof authored Jul 30, 2023
2 parents bc9c551 + a390822 commit 2514af0
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ jobs:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: 'Linter: Scalafix checks'
run: sbt "scalafixAll --check"
- uses: olafurpg/setup-scala@v10
- run: sbt test scripted publishLocal
30 changes: 30 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
rules = [
DisableSyntax, # Disables some constructs that make no semantic sense like `final val`
ProcedureSyntax, # Procedure syntax in Scala is always discouraged
NoValInForComprehension, # `val` in for comprehensions are deprecated and shouldn't be used
NoAutoTupling, # Avoids the automatic tupling in parameters
RemoveUnused, # Removes unused elements
LeakingImplicitClassVal, # This rule adds the private access modifier on the field of implicit value classes in order to prevent direct access.
OrganizeImports # Organizes imports and removes unused ones
]

ExplicitResultTypes.memberKind = [Def, Val, Var]
ExplicitResultTypes.memberVisibility = [Public, Protected]
ExplicitResultTypes.skipSimpleDefinitions = ['Lit', 'Term.New', 'Term.Ref']
ExplicitResultTypes.fatalWarnings = true
DisableSyntax.noReturns = true
DisableSyntax.noWhileLoops = true
DisableSyntax.noXml = true
DisableSyntax.noFinalVal = true
DisableSyntax.noFinalize = true
DisableSyntax.noValPatterns = true
RemoveUnused.imports = false # The plugin organize imports removes unused and clashes with this
OrganizeImports {
groupedImports = Merge
groups = [
"*"
"java."
"scala."
"re:javax?\\."
] # Reasoning for this config is to keep the more business related imports at the top, while language imports are on the bottom
}
13 changes: 13 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import sbt.Keys.{semanticdbEnabled, semanticdbVersion}

sbtPlugin := true

organization := "net.bzzt"
Expand Down Expand Up @@ -41,3 +43,14 @@ scriptedLaunchOpts := {
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
}
scriptedBufferLog := false

// scalafix specific settings
inThisBuild(
List(
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalacOptions ++= Seq(
"-Ywarn-unused"
)
)
)
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ addSbtPlugin("net.bzzt" % "sbt-reproducible-builds" % "0.31")
addSbtPlugin("net.bzzt" % "sbt-strict-scala-versions" % "0.0.1")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package net.bzzt.reproduciblebuilds

import sbt.Keys._
import sbt._
import sbtassembly.AssemblyPlugin
import sbtassembly.AssemblyPlugin.autoImport.{Assembly => _, baseAssemblySettings => _, _}
import sbt._
import sbt.Keys._

object AssemblyHelpers {
val plugin: Plugins.Basic = AssemblyPlugin
Expand Down
10 changes: 4 additions & 6 deletions src/main/scala/net/bzzt/reproduciblebuilds/Certification.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@

package net.bzzt.reproduciblebuilds

import sbt.librarymanagement.ScmInfo
import sbt.{Artifact, File, ModuleID}

import java.io.StringReader
import java.math.BigInteger
import java.nio.file.Files
import java.security.MessageDigest

import sbt.{Artifact, File, ModuleID}
import sbt.librarymanagement.ScmInfo

import scala.collection.mutable
import scala.collection.immutable
import scala.collection.{immutable, mutable}

case class Checksum(filename: String, length: Int, checksum: List[Byte]) {
def hexChecksum = checksum.map("%02x" format _).mkString
Expand Down Expand Up @@ -58,7 +57,6 @@ case class Certification(
)

def asPropertyString: String = {
val packageName = groupId + ":" + artifactId
val content = mutable.LinkedHashMap(
"buildinfo.version" -> "0.1-SNAPSHOT",
"name" -> name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package net.bzzt.reproduciblebuilds

import scala.util.Try

import sbt._
import sbt.plugins.JvmPlugin

import scala.util.Try

object ReproducibleBuildsAssemblyPlugin extends AutoPlugin {
val assemblyPluginOnClasspath =
Try(getClass.getClassLoader.loadClass("sbtassembly.AssemblyPlugin")).isSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,28 @@

package net.bzzt.reproduciblebuilds

import java.net.InetAddress
import java.nio.charset.Charset
import java.nio.file.Files

import scala.concurrent.duration._
import gigahorse.{GigahorseSupport, StatusError}
import sbt.{io => _, _}
import sbt.Keys._
import sbt.Classpaths._
import sbt.plugins.JvmPlugin
import io.github.zlika.reproducible._
import org.apache.ivy.core.IvyPatternHelper
import org.apache.ivy.plugins.resolver.DependencyResolver
import sbt.Classpaths._
import sbt.Keys._
import sbt.io.syntax.{URI, uri}
import sbt.librarymanagement.Artifact
import sbt.librarymanagement.Http.http
import sbt.plugins.JvmPlugin
import sbt.util.Logger

import scala.util.Try
import sbt.{io => _, _}
import spray.json._

import java.net.InetAddress
import java.nio.charset.Charset
import java.nio.file.Files

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.util.Try

object ReproducibleBuildsPlugin extends AutoPlugin {
// To make sure we're loaded after the defaults
Expand Down Expand Up @@ -210,7 +209,7 @@ object ReproducibleBuildsPlugin extends AutoPlugin {
.value,
reproducibleBuildsCheckCertification := {
val ours = ourCertification.value
val groupId = organization.value
organization.value
val pTo = (ReproducibleBuilds / publishTo).value.getOrElse(bzztNetResolver)
Def.task {
val prefix = artifactUrl(pTo, "buildinfo").value
Expand Down Expand Up @@ -354,7 +353,7 @@ object ReproducibleBuildsPlugin extends AutoPlugin {
Future
.sequence {
result.verdicts
.collect { case (filename: String, m: Mismatch) =>
.collect { case (filename: String, _: Mismatch) =>
val ext = filename.substring(filename.lastIndexOf('.') + 1)
val mavenArtifactUrl = artifactUrl(resolver, "").value + ext

Expand All @@ -366,7 +365,7 @@ object ReproducibleBuildsPlugin extends AutoPlugin {
case List() =>
throw new IllegalStateException(s"Did not find local artifact for $artifactName ($ext)")
case List(artifact) => artifact
case multiple => throw new IllegalStateException(s"Found multiple artifacts for $ext")
case _ => throw new IllegalStateException(s"Found multiple artifacts for $ext")
}

http
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package net.bzzt.reproduciblebuilds

import org.apache.ivy.core.module.descriptor.{
Artifact => IArtifact,
DefaultModuleDescriptor,
License,
MDArtifact,
ModuleDescriptor,
Artifact => IArtifact
ModuleDescriptor
}
import org.apache.ivy.core.module.id.ModuleRevisionId
import sbt.librarymanagement.ScalaModuleInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package net.bzzt.reproduciblebuilds

import com.typesafe.sbt.packager.universal.UniversalPlugin
import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport._
import sbt._
import sbt.Keys._
import sbt._

/** Helper code for sbt-native-packager integration.
*
Expand Down
5 changes: 0 additions & 5 deletions src/test/scala/CertificationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

package net.bzzt.reproduciblebuilds

import java.math.BigInteger

import org.scalatest._

import scala.collection.mutable
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

Expand Down

0 comments on commit 2514af0

Please sign in to comment.