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

Upgrade Scalafmt to latest release of 2.6.x serias #11633

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
7b5c1ba370cb8e4779247de639905323271d839e
# Upgrade Scalafmt to 2.5.x
6e6e94d39566c7ad75f13eba7207b5e93fc0ffa9
# Upgrade Scalafmt to 2.6.x
e7923768a51fd30e549572c57506f2387b5337d4
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifi
rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ]
spaces.inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy }
trailingCommas = preserve
version = 2.5.3
version = 2.6.4
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import javax.cache.CacheManager
import play.api.test._

/**
*
*/
class JCacheSpec extends PlaySpecification {
"CacheManager" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,13 @@ object Configuration {
{
setting("config.resource").map(resource => ConfigFactory.parseResources(classLoader, resource))
}.orElse {
setting("config.file").map(fileName => ConfigFactory.parseFileAnySyntax(new File(fileName)))
}
.getOrElse {
val parseOptions = ConfigParseOptions.defaults
.setClassLoader(classLoader)
.setAllowMissing(allowMissingApplicationConf)
ConfigFactory.defaultApplication(parseOptions)
}
setting("config.file").map(fileName => ConfigFactory.parseFileAnySyntax(new File(fileName)))
}.getOrElse {
val parseOptions = ConfigParseOptions.defaults
.setClassLoader(classLoader)
.setAllowMissing(allowMissingApplicationConf)
ConfigFactory.defaultApplication(parseOptions)
}
Comment on lines +71 to +77
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the similar below is nice for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems like they fixed some bugs with the 2.6.x releases 😉

}

