Skip to content

Commit

Permalink
Squashed commits: WIP - Unit3 cross compilation and test fixes
Browse files Browse the repository at this point in the history
This is the commit message scalacenter#2:

WIP unit3 to show code, not working
unit3 munit dep: exclude 2.13 and include munit_3 instead

WIP unit3 fixed some unit3 compilation errors, many  errors, all similar, on unit2* to fix

This is the commit message scalacenter#2:

fixed compilation error unit SaveExpect class ()

unit2Target2 fix with scalatest version to 3.2.0, but this shouldn't be bumped as per comment(breaking clients via eviction)

fix unit2Target2 by reintroducing scalatest 3.2.0 in unit libs for scala2 versions

unit3 fix Test/compilation errors

unit3 test RuleDecoderSuite: removed scalafix.v1.Rule rules not available in scala3: explicitResultTypes and ProcedureSintax

unit3 moved test ScalafixArgumentsSuite to scala-2, cause it depends on semanticdb-scalac_3.1.3

unit3 changed CliGitDiffSuite.'works on Patch' to not use ProcedureSyntaxRule cause not available for scala3

Revert "unit3 moved test ScalafixArgumentsSuite to scala-2, cause it depends on semanticdb-scalac_3.1.3"

This reverts commit 7bad87b.

unit3 ScalafixArgumentSuite compat/semanticdb split, version 2 pr comments applied

unit3 unmanagedresources folders for cross compilation, scalafmt and scalafixAll applied

unit3 introduced CompatSemanticdb for scala3 with semanticdb new options, fixed one unit test

 This is the commit message scalacenter#2:

unit 3 PrettyExpectSuite split expected results between scala2 and 3

 This is the commit message scalacenter#3:

unit 3 Apply suggestions from code review, small changes to build and rules

Co-authored-by: Brice Jaglin <bjaglin@gmail.com>
 This is the commit message scalacenter#4:

change scalatest dep and refactored jgit

 This is the commit message scalacenter#5:

fix windows ci scaladoc issue on paths: upgrade scala3 to 3.2.0

 This is the commit message scalacenter#6:

unit3 test rulecompiler

 This is the commit message scalacenter#7:

unit3 ToolClasspathSuite changed dependency to scalatest and renamings

 This is the commit message scalacenter#8:

unit3 ScalafixArgumentsSuite and classes to provide compiler options

 This is the commit message scalacenter#9:

unit3 scalafmt and scalafixAll
  • Loading branch information
