Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scalafix #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ jobs:
- name: Setup sbt
uses: sbt/setup-sbt@v1

- name: 'Linter: Scalafix checks'
shell: bash
run: sbt '++ ${{ matrix.scala }}' 'scalafixAll --check'

- name: Install sbt
if: matrix.os == 'macos-latest'
shell: bash
Expand Down
32 changes: 32 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
rules = [
DisableSyntax, # Disables some constructs that make no semantic sense like `final val`
ProcedureSyntax, # Procedure syntax in Scala is always discouraged
ExplicitResultTypes, # To avoid public API breakages by mistake is good to always annotate the return types of public methods
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.noIsInstanceOf = 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
}
16 changes: 16 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ ThisBuild / githubWorkflowPublish := Seq(
)
)

ThisBuild / githubWorkflowBuildPreamble := Seq(
WorkflowStep.Sbt(List("scalafixAll --check"), name = Some("Linter: Scalafix checks"))
)

ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(
Expand Down Expand Up @@ -221,3 +225,15 @@ ThisBuild / githubWorkflowBuildPreamble ++= Seq(
name = Some("Install sbt")
)
)

// scalafix specific settings
inThisBuild(
List(
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalafixScalaBinaryVersion := scalaBinaryVersion.value,
scalacOptions ++= Seq(
"-Ywarn-unused"
)
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
package org.mdedetrich.pekko.http

import org.apache.pekko
import org.mdedetrich.pekko.json.stream.JsonStreamParser
import org.typelevel.jawn.Facade

import scala.concurrent.{Future, Promise}

import pekko.http.scaladsl.model.HttpEntity
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.unmarshalling.{FromEntityUnmarshaller, Unmarshaller}
import pekko.http.scaladsl.util.FastFuture
import pekko.stream._
import pekko.stream.scaladsl.Sink
import pekko.stream.stage._
import org.mdedetrich.pekko.json.stream.JsonStreamParser
import org.typelevel.jawn.Facade

import scala.concurrent.{Future, Promise}

trait JsonSupport {

Expand Down
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.24.0")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@
package org.mdedetrich.pekko.json.stream

import org.apache.pekko
import pekko.NotUsed
import pekko.stream.Attributes.name
import pekko.stream.scaladsl.{Flow, Keep, Sink}
import pekko.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import pekko.stream._
import pekko.util.ByteString
import org.typelevel.jawn.AsyncParser.ValueStream
import org.typelevel.jawn._

import java.nio.ByteBuffer

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.concurrent.Future
import scala.util.Try
import java.nio.ByteBuffer

import pekko.NotUsed
import pekko.stream.Attributes.name
import pekko.stream.scaladsl.{Flow, Keep, Sink}
import pekko.stream.stage.{GraphStage, GraphStageLogic, InHandler, OutHandler}
import pekko.stream._
import pekko.util.ByteString

object JsonStreamParser {

Expand Down Expand Up @@ -132,9 +134,9 @@ object JsonStreamParser {

final class JsonStreamParser[J: Facade] private (mode: AsyncParser.Mode, multiValue: Boolean)
extends GraphStage[FlowShape[ByteString, J]] {
private[this] val in = Inlet[ByteString]("Json.in")
private[this] val out = Outlet[J]("Json.out")
override val shape = FlowShape(in, out)
private[this] val in = Inlet[ByteString]("Json.in")
private[this] val out = Outlet[J]("Json.out")
override val shape: FlowShape[ByteString, J] = FlowShape(in, out)
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic =
new JsonStreamParser.ParserLogic[J](AsyncParser[J](mode, multiValue), shape)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

package org.mdedetrich.pekko.http.support

import org.apache.pekko
import pekko.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.unmarshalling.FromEntityUnmarshaller
import io.circe.jawn.CirceSupportParser._
import io.circe.{Decoder, Encoder, Json, Printer}

import org.apache.pekko
import org.mdedetrich.pekko.http.JsonSupport
import org.mdedetrich.pekko.stream.support.CirceStreamSupport

import pekko.http.scaladsl.marshalling.{Marshaller, ToEntityMarshaller}
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.unmarshalling.FromEntityUnmarshaller

trait CirceHttpSupport extends JsonSupport {

implicit def circeJsonUnmarshaller: FromEntityUnmarshaller[Json] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
package org.mdedetrich.pekko.stream
package support

import org.apache.pekko
import pekko.NotUsed
import pekko.stream.scaladsl.Flow
import pekko.util.ByteString
import io.circe.CursorOp.DownField
import io.circe.jawn.CirceSupportParser._
import io.circe._
import io.circe.jawn.CirceSupportParser._
import org.apache.pekko
import org.mdedetrich.pekko.json.stream.JsonStreamParser
import org.typelevel.jawn.AsyncParser

import pekko.NotUsed
import pekko.stream.scaladsl.Flow
import pekko.util.ByteString

trait CirceStreamSupport {

def decode[A: Decoder]: Flow[ByteString, A, NotUsed] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,9 @@

package org.mdedetrich.pekko.http

import org.apache.pekko
import pekko.actor.ActorSystem
import pekko.http.scaladsl.marshalling.Marshal
import pekko.http.scaladsl.model.HttpCharsets.`UTF-8`
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.model.{HttpEntity, RequestEntity, UniversalEntity}
import pekko.http.scaladsl.unmarshalling.Unmarshal
import pekko.stream.scaladsl.{Keep, Sink, Source}
import pekko.util.ByteString
import io.circe.generic.semiauto._
import io.circe.{Decoder, Encoder, Printer}
import org.apache.pekko
import org.mdedetrich.pekko.http.support.CirceHttpSupport
import org.mdedetrich.pekko.stream.support.CirceStreamSupport
import org.scalatest._
Expand All @@ -38,6 +30,15 @@ import org.typelevel.jawn.{AsyncParser, ParseException}
import scala.concurrent.Await
import scala.concurrent.duration._

import pekko.actor.ActorSystem
import pekko.http.scaladsl.marshalling.Marshal
import pekko.http.scaladsl.model.HttpCharsets.`UTF-8`
import pekko.http.scaladsl.model.MediaTypes.`application/json`
import pekko.http.scaladsl.model.{HttpEntity, RequestEntity, UniversalEntity}
import pekko.http.scaladsl.unmarshalling.Unmarshal
import pekko.stream.scaladsl.{Keep, Sink, Source}
import pekko.util.ByteString

case class Foo(bar: String, baz: Int, qux: List[Boolean])
object Foo {
implicit val decoderFoo: Decoder[Foo] = deriveDecoder
Expand All @@ -56,15 +57,15 @@ class JsonSupportSpec
with Matchers
with BeforeAndAfterAll {

val foo = Foo("bar", 42, List(true, false))
val goodJson = """{"bar":"bar","baz":42,"qux":[true,false]}"""
val incompleteJson = """{"bar":"bar","baz":42,"qux"""
val badJson = """{"bar":"bar"}"""
val badBarJson = """{"foo":{"bar":"bar"}}"""
val wrongJson = """{"bar":"bar","baz":"forty two","qux":[]}"""
val wrongBarJson = """{"foo":{"bar":"bar","baz":"forty two","qux":[]}}"""
val invalidJson = """{"bar"="bar"}"""
val prettyJson =
val foo: Foo = Foo("bar", 42, List(true, false))
val goodJson: String = """{"bar":"bar","baz":42,"qux":[true,false]}"""
val incompleteJson: String = """{"bar":"bar","baz":42,"qux"""
val badJson: String = """{"bar":"bar"}"""
val badBarJson: String = """{"foo":{"bar":"bar"}}"""
val wrongJson: String = """{"bar":"bar","baz":"forty two","qux":[]}"""
val wrongBarJson: String = """{"foo":{"bar":"bar","baz":"forty two","qux":[]}}"""
val invalidJson: String = """{"bar"="bar"}"""
val prettyJson: String =
"""
|{
| "bar" : "bar",
Expand Down
Loading