Skip to content

Commit

Permalink
scalafix 0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Sep 27, 2024
1 parent f25b0c9 commit 5b1f4c6
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ lazy val rules212 = rules
.enablePlugins(ScalafixPlugin)
.dependsOn(myRuleRule % ScalafixConfig)
.settings(
Test / test := (Test / test).dependsOn(scripted.toTask("")).value,
// TODO re-enable if warning-diff-scalafix-plugin released
// Test / test := (Test / test).dependsOn(scripted.toTask("")).value,
Compile / compile := (Compile / compile).dependsOn((Compile / scalafix).toTask(" MyScalafixRuleRule")).value,
scriptedBufferLog := false,
scriptedLaunchOpts += ("-Dscalafix-rules.version=" + version.value),
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.13.0")

addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.10.0")

Expand Down
2 changes: 1 addition & 1 deletion rules/src/main/scala/fix/FileNameConsistent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ object FileNameConsistent {

implicit class TreeOps(private val self: Defn) extends AnyVal {
def isTopLevel: Boolean =
self.parent.exists(_.is[Pkg]) || self.parent.isEmpty
self.parent.exists(_.is[Pkg.Body]) || self.parent.isEmpty
}
}
4 changes: 3 additions & 1 deletion rules/src/main/scala/fix/ImplicitValueClass.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class ImplicitValueClass extends SyntacticRule("ImplicitValueClass") {
def loop(a: Tree): Boolean = {
a.parent match {
case Some(x) =>
if (x.is[Template] || x.is[Defn.Object] || x.is[Pkg] || x.is[Source]) {
if (
x.is[Template] || x.is[Defn.Object] || x.is[Pkg] || x.is[Source] || x.is[Template.Body] || x.is[Pkg.Body]
) {
loop(x)
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion rules/src/main/scala/fix/ScalaApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ScalaApp extends SyntacticRule("ScalaApp") {
override def fix(implicit doc: SyntacticDocument): Patch = {
doc.tree.collect {
case x1 @ Defn.Object(_, _, Template.Initial(_, (app @ Init.Initial(Type.Name("App"), _, _)) :: tail, _, stats))
if x1.parent.exists(_.is[Pkg]) || x1.parent.isEmpty =>
if x1.parent.exists(_.is[Pkg.Body]) || x1.parent.isEmpty =>
val (classes, newBody) = stats.partition(s => s.is[Defn.Trait] || s.is[Defn.Class] || s.is[Defn.Object])

// TODO
Expand Down
2 changes: 1 addition & 1 deletion rules/src/main/scala/fix/SeparateEachFileRewrite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SeparateEachFileRewrite(config: SeparateEachFileConfig) extends SyntacticR
}
.filter { _ =>
doc.tree.collect {
case t: Stat.WithMods if t.parent.forall(_.is[Pkg]) && t.mods.exists(_.is[Mod.Sealed]) =>
case t: Stat.WithMods if t.parent.forall(_.is[Pkg.Body]) && t.mods.exists(_.is[Mod.Sealed]) =>
()
}.isEmpty
}
Expand Down
4 changes: 2 additions & 2 deletions rules/src/main/scala/fix/SeparateEachFileWarn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class SeparateEachFileWarn(config: SeparateEachFileConfig) extends SyntacticRule
override def fix(implicit doc: SyntacticDocument): Patch = {
if (
doc.tree.collect {
case t: Stat.WithMods if t.parent.forall(_.is[Pkg]) && t.mods.exists(_.is[Mod.Sealed]) =>
case t: Stat.WithMods if t.parent.forall(_.is[Pkg.Body]) && t.mods.exists(_.is[Mod.Sealed]) =>
()
}.isEmpty
) {
val topLevelValues = doc.tree.collect {
case t: (Stat.WithTemplate & Stat.WithMods & Member)
if t.parent.forall(_.is[Pkg]) && t.templ.inits.isEmpty && !t.is[Defn.Object] =>
if t.parent.forall(_.is[Pkg.Body]) && t.templ.inits.isEmpty && !t.is[Defn.Object] =>
t
}

Expand Down

0 comments on commit 5b1f4c6

Please sign in to comment.