rvacaru committed Oct 1, 2022
1 parent e08e1cb commit 58f0ec5
Show file tree
Hide file tree
Showing 27 changed files with 374 additions and 293 deletions.
43 changes: 29 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,7 @@ lazy val testkit = projectMatrix
moduleName := "scalafix-testkit",
isFullCrossVersion,
libraryDependencies += googleDiff,
libraryDependencies ++= {
if (!isScala3.value)
Seq(scalatest)
else
Seq("org.scalatest" %% "scalatest" % scalatest3V)
}
libraryDependencies += scalatestDep.value
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions :+ scala3)
Expand All @@ -231,14 +226,29 @@ lazy val unit = projectMatrix
testFrameworks += new TestFramework("munit.Framework"),
buildInfoPackage := "scalafix.tests",
buildInfoObject := "BuildInfo",
libraryDependencies ++= List(
jgit,
coursier,
scalatest.withRevision(
"3.2.13"
), // make sure testkit clients can use recent 3.x versions
scalametaTeskit
),
libraryDependencies += jgit,
libraryDependencies ++= {
if (!isScala3.value) {
List(
coursier,
scalametaTeskit,
scalatest.withRevision(
"3.2.13"
)
)
} else {
List(
scalatestDep.value,
coursier
.exclude("org.scala-lang.modules", "scala-xml_2.13"),
scalametaTeskit
.exclude("com.lihaoyi", "sourcecode_2.13")
.exclude("org.scala-lang.modules", "scala-collection-compat_2.13")
.exclude("org.scalameta", "munit_2.13"),
("org.scalameta" %% "munit" % "0.7.29")
)
}
},
Compile / compile / compileInputs := {
(Compile / compile / compileInputs)
.dependsOn(
Expand Down Expand Up @@ -329,6 +339,11 @@ lazy val unit = projectMatrix
}
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(
scalaVersions = Seq(scala3),
axisValues = Seq(TargetAxis(scala3)),
settings = Seq()
)
.jvmPlatform(
scalaVersions = Seq(scala212),
axisValues = Seq(TargetAxis(scala3)),
Expand Down
14 changes: 8 additions & 6 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Dependencies {
val scala211 = "2.11.12"
val scala212 = "2.12.17"
val scala213 = "2.13.9"
val scala3 = "3.1.3"
val scala3 = "3.2.0"

val buildScalaVersions = Seq(scala211, scala212, scala213)
val testTargetScalaVersions = Seq(scala211, scala212, scala213, scala3)
Expand All @@ -34,13 +34,14 @@ object Dependencies {
val scalaXmlV = "2.1.0"
val scalaXml211V = "1.3.0" // scala-xml stops publishing for scala 2.11
val scalametaV = "4.5.13"
val scalatestV = "3.0.8" // don't bump, to avoid forcing breaking changes on clients via eviction
val scalatest3V = "3.2.13"
val scalatestMinV = "3.0.8" // don't bump, to avoid forcing breaking changes on clients via eviction
val scalatestLatestV = "3.2.13"

val bijectionCore = "com.twitter" %% "bijection-core" % bijectionCoreV
val collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % collectionCompatV
val commonText = "org.apache.commons" % "commons-text" % commontTextV
val coursier = "io.get-coursier" %% "coursier" % coursierV
val coursier = ("io.get-coursier" %% "coursier" % coursierV)
.cross(CrossVersion.for3Use2_13)
val coursierInterfaces = "io.get-coursier" % "interface" % coursierInterfaceV
val googleDiff = "com.googlecode.java-diff-utils" % "diffutils" % googleDiffV
val java8Compat = "org.scala-lang.modules" %% "scala-java8-compat" % java8CompatV
Expand All @@ -57,8 +58,9 @@ object Dependencies {
// https://github.com/scalameta/scalameta/issues/2485
val scalameta = ("org.scalameta" %% "scalameta" % scalametaV)
.cross(CrossVersion.for3Use2_13)
val scalametaTeskit = "org.scalameta" %% "testkit" % scalametaV
val scalatest = "org.scalatest" %% "scalatest" % scalatestV
val scalametaTeskit = ("org.scalameta" %% "testkit" % scalametaV)
.cross(CrossVersion.for3Use2_13)
val scalatest = "org.scalatest" %% "scalatest" % scalatestMinV
val semanticdbScalacCore = "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full

private def previousVersions(scalaVersion: String): List[String] = {
Expand Down
18 changes: 13 additions & 5 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
lazy val buildInfoSettingsForRules: Seq[Def.Setting[_]] = Seq(
buildInfoObject := "RulesBuildInfo"
)

lazy val scalatestDep = Def.setting {
if (isScala3.value) scalatest.withRevision(scalatestLatestV)
else scalatest
}
}

import autoImport._
Expand All @@ -140,11 +145,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
},
commands += Command.command("ci-3") { s =>
"unit2_12Target3/test" ::
"core3/compile" ::
"rules3/compile" ::
"reflect3/compile" ::
"cli3/compile" ::
"testkit3/compile" :: // TODO replace core rules and reflect with unit3 in the end
"unit3Target3/test" ::
s
},
commands += Command.command("ci-213") { s =>
Expand Down Expand Up @@ -228,6 +229,13 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
case _ => Seq()
}
},
Compile / unmanagedResourceDirectories ++= {
val resourceParentDir = (Compile / resourceDirectory).value.getParentFile
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((major, _)) => Seq(resourceParentDir / s"resources-${major}")
case _ => Seq()
}
},
// Don't package sources & docs when publishing locally as it adds a significant
// overhead when testing because of publishLocalTransitive. Tweaking publishArtifact
// would more readable, but it would also affect remote (sonatype) publishing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import dotty.tools.dotc.util.SourceFile
import dotty.tools.dotc.reporting.StoreReporter
import dotty.tools.dotc.interactive.InteractiveDriver
import dotty.tools.io.AbstractFile as DottyAbstractFile
import dotty.tools.io.VirtualFile
import dotty.tools.io.VirtualDirectory as DottyVirtualDirectory

import scala.reflect.io.VirtualDirectory
import scala.reflect.io.PlainDirectory
import scala.reflect.io.AbstractFile
import scala.reflect.internal.util.AbstractFileClassLoader

Expand All @@ -26,26 +28,33 @@ class RuleCompiler(
private val driver = new InteractiveDriver(settings)
private val reporter: StoreReporter = new StoreReporter()
private var ctx: FreshContext = driver.currentCtx.fresh
private val dottyVirtualDirectory = new DottyVirtualDirectory(target.name, None)

private val dottyTargetDirectory: DottyAbstractFile = {
if (target.isVirtual)
new DottyVirtualDirectory(target.name)
else
DottyAbstractFile.getDirectory(target.path)
}
ctx = ctx
.setReporter(reporter)
.setSetting(ctx.settings.outputDir, dottyVirtualDirectory)
.setSetting(ctx.settings.outputDir, dottyTargetDirectory)
.setSetting(ctx.settings.classpath, classpath)

private val compiler: Compiler = new Compiler()
private val classLoader: AbstractFileClassLoader =
new AbstractFileClassLoader(target, this.getClass.getClassLoader)

def compile(input: Input): Configured[ClassLoader] = {
reporter.removeBufferedMessages(using ctx)
val run: Run = compiler.newRun(using ctx)

val dottyFile: DottyAbstractFile = input match {
case Input.File(path, _) => DottyAbstractFile.getFile(input.path)
case Input.VirtualFile(path, _) => VirtualFile(input.path, input.text.getBytes())
case _ => throw RuntimeException("Invalid Input file")
}

run.compileSources(
List(
new SourceFile(
DottyAbstractFile.getFile(input.path),
input.chars
)
)
List(new SourceFile(dottyFile, input.chars))
)

val errors = reporter.allErrors.map(error =>
Expand All @@ -60,6 +69,10 @@ class RuleCompiler(
"to 2.x in your build tool"
)

println(s"ipath ${input.path}")
println(s"try load ${classLoader.tryToLoadClass(input.path + "$")}")
println(s"try load ${classLoader.tryToLoadClass(input.path)}")

ConfError
.apply(errors)
.map(_.notOk)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
scalafix.internal.rule.DisableSyntax
scalafix.internal.rule.NoAutoTupling
scalafix.internal.rule.NoValInForComprehension
scalafix.internal.rule.RedundantSyntax
scalafix.internal.rule.RemoveUnused
scalafix.internal.rule.LeakingImplicitClassVal
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ DisableSyntax.noXml = true
*/
package test.disableSyntax

object NoXml {
object NoXml {{
<a>xml</a> /* assert: DisableSyntax.noXml
^
xml literals should be avoided */
}
}}
113 changes: 113 additions & 0 deletions scalafix-tests/unit/src/main/resources-3/expect/Pretty.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
[6:7..6:17]: test/PrettyTest# => class PrettyTest extends Object { self: PrettyTest => +6 decls }
[7:3..7:14]: *[Int]
[7:3..7:7]: *.apply[Int]
[9:10..9:11]: intWrapper(*)
[10:10..10:11]: intWrapper(*)
[14:10..14:16]: *.apply[Inclusive]
[14:10..14:26]: *(global)
[14:17..14:18]: intWrapper(*)
[15:10..15:16]: *.apply[Inclusive]
[15:10..15:32]: *(global)
[15:17..15:18]: intWrapper(*)
[20:9..20:14]: test/PrettyTest#Inner# => class Inner extends Object { self: Inner => +1 decls }
[21:7..21:8]: test/PrettyTest#a. => val method aPrettyTest
[22:7..22:8]: test/PrettyTest#b. => val method ba.Inner
[24:3..24:9]: *.apply[Object {
local4 => abstract method foo(a: Int): Int
local5 => abstract method bar(a: Int): Int
}]
[28:3..28:9]: *.apply[a.Inner]
[29:3..29:9]: *.apply[Int & String]
[30:3..30:9]: *.apply[PrettyTest]
[37:7..37:10]: test/ann# => class ann[T] extends Annotation with StaticAnnotation { self: ann[T] => +3 decls }
[37:11..37:12]: test/ann#[T] => typeparam T
[37:14..37:15]: test/ann#x. => private[this] val method xT
[38:7..38:11]: test/ann1# => class ann1 extends Annotation with StaticAnnotation { self: ann1 => +1 decls }
[39:7..39:11]: test/ann2# => class ann2 extends Annotation with StaticAnnotation { self: ann2 => +1 decls }
[41:7..41:8]: test/B# => class B extends Object { self: B => +1 decls }
[43:7..43:8]: test/C# => class C extends Object { self: C => +1 decls }
[45:7..45:8]: test/P# => class P extends Object { self: P => +8 decls }
[46:9..46:10]: test/P#C# => class C extends Object { self: C => +1 decls }
[47:9..47:10]: test/P#X# => class X extends Object { self: X => +1 decls }
[48:7..48:8]: test/P#x. => val method xX
[51:7..51:8]: test/T# => class T extends Object { self: T => +8 decls }
[52:9..52:10]: test/T#C# => class C extends Object { self: C => +1 decls }
[53:9..53:10]: test/T#X# => class X extends Object { self: X => +1 decls }
[54:7..54:8]: test/T#x. => val method xX
[57:8..57:12]: test/Test. => final object Test extends Object { self: Test.type => +10 decls }
[58:9..58:10]: test/Test.M# => class M extends Object { self: M => +2 decls }
[59:9..59:10]: test/Test.M#m(). => method m=> Int
[62:9..62:10]: test/Test.N# => trait N extends Object { self: N => +2 decls }
[63:9..63:10]: test/Test.N#n(). => method n=> Int
[66:9..66:10]: test/Test.C# => class C extends M { self: C => +42 decls }
[67:9..67:10]: test/Test.C#p. => val method pP
[68:9..68:10]: test/Test.C#x. => val method xp.X
[70:9..70:17]: test/Test.C#typeRef1. => val method typeRef1C
[71:9..71:17]: test/Test.C#typeRef2. => val method typeRef2p.C
[72:9..72:17]: test/Test.C#typeRef3. => val method typeRef3T#C
[73:9..73:17]: test/Test.C#typeRef4. => val method typeRef4List[Int]
[75:9..75:20]: test/Test.C#singleType1. => val method singleType1x.type
[76:9..76:20]: test/Test.C#singleType2. => val method singleType2p.x.type
[77:9..77:15]: test/Test.C#Either. => val method EitherEither.type
[79:9..79:18]: test/Test.C#thisType1. => val method thisType1C.this.type
[80:9..80:18]: test/Test.C#thisType2. => val method thisType2C.this.type
[82:9..82:19]: test/Test.C#superType1. => val method superType1Int
[83:9..83:19]: test/Test.C#superType2. => val method superType2Int
[84:9..84:19]: test/Test.C#superType3. => val method superType3Int
[86:9..86:22]: test/Test.C#compoundType1. => val method compoundType1Object { def k=> Int }
[87:9..87:22]: test/Test.C#compoundType2. => val method compoundType2M & N
[88:9..88:22]: test/Test.C#compoundType3. => val method compoundType3M & N { def k=> Int }
[89:9..89:22]: test/Test.C#compoundType4. => val method compoundType4Object
[90:9..90:22]: test/Test.C#compoundType5. => val method compoundType5M & N
[91:9..91:22]: test/Test.C#compoundType6. => val method compoundType6M & N
[93:9..93:17]: test/Test.C#annType1. => val method annType1T @ann[T]
[93:21..93:25]: [Int]
[94:9..94:17]: test/Test.C#annType2. => val method annType2T @ann1 @ann2
[96:9..96:25]: test/Test.C#existentialType2. => val method existentialType2List[_] forSome { type _ }
[97:9..97:25]: test/Test.C#existentialType3. => val method existentialType3Class[_] forSome { type _ }
[98:9..98:25]: test/Test.C#existentialType4. => val method existentialType4Class[_] forSome { type _ }
[100:9..100:20]: test/Test.C#typeLambda1(). => method typeLambda1[M[type _]]: Nothing
[100:21..100:22]: test/Test.C#typeLambda1().[M] => typeparam M[type _]
[103:12..103:26]: test/Test.C#ClassInfoType1. => final object ClassInfoType1 extends Object { self: ClassInfoType1.type => +1 decls }
[104:11..104:25]: test/Test.C#ClassInfoType2# => class ClassInfoType2 extends B { self: ClassInfoType2 => +2 decls }
[104:42..104:43]: test/Test.C#ClassInfoType2#x(). => method x=> Int
[105:11..105:25]: test/Test.C#ClassInfoType3# => trait ClassInfoType3[T] extends Object { self: ClassInfoType3[T] => +2 decls }
[105:26..105:27]: test/Test.C#ClassInfoType3#[T] => typeparam T
[107:12..107:22]: test/Test.C#MethodType. => final object MethodType extends Object { self: MethodType.type => +7 decls }
[108:11..108:13]: test/Test.C#MethodType.x1(). => method x1=> Int
[109:11..109:13]: test/Test.C#MethodType.x2(). => method x2=> Int
[110:11..110:13]: test/Test.C#MethodType.m3(). => method m3=> Int
[111:11..111:13]: test/Test.C#MethodType.m4(). => method m4(): Int
[112:11..112:13]: test/Test.C#MethodType.m5(). => method m5(x: Int): Int
[112:14..112:15]: test/Test.C#MethodType.m5().(x) => param x: Int
[113:11..113:13]: test/Test.C#MethodType.m6(). => method m6[T](x: T): T
[113:14..113:15]: test/Test.C#MethodType.m6().[T] => typeparam T
[113:17..113:18]: test/Test.C#MethodType.m6().(x) => param x: T
[116:12..116:22]: test/Test.C#ByNameType. => final object ByNameType extends Object { self: ByNameType.type => +2 decls }
[117:11..117:13]: test/Test.C#ByNameType.m1(). => method m1(x: => Int): Int
[117:14..117:15]: test/Test.C#ByNameType.m1().(x) => param x: => Int
[120:16..120:28]: test/Test.C#RepeatedType# => case class RepeatedType extends Object with Product with Serializable { self: RepeatedType => +4 decls }
[120:29..120:30]: test/Test.C#RepeatedType#s. => val method sString*
[121:11..121:13]: test/Test.C#RepeatedType#m1(). => method m1(x: Int*): Int
[121:14..121:15]: test/Test.C#RepeatedType#m1().(x) => param x: Int*
[124:12..124:20]: test/Test.C#TypeType. => final object TypeType extends Object { self: TypeType.type => +6 decls }
[125:12..125:14]: test/Test.C#TypeType.T1# => type T1
[126:11..126:13]: test/Test.C#TypeType.m2(). => method m2[T2 = C]: Nothing
[126:14..126:16]: test/Test.C#TypeType.m2().[T2] => typeparam T2 = C
[127:11..127:13]: test/Test.C#TypeType.m3(). => method m3[M3[type _]]: Nothing
[127:14..127:16]: test/Test.C#TypeType.m3().[M3] => typeparam M3[type _]
[128:12..128:14]: test/Test.C#TypeType.T4# => type T4 = C
[129:12..129:14]: test/Test.C#TypeType.T5# => type T5[U] = U
[129:15..129:16]: test/Test.C#TypeType.T5#[U] => typeparam U
[133:10..133:17]: test/Test.Literal. => final object Literal extends Object { self: Literal.type => +12 decls }
[134:15..134:18]: test/Test.Literal.int. => final val method int1
[135:15..135:19]: test/Test.Literal.long. => final val method long1L
[136:15..136:20]: test/Test.Literal.float. => final val method float1.0f
[137:15..137:21]: test/Test.Literal.double. => final val method double2.0
[138:15..138:18]: test/Test.Literal.nil. => final val method nilNull
[139:15..139:19]: test/Test.Literal.char. => final val method char'a'
[140:15..140:21]: test/Test.Literal.string. => final val method string"a"
[141:15..141:19]: test/Test.Literal.bool. => final val method booltrue
[142:15..142:19]: test/Test.Literal.unit. => final val method unitUnit
[143:15..143:23]: test/Test.Literal.javaEnum. => final val method javaEnumLinkOption
[144:15..144:22]: test/Test.Literal.clazzOf. => final val method clazzOfOption[Int]
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ExplicitSynthetic() extends SemanticRule("ExplicitSynthetic") {
Patch.addRight(t, ".apply")
}
}
patches.flatten.asPatch + Patch.replaceTree(q"a", "b")
patches.flatten.asPatch + Patch.replaceTree(Term.Name("a"), "b")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package banana.rule
import scala.meta._
import scala.meta.contrib._

import scalafix.XtensionOptionPatch
import scalafix.XtensionSeqPatch
import scalafix.patch.Patch
import scalafix.util.SymbolMatcher
import scalafix.v0
Expand All @@ -11,7 +13,12 @@ import scalafix.v1
case class FqnRule(index: v0.SemanticdbIndex)
extends v0.SemanticRule(index, "FqnRule") {
override def fix(ctx: v0.RuleCtx): Patch =
ctx.addGlobalImport(importer"scala.collection.immutable") + {
ctx.addGlobalImport(
Importer(
Term.Select(Term.Name("scala"), Term.Name("collection")),
List(Importee.Name(Name("immutable")))
)
) + {
val fqnRule = SymbolMatcher.exact(v0.Symbol("test/FqnRule."))
ctx.tree.collect { case fqnRule(t: Term.Name) =>
ctx.addLeft(t, "/* matched */ ")
Expand Down
10 changes: 7 additions & 3 deletions scalafix-tests/unit/src/main/scala/scalafix/test/NoNull.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package scalafix.test

import scala.meta._
import scala.meta.Lit
import scala.meta.XtensionCollectionLikeUI

import scalafix.v0._
import scalafix.lint.Diagnostic
import scalafix.v0.LintCategory
import scalafix.v0.Rule
import scalafix.v0.RuleCtx

object NoNull extends Rule("NoNull") {
val error: LintCategory = LintCategory.error("Nulls are not allowed.")

override def check(ctx: RuleCtx): List[Diagnostic] = ctx.tree.collect {
case nil @ q"null" => error.at(nil.pos)
case nil @ Lit.Null() => error.at(nil.pos)
}
}
Loading

0 comments on commit 58f0ec5

Please sign in to comment.