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 a Scalafix migration for v0.5.0 #88

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
98 changes: 53 additions & 45 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,70 +1,78 @@
import com.typesafe.tools.mima.core._

// Common settings
ThisBuild / organization := "io.github.davidgregory084"
ThisBuild / organizationName := "David Gregory"

name := "sbt-tpolecat"
description := "scalac options for the enlightened"
organization := "io.github.davidgregory084"

organizationName := "David Gregory"
startYear := Some(2022)
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))
scmInfo := Some(
ThisBuild / startYear := Some(2022)
ThisBuild / licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html"))
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/DavidGregory084/sbt-tpolecat"),
"scm:git:git@github.com:DavidGregory084/sbt-tpolecat.git"
)
)
developers := List(
ThisBuild / developers := List(
Developer(
"DavidGregory084",
"David Gregory",
"davidgregory084@gmail.com",
url("https://github.com/DavidGregory084")
)
)
homepage := scmInfo.value.map(_.browseUrl)

crossSbtVersions := Seq("1.6.2")

enablePlugins(SbtPlugin)

// License headers

Compile / headerCreate := { (Compile / headerCreate).triggeredBy(Compile / compile).value }
Test / headerCreate := { (Test / headerCreate).triggeredBy(Test / compile).value }

scalacOptions += "-Xlint:unused"

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.11" % Test,
"org.scalacheck" %% "scalacheck" % "1.15.4" % Test,
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0" % Test
)
ThisBuild / homepage := scmInfo.value.map(_.browseUrl)

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"

ThisBuild / versionScheme := Some(VersionScheme.EarlySemVer)

mimaPreviousArtifacts := Set(
projectID.value.withRevision("0.4.0")
)

mimaBinaryIssueFilters ++= Seq(
)

// Testing

scriptedBufferLog := false
ThisBuild / crossSbtVersions := Seq("1.6.2")

lazy val `sbt-tpolecat` = project
.in(file("."))
.aggregate(`sbt-tpolecat-plugin`)
.settings(
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true,
mimaReportBinaryIssues := {}
)

scriptedLaunchOpts := scriptedLaunchOpts.value ++ Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value
)
lazy val `sbt-tpolecat-plugin` = project
.in(file("plugin"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-tpolecat",
moduleName := "sbt-tpolecat",
description := "scalac options for the enlightened",
Compile / headerCreate := { (Compile / headerCreate).triggeredBy(Compile / compile).value },
Test / headerCreate := { (Test / headerCreate).triggeredBy(Test / compile).value },
scalacOptions += "-Xlint:unused",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.2.11" % Test,
"org.scalacheck" %% "scalacheck" % "1.15.4" % Test,
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0" % Test
),
mimaPreviousArtifacts := Set(
projectID.value.withRevision("0.4.0")
),
mimaBinaryIssueFilters ++= Seq(
),
scriptedBufferLog := false,
scriptedLaunchOpts := scriptedLaunchOpts.value ++ Seq(
"-Xmx1024M",
"-Dplugin.version=" + version.value
),
test := {
(Test / test).value
scripted.toTask("").value
}
)

test := {
(Test / test).value
scripted.toTask("").value
}
lazy val `sbt-tpolecat-scalafix` = scalafixProject("sbt-tpolecat")
.inputSettings(
libraryDependencies += (`sbt-tpolecat-plugin` / projectID).value.withRevision("0.4.0")
)
DavidGregory084 marked this conversation as resolved.
Show resolved Hide resolved
141 changes: 141 additions & 0 deletions project/ScalafixProjectPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import sbt._, Keys._

import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport._
import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport._
import scalafix.sbt._
import ScalafixPlugin.autoImport._
import ScalafixTestkitPlugin.autoImport._

object ScalafixProjectPlugin extends AutoPlugin {
object autoImport {
lazy val V = _root_.scalafix.sbt.BuildInfo
def scalafixProject(name: String) = ScalafixProject(name)
}
}

