Skip to content

Commit

Permalink
Add explicit result types for public API (#2955)
Browse files Browse the repository at this point in the history
Pull request: #2955
  • Loading branch information
lefou authored Jan 11, 2024
1 parent 1377356 commit b9c5e90
Show file tree
Hide file tree
Showing 102 changed files with 480 additions and 406 deletions.
5 changes: 3 additions & 2 deletions bsp/src/mill/bsp/Constants.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package mill.bsp

import os.SubPath
private[mill] object Constants {
val bspDir = os.sub / ".bsp"
val bspDir: SubPath = os.sub / ".bsp"
val bspProtocolVersion = BuildInfo.bsp4jVersion
val bspWorkerImplClass = "mill.bsp.worker.BspWorkerImpl"
val bspWorkerBuildInfoClass = "mill.bsp.worker.BuildInfo"
val languages = Seq("scala", "java")
val languages: Seq[String] = Seq("scala", "java")
val serverName = "mill-bsp"
}
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private class MillBuildServer(
) extends ExternalModule
with BuildServer {

lazy val millDiscover: Discover[MillBuildServer.this.type] = Discover[this.type]
lazy val millDiscover: Discover[this.type] = Discover[this.type]

private[worker] var cancellator: Boolean => Unit = shutdownBefore => ()
private[worker] var onSessionEnd: Option[BspServerResult => Unit] = None
Expand All @@ -108,7 +108,7 @@ private class MillBuildServer(
}
}

def debug(msg: String) = logStream.println(msg)
def debug(msg: String): Unit = logStream.println(msg)

def onConnectWithClient(buildClient: BuildClient): Unit = client = buildClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package mill.contrib.artifactory
import java.util.Base64

import scala.concurrent.duration._
import requests.Session

class ArtifactoryHttpApi(
credentials: String,
readTimeout: Int,
connectTimeout: Int
) {
val http = requests.Session(
val http: Session = requests.Session(
readTimeout = readTimeout,
connectTimeout = connectTimeout,
maxRedirects = 0,
Expand Down
14 changes: 8 additions & 6 deletions contrib/bintray/src/mill/contrib/bintray/BintrayHttpApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.time.format.DateTimeFormatter
import java.util.Base64

import scala.concurrent.duration._
import requests.Session

class BintrayHttpApi(
owner: String,
Expand All @@ -16,7 +17,7 @@ class BintrayHttpApi(
connectTimeout: Int,
log: Logger
) {
val http = requests.Session(
val http: Session = requests.Session(
readTimeout = readTimeout,
connectTimeout = connectTimeout,
maxRedirects = 0,
Expand All @@ -25,7 +26,7 @@ class BintrayHttpApi(

private val uploadTimeout = 5.minutes.toMillis.toInt

def now = ZonedDateTime.now(ZoneOffset.UTC)
def now: ZonedDateTime = ZonedDateTime.now(ZoneOffset.UTC)

// https://www.jfrog.com/confluence/display/BT/Bintray+REST+API#BintrayRESTAPI-UploadContent
def upload(
Expand Down Expand Up @@ -90,9 +91,10 @@ class BintrayHttpApi(

object Paths {
val root = "https://api.bintray.com"
def upload(pkg: String, version: String) = s"$root/content/$owner/$repo/$pkg/$version"
def publish(pkg: String, version: String) = s"$root/content/$owner/$repo/$pkg/$version/publish"
def version(pkg: String) = s"$root/packages/$owner/$repo/$pkg/versions"
def upload(pkg: String, version: String): String = s"$root/content/$owner/$repo/$pkg/$version"
def publish(pkg: String, version: String): String =
s"$root/content/$owner/$repo/$pkg/$version/publish"
def version(pkg: String): String = s"$root/packages/$owner/$repo/$pkg/versions"
}

object ContentTypes {
Expand All @@ -102,7 +104,7 @@ class BintrayHttpApi(
}

object Auth {
val basic = s"Basic ${base64(credentials)}"
val basic: String = s"Basic ${base64(credentials)}"
}

private def base64(s: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class BintrayPublisher(
log
)

def publish(publishData: BintrayPublishData) = publishAll(publishData)
def publishAll(publishData: BintrayPublishData*) = {
def publish(publishData: BintrayPublishData): Unit = publishAll(publishData)
def publishAll(publishData: BintrayPublishData*): Unit = {
val mappings =
for {
BintrayPublishData(meta, payload, pkg) <- publishData
Expand Down
4 changes: 2 additions & 2 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
Result.Success(sources.toMap)
}

protected def name(m: JavaModule) = ModuleUtils.moduleDisplayName(m) match {
protected def name(m: JavaModule): String = ModuleUtils.moduleDisplayName(m) match {
case "" => "root-module"
case n => n
}
Expand Down Expand Up @@ -433,5 +433,5 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
}
}

lazy val millDiscover = Discover[this.type]
lazy val millDiscover: Discover[this.type] = Discover[this.type]
}
7 changes: 4 additions & 3 deletions contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mill.contrib.buildinfo

import mill.{PathRef, T}
import mill.T
import mill.api.PathRef
import mill.scalalib.{JavaModule, ScalaModule}
import mill.scalanativelib.ScalaNativeModule
import mill.scalajslib.ScalaJSModule
Expand Down Expand Up @@ -34,7 +35,7 @@ trait BuildInfo extends JavaModule {
*/
def buildInfoMembers: T[Seq[BuildInfo.Value]] = Seq.empty[BuildInfo.Value]

def resources =
def resources: T[Seq[PathRef]] =
if (buildInfoStaticCompiled) super.resources
else T.sources { super.resources() ++ Seq(buildInfoResources()) }

Expand Down Expand Up @@ -219,7 +220,7 @@ object BuildInfo {
""".stripMargin.trim
}

def commentStr(v: Value) = {
def commentStr(v: Value): String = {
if (v.comment.isEmpty) ""
else {
val lines = v.comment.linesIterator.toVector
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package mill.contrib.codeartifact

import scala.concurrent.duration._
import requests.Session

class CodeartifactHttpApi(
credentials: String,
readTimeout: Int,
connectTimeout: Int
) {
val http = requests.Session(
val http: Session = requests.Session(
readTimeout = readTimeout,
connectTimeout = connectTimeout,
maxRedirects = 0,
Expand Down
3 changes: 2 additions & 1 deletion contrib/gitlab/src/mill/contrib/gitlab/GitlabUploader.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mill.contrib.gitlab

import scala.concurrent.duration._
import requests.Session

object GitlabUploader {
type Upload = (String, Array[Byte]) => requests.Response
Expand All @@ -11,7 +12,7 @@ class GitlabUploader(
readTimeout: Int = 5000,
connectTimeout: Int = 5000
) {
val http = requests.Session(
val http: Session = requests.Session(
readTimeout = readTimeout,
connectTimeout = connectTimeout,
maxRedirects = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ trait RouteCompilerWorkerModule extends Module {
private[playlib] object RouteCompilerWorkerModule
extends ExternalModule
with RouteCompilerWorkerModule {
lazy val millDiscover = Discover[this.type]
lazy val millDiscover: Discover[this.type] = Discover[this.type]
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,5 @@ trait ScalaPBWorkerApi {

object ScalaPBWorkerApi extends ExternalModule {
def scalaPBWorker: Worker[ScalaPBWorker] = T.worker { new ScalaPBWorker() }
lazy val millDiscover = Discover[this.type]
lazy val millDiscover: Discover[this.type] = Discover[this.type]
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ object ScoverageReportWorker extends ExternalModule {

def scoverageReportWorker: Worker[ScoverageReportWorker] =
T.worker { new ScoverageReportWorker() }
lazy val millDiscover = Discover[this.type]
lazy val millDiscover: Discover[this.type] = Discover[this.type]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mill.contrib.versionfile

import scala.util.matching.Regex
sealed trait Version {

import Version._
Expand Down Expand Up @@ -44,7 +45,7 @@ object Bump {
val minor = "minor"
val patch = "patch"

val values = Seq(major, minor, patch)
val values: Seq[String] = Seq(major, minor, patch)
}

object Version {
Expand All @@ -60,8 +61,8 @@ object Version {
case class Release(major: Int, minor: Int, patch: Int) extends Version
case class Snapshot(major: Int, minor: Int, patch: Int) extends Version

val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r
val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.(\d+)-SNAPSHOT""".r
val ReleaseVersion: Regex = raw"""(\d+)\.(\d+)\.(\d+)""".r
val MinorSnapshotVersion: Regex = raw"""(\d+)\.(\d+)\.(\d+)-SNAPSHOT""".r

import upickle.default._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait VersionFileModule extends Module {
writeVersionToFile(versionFile(), version())
}

def writeVersionToFile(versionFile: mill.api.PathRef, version: Version) =
def writeVersionToFile(versionFile: mill.api.PathRef, version: Version): Unit =
os.write.over(
versionFile.path,
version.toString
Expand All @@ -58,7 +58,7 @@ trait VersionFileModule extends Module {
)
}

def generateCommitMessage(version: Version) =
def generateCommitMessage(version: Version): String =
version match {
case release: Version.Release => s"Setting release version to $version"
case snapshot: Version.Snapshot => s"Setting next version to $version"
Expand Down
2 changes: 1 addition & 1 deletion example/src/mill/integration/ExampleTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ object ExampleTestSuite extends IntegrationTestSuite {
}
}

def processCommandBlock(workspaceRoot: os.Path, commandBlock: String) = {
def processCommandBlock(workspaceRoot: os.Path, commandBlock: String): Unit = {
val commandBlockLines = commandBlock.linesIterator.toVector

val expectedSnippets = commandBlockLines.tail
Expand Down
2 changes: 1 addition & 1 deletion idea/src/mill/idea/GenIdea.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ object GenIdea extends ExternalModule {
}
}

override lazy val millDiscover = Discover[this.type]
override lazy val millDiscover: Discover[this.type] = Discover[this.type]
}
8 changes: 4 additions & 4 deletions idea/src/mill/idea/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ case class GenIdeaImpl(
fixedFiles ++ ideaWholeConfigFiles ++ fileComponentContributions ++ libraries ++ moduleFiles
}

def relify(p: os.Path) = {
def relify(p: os.Path): String = {
val r = p.relativeTo(ideaDir / "mill_modules")
(Seq.fill(r.ups)("..") ++ r.segments).mkString("/")
}
Expand Down Expand Up @@ -668,15 +668,15 @@ case class GenIdeaImpl(
</project>
}

def scalaSettingsTemplate() = {
def scalaSettingsTemplate(): Elem = {
// simpleIdeaConfigFileTemplate(Map("ScalaProjectSettings" -> Map("scFileMode" -> "Ammonite")))
<project version={"" + ideaConfigVersion}>
<component name="ScalaProjectSettings">
<option name="scFileMode" value="Ammonite" />
</component>
</project>
}
def miscXmlTemplate(jdkInfo: (String, String)) = {
def miscXmlTemplate(jdkInfo: (String, String)): Elem = {
<project version={"" + ideaConfigVersion}>
<component name="ProjectRootManager" version="2" languageLevel={jdkInfo._1} project-jdk-name={
jdkInfo._2
Expand All @@ -686,7 +686,7 @@ case class GenIdeaImpl(
</project>
}

def allModulesXmlTemplate(selectors: Seq[String]) = {
def allModulesXmlTemplate(selectors: Seq[String]): Elem = {
<project version={"" + ideaConfigVersion}>
<component name="ProjectModuleManager">
<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import utest._

object BspInstallDebugTests extends IntegrationTestSuite {

val bsp4jVersion = sys.props.getOrElse("BSP4J_VERSION", ???)
val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", ???)
// we purposely enable debugging in this simulated test env
override val debugLog: Boolean = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mill.bsp.Constants
import utest._

object BspInstallTests extends IntegrationTestSuite {
val bsp4jVersion = sys.props.getOrElse("BSP4J_VERSION", ???)
val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", ???)

def tests: Tests = Tests {
test("BSP install") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mill.bsp.Constants
import utest._

object BspModulesTests extends IntegrationTestSuite {
val bsp4jVersion = sys.props.getOrElse("BSP4J_VERSION", ???)
val bsp4jVersion: String = sys.props.getOrElse("BSP4J_VERSION", ???)

def tests: Tests = Tests {
test("BSP module with foreign modules") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mill.integration
import utest._

object DocAnnotationsTests extends IntegrationTestSuite {
def globMatches(glob: String, input: String) = {
def globMatches(glob: String, input: String): Boolean = {
StringContext
.glob(
// Normalize the line separator to be `\n` for comparisons
Expand Down
3 changes: 2 additions & 1 deletion integration/feature/foreign/test/src/ForeignBuildsTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package local

import utest._
import utest.framework.TestPath
import os.SubPath

object ForeignBuildsTest extends IntegrationTestSuite {
override def buildPath = os.sub / "project" / "build.sc"
override def buildPath: SubPath = os.sub / "project" / "build.sc"

val tests = Tests {
initWorkspace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package mill.integration
package local

import utest._
import os.SubPath

object ForeignConflictTest extends IntegrationTestSuite {

override def buildPath = os.sub / "conflict" / "build.sc"
override def buildPath: SubPath = os.sub / "conflict" / "build.sc"

val tests = Tests {
initWorkspace()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import mill.integration.IntegrationTestSuite
import utest._

import scala.util.Try
import os.Path

object GenIdeaExtendedTests extends IntegrationTestSuite {

override def scriptSourcePath = super.scriptSourcePath / "extended"
override def scriptSourcePath: Path = super.scriptSourcePath / "extended"

private val scalaVersionLibPart = "2_13_6"

Expand Down
3 changes: 2 additions & 1 deletion integration/feature/gen-idea/test/src/GenIdeaTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import utest.{Tests, assert, _}
import scala.util.Try
import mill.integration.IntegrationTestSuite
import GenIdeaUtils._
import os.Path

object GenIdeaTests extends IntegrationTestSuite {

override def scriptSourcePath = super.scriptSourcePath / "hello-world"
override def scriptSourcePath: Path = super.scriptSourcePath / "hello-world"
private val scalaVersionLibPart = "2_12_5"

def tests: Tests = Tests {
Expand Down
Loading

0 comments on commit b9c5e90

Please sign in to comment.