// Resolve another .conf file so that we can override values in Akka's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import play.mvc.Http.RequestBody
// Use an `ObjectMapper` which overrides some defaults
class PlayBindingNameJavaJsonSpec extends JavaJsonSpec {
override val createObjectMapper: ObjectMapper = GuiceApplicationBuilder()
// should be able to use `.play.` namespace to override configurations
// for this `ObjectMapper`.
// should be able to use `.play.` namespace to override configurations
// for this `ObjectMapper`.
.configure("akka.serialization.jackson.play.serialization-features.WRITE_DURATIONS_AS_TIMESTAMPS" -> true)
.build()
.injector
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import scala.reflect.ClassTag
* }}}
*
* This will create an application using the current classloader.
*
*/
@implicitNotFound(
msg =
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ object Logger {
* implicit val markerContext: MarkerContext = org.slf4j.MarkerFactory.getMarker("EXAMPLEMARKER")
* log.error("This message will be logged with the EXAMPLEMARKER marker")
* }}}
*
*/
trait MarkerContext {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import scala.concurrent.Future
* GET /assets/\uFEFF*file controllers.ExternalAssets.at(path="C:\external", file)
* GET /assets/\uFEFF*file controllers.ExternalAssets.at(path="relativeToYourApp", file)
* }}}
*
*/
class ExternalAssets @Inject() (environment: Environment)(implicit ec: ExecutionContext, fileMimeTypes: FileMimeTypes)
extends ControllerHelpers {
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/data/Forms.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import play.api.data.validation._
* )
* )
* }}}
*
*/
object Forms {

Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/data/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ package play.api
* )
* )
* }}}
*
*/
package object data
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ trait Constraints {

/**
* $emailAddressDoc
*
*/
def emailAddress: Constraint[String] = emailAddress()

Expand All @@ -111,7 +110,6 @@ trait Constraints {

/**
* $nonEmptyDoc
*
*/
def nonEmpty: Constraint[String] = nonEmpty()

Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/inject/Injector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import scala.reflect.ClassTag
* they are using directly, for example, if using Guice, use
* [[http://google.github.io/guice/api-docs/latest/javadoc/index.html?com/google/inject/Injector.html com.google.inject.Injector]]
* instead of this.
*
*/
trait Injector {

Expand Down
28 changes: 13 additions & 15 deletions core/play/src/main/scala/play/api/inject/Module.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,19 @@ object Modules {
{
tryConstruct(environment, configuration)
}.orElse {
tryConstruct(new JavaEnvironment(environment), configuration.underlying)
}
.orElse {
tryConstruct()
}
.getOrElse {
throw new PlayException(
"No valid constructors",
"Module [" + className + "] cannot be instantiated. " +
"Expected one of:\n" +
"()\n" +
"(play.api.Environment, play.api.Configuration)\n" +
"(play.Environment, com.typesafe.config.Config)"
)
}
tryConstruct(new JavaEnvironment(environment), configuration.underlying)
}.orElse {
tryConstruct()
}.getOrElse {
throw new PlayException(
"No valid constructors",
"Module [" + className + "] cannot be instantiated. " +
"Expected one of:\n" +
"()\n" +
"(play.api.Environment, play.api.Configuration)\n" +
"(play.Environment, com.typesafe.config.Config)"
)
}
} catch {
case e: PlayException => throw e
case e: VirtualMachineError => throw e
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/libs/Comet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import play.twirl.api._
* Ok.chunked(source via Comet.flow("parent.clockChanged"))
* }
* }}}
*
*/
object Comet {
val initialHtmlChunk = Html(Array.fill[Char](5 * 1024)(' ').mkString + "<html><body>")
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/libs/EventSource.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ object EventSource {
* If no extractor is available, the implicit conversion in the low priority traits will be used.
* For the EventDataExtractor, this means `String` or `JsValue` will be automatically mapped,
* and the nameExtractor and idExtractor will implicitly resolve to `None`.
*
*/
def apply[A](a: A)(
implicit dataExtractor: EventDataExtractor[A],
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/mvc/Controller.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ trait RequestImplicits {
* }
* }}}
*
*
* This is intended to provide the idiomatic Play API for actions, allowing you to use "Action" for the default
* action builder and "parse" to access Play's default body parsers. You may want to extend this to provide your own
* base controller class, or write your own version with similar code.
Expand Down
29 changes: 14 additions & 15 deletions core/play/src/main/scala/play/api/mvc/Filters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ trait EssentialFilter {
* {{{
* object AccessLog extends Filter {
* override def apply(next: RequestHeader => Future[Result])(request: RequestHeader): Future[Result] = {
* val result = next(request)
* result.map { r => play.Logger.info(request + "\n\t => " + r; r }
* }
* val result = next(request)
* result.map { r => play.Logger.info(request + "\n\t => " + r; r }
* }
* }
* }}}
*/
Expand Down Expand Up @@ -71,19 +71,18 @@ trait Filter extends EssentialFilter {

Accumulator.flatten(bodyAccumulator.future.map { it =>
it.mapFuture { simpleResult =>
// When the iteratee is done, we can redeem the promised result that was returned to the filter
promisedResult.success(simpleResult)
// When the iteratee is done, we can redeem the promised result that was returned to the filter
promisedResult.success(simpleResult)
result
}.recoverWith {
case t: Throwable =>
// If the iteratee finishes with an error, fail the promised result that was returned to the
// filter with the same error. Note, we MUST use tryFailure here as it's possible that a)
// promisedResult was already completed successfully in the mapM method above but b) calculating
// the result in that method caused an error, so we ended up in this recover block anyway.
promisedResult.tryFailure(t)
result
}
.recoverWith {
case t: Throwable =>
// If the iteratee finishes with an error, fail the promised result that was returned to the
// filter with the same error. Note, we MUST use tryFailure here as it's possible that a)
// promisedResult was already completed successfully in the mapM method above but b) calculating
// the result in that method caused an error, so we ended up in this recover block anyway.
promisedResult.tryFailure(t)
result
}
}
})
}
}
Expand Down
1 change: 0 additions & 1 deletion core/play/src/main/scala/play/api/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ package play {
* {{{
* val application = Application(new File("."), this.getClass.getClassloader, None, Play.Mode.DEV)
* }}}
*
*/
package object api
}
27 changes: 13 additions & 14 deletions core/play/src/main/scala/play/api/routing/sird/PathExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,19 @@ object PathExtractor {
cache.getOrElseUpdate(
parts, {
// "parse" the path
val (regexParts, descs) = parts.tail.map {
part =>
if (part.startsWith("*")) {
// It's a .* matcher
"(.*)" + Pattern.quote(part.drop(1)) -> PathPart.Raw
} else if (part.startsWith("<") && part.contains(">")) {
// It's a regex matcher
val splitted = part.split(">", 2)
val regex = splitted(0).drop(1)
"(" + regex + ")" + Pattern.quote(splitted(1)) -> PathPart.Raw
} else {
// It's an ordinary path part matcher
"([^/]*)" + Pattern.quote(part) -> PathPart.Decoded
}
val (regexParts, descs) = parts.tail.map { part =>
if (part.startsWith("*")) {
// It's a .* matcher
"(.*)" + Pattern.quote(part.drop(1)) -> PathPart.Raw
} else if (part.startsWith("<") && part.contains(">")) {
// It's a regex matcher
val splitted = part.split(">", 2)
val regex = splitted(0).drop(1)
"(" + regex + ")" + Pattern.quote(splitted(1)) -> PathPart.Raw
} else {
// It's an ordinary path part matcher
"([^/]*)" + Pattern.quote(part) -> PathPart.Decoded
}
}.unzip

new PathExtractor(regexParts.mkString(Pattern.quote(parts.head), "", "/?").r, descs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import scala.concurrent.duration._
import scala.concurrent.Await

/**
*
*/
class TextBodyParserSpec extends Specification with AfterAll {
implicit val system: ActorSystem = ActorSystem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object Reloader {
/** Allows to register a listener that will be triggered a monitored file is changed. */
def addChangeListener(f: () => Unit): Unit

/** Reloads the application.*/
/** Reloads the application. */
def reload(): Unit
}

Expand Down Expand Up @@ -412,7 +412,7 @@ object Reloader {
/** Allows to register a listener that will be triggered a monitored file is changed. */
def addChangeListener(f: () => Unit): Unit = ()

/** Reloads the application.*/
/** Reloads the application. */
def reload(): Unit = ()

def close(): Unit = server.stop()
Expand Down Expand Up @@ -474,7 +474,6 @@ class Reloader(
*
* Since this communicates across classloaders, it must return only simple objects.
*
*
* @return Either
* - Throwable - If something went wrong (eg, a compile error).
* - ClassLoader - If the classloader has changed, and the application should be reloaded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object PlayCommands {
case _: ClassNotFoundException =>
state.log.error(
s"""|H2 Dependency not loaded, please add H2 to your Classpath!
|Take a look at https://www.playframework.com/documentation/${play.core.PlayVersion.current}/Developing-with-the-H2-Database#H2-database on how to do it.""".stripMargin
|Take a look at https://www.playframework.com/documentation/${play.core.PlayVersion.current}/Developing-with-the-H2-Database#H2-database on how to do it.""".stripMargin
)
case e: Exception => e.printStackTrace()
}
Expand Down
14 changes: 7 additions & 7 deletions dev-mode/sbt-plugin/src/main/scala/play/sbt/PlaySettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ object PlaySettings {
| /_/ /____/
|""".stripMargin.linesIterator.map(Colors.green(_)).mkString("\n") +
s"""|
|
|Version ${play.core.PlayVersion.current} running Java ${System.getProperty("java.version")}
|
|${Colors.bold(
|
|Version ${play.core.PlayVersion.current} running Java ${System.getProperty("java.version")}
|
|${Colors.bold(
"Play is run entirely by the community. Please consider contributing and/or donating:"
)}
|https://www.playframework.com/sponsors
|
|""".stripMargin +
|https://www.playframework.com/sponsors
|
|""".stripMargin +
(if (javaVersion != "1.8" && javaVersion != "11" && javaVersion != "17")
s"""!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
| Java version is ${sys.props("java.specification.version")}. Play supports only 8, 11 and 17.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,24 @@ object RoutesCompiler extends AutoPlugin {
aggregateReverseRoutes.value
.map { agg => (agg.project / configuration.value / routesCompilerTasks) }
.join
.map {
(aggTasks: Seq[Seq[RoutesCompilerTask]]) =>
// Aggregated tasks need to have forwards router compilation disabled and reverse router compilation enabled.
val reverseRouterTasks = aggTasks.flatten.map { task =>
task.copy(forwardsRouter = false, reverseRouter = true)
}

// Find the routes compile tasks for this project
val thisProjectTasks = sourcesInRoutes.map { file =>
RoutesCompilerTask(
file,
routesImportValue,
forwardsRouter = true,
reverseRouter = generateReverseRouterValue,
namespaceReverseRouter = namespaceReverseRouterValue
)
}

thisProjectTasks ++ reverseRouterTasks
.map { (aggTasks: Seq[Seq[RoutesCompilerTask]]) =>
// Aggregated tasks need to have forwards router compilation disabled and reverse router compilation enabled.
val reverseRouterTasks = aggTasks.flatten.map { task =>
task.copy(forwardsRouter = false, reverseRouter = true)
}

// Find the routes compile tasks for this project
val thisProjectTasks = sourcesInRoutes.map { file =>
RoutesCompilerTask(
file,
routesImportValue,
forwardsRouter = true,
reverseRouter = generateReverseRouterValue,
namespaceReverseRouter = namespaceReverseRouterValue
)
}

thisProjectTasks ++ reverseRouterTasks
}
}.value,
Defaults.ConfigGlobal / watchSources ++= (routes / sources).value,
Expand Down
2 changes: 1 addition & 1 deletion documentation/.scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifi
rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ]
spaces.inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy }
trailingCommas = preserve
version = 2.5.3
version = 2.6.4
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ package scalaguide.http.scalabodyparsers {
val csv: BodyParser[Seq[Seq[String]]] = BodyParser { req =>
// A flow that splits the stream into CSV lines
val sink: Sink[ByteString, Future[Seq[Seq[String]]]] = Flow[ByteString]
// We split by the new line character, allowing a maximum of 1000 characters per line
// We split by the new line character, allowing a maximum of 1000 characters per line
.via(Framing.delimiter(ByteString("\n"), 1000, allowTruncation = true))
// Turn each line to a String and split it by commas
.map(_.utf8String.trim.split(",").toSeq)
Expand Down