class ScalafixProject private (
val name: String,
val rules: Project,
val input: Project,
val output: Project,
val tests: Project
) extends CompositeProject {

lazy val componentProjects = Seq(all, rules, input, output, tests)

lazy val all = Project(name, file(s"target/$name-scalafix-aggregate"))
.aggregate(rules, input, output, tests)
.settings(
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true,
mimaReportBinaryIssues := {}
)

def rulesSettings(ss: Def.SettingsDefinition*): ScalafixProject =
rulesConfigure(_.settings(ss: _*))

def inputSettings(ss: Def.SettingsDefinition*): ScalafixProject =
inputConfigure(_.settings(ss: _*))

def outputSettings(ss: Def.SettingsDefinition*): ScalafixProject =
outputConfigure(_.settings(ss: _*))

def testsSettings(ss: Def.SettingsDefinition*): ScalafixProject =
testsConfigure(_.settings(ss: _*))

def rulesConfigure(transforms: (Project => Project)*): ScalafixProject =
new ScalafixProject(
name,
rules.configure(transforms: _*),
input,
output,
tests
)

def inputConfigure(transforms: (Project => Project)*): ScalafixProject =
new ScalafixProject(
name,
rules,
input.configure(transforms: _*),
output,
tests
)

def outputConfigure(transforms: (Project => Project)*): ScalafixProject =
new ScalafixProject(
name,
rules,
input,
output.configure(transforms: _*),
tests
)

def testsConfigure(transforms: (Project => Project)*): ScalafixProject =
new ScalafixProject(
name,
rules,
input,
output,
tests.configure(transforms: _*)
)

}

object ScalafixProject {
def apply(name: String): ScalafixProject = {

lazy val rules = Project(s"$name-scalafix", file(s"scalafix/rules"))
.settings(
moduleName := s"$name-scalafix",
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % _root_.scalafix.sbt.BuildInfo.scalafixVersion
)

lazy val input = Project(s"$name-scalafix-input", file(s"scalafix/input"))
.settings(
headerSources / excludeFilter := AllPassFilter,
scalacOptions ~= { opts => opts.filterNot(Set("-Xfatal-warnings", "-Werror")) }
)
.settings(
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true,
mimaReportBinaryIssues := {}
)

lazy val output = Project(s"$name-scalafix-output", file(s"scalafix/output"))
.settings(
headerSources / excludeFilter := AllPassFilter,
scalacOptions ~= { opts => opts.filterNot(Set("-Xfatal-warnings", "-Werror")) }
)
.settings(
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true,
mimaReportBinaryIssues := {}
)

lazy val tests = Project(s"$name-scalafix-tests", file(s"scalafix/tests"))
.settings(
scalafixTestkitOutputSourceDirectories := (output / Compile / unmanagedSourceDirectories).value,
scalafixTestkitInputSourceDirectories := (input / Compile / unmanagedSourceDirectories).value,
scalafixTestkitInputClasspath := (input / Compile / fullClasspath).value,
scalafixTestkitInputScalacOptions := (input / Compile / scalacOptions).value,
scalafixTestkitInputScalaVersion := (input / Compile / scalaVersion).value
)
.dependsOn(rules)
.enablePlugins(ScalafixTestkitPlugin)
.settings(
publish := {},
publishLocal := {},
publishArtifact := false,
publish / skip := true,
mimaReportBinaryIssues := {}
)

new ScalafixProject(name, rules, input, output, tests)
}
}
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.2")

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

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
rule = v0_5
*/
import io.github.davidgregory084.TpolecatPlugin
import io.github.davidgregory084._
import _root_.io.github.davidgregory084.ScalacOption
import _root_.io.github.davidgregory084._

object Tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import org.typelevel.sbt.TpolecatPlugin
import org.typelevel.sbt._
import _root_.org.typelevel.sbt.ScalacOption
import _root_.org.typelevel.sbt._

object Tests
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.typelevel.fix.v0_5
14 changes: 14 additions & 0 deletions scalafix/rules/src/main/scala/org/typelevel/fix/v0_5.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.typelevel.fix

import scalafix.v1._
import scala.meta._

class v0_5 extends SemanticRule("v0_5") {
override def fix(implicit doc: SemanticDocument): Patch =
doc.tree.collect {
case Importer(ref , _) if ref.toString == "io.github.davidgregory084" =>
DavidGregory084 marked this conversation as resolved.
Show resolved Hide resolved
Patch.replaceTree(ref, "org.typelevel.sbt")
case Importer(ref, _) if ref.toString == "_root_.io.github.davidgregory084" =>
Patch.replaceTree(ref, "_root_.org.typelevel.sbt")
DavidGregory084 marked this conversation as resolved.
Show resolved Hide resolved
}.asPatch
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.typelevel.fix

import scalafix.testkit._
import org.scalatest.FunSuiteLike

class RuleSuite extends AbstractSemanticRuleSuite with FunSuiteLike {
runAllTests()
}