Skip to content

Commit b2262a9

Browse files
committed
Test scalafix downstream
Couldn't work out how to check inferred types.
1 parent ecd8560 commit b2262a9

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

downstream-tests/.scalafix.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rules = [
2+
ScalaJsReactEffectAgnosticism,
3+
]

downstream-tests/build.sbt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,17 @@ lazy val jsCE = project
174174
},
175175
jsDependencies += (ProvidedJS / "polyfill.js") % Test,
176176
)
177+
178+
lazy val generic = project
179+
.enablePlugins(ScalaJSPlugin)
180+
.configure(commonSettings)
181+
.settings(
182+
scalaJSStage := jsStage,
183+
libraryDependencies ++= {
184+
val ver = version.value.stripSuffix("-SNAPSHOT") + "-SNAPSHOT"
185+
Seq(
186+
"com.github.japgolly.scalajs-react" %%% "core-generic" % ver,
187+
"com.github.japgolly.scalajs-react" %%% "util-dummy-defaults" % ver % Provided,
188+
)
189+
},
190+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package downstream
2+
3+
import japgolly.scalajs.react.util.DefaultEffects._
4+
5+
object ScalafixTest {
6+
def x: Sync[Int] = Sync.delay(1)
7+
}

downstream-tests/scalafix.sbt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This is here just to manually test using the ScalaJsReactEffectAgnosticism
2+
// scalafix rule downstream.
3+
4+
ThisBuild / scalacOptions ++= {
5+
if (scalaVersion.value startsWith "2")
6+
"-Yrangepos" :: Nil
7+
else
8+
Nil
9+
}
10+
11+
ThisBuild / semanticdbEnabled := true
12+
13+
ThisBuild / semanticdbVersion := "4.4.23"
14+
15+
ThisBuild / scalafixScalaBinaryVersion := "2.13"
16+
17+
ThisBuild / scalafixDependencies += {
18+
val ver = version.value.stripSuffix("-SNAPSHOT") + "-SNAPSHOT"
19+
"com.github.japgolly.scalajs-react" %% "scalafix" % ver
20+
}

scalafixRules/src/main/scala/sjr/ProhibitDefaultEffects.scala

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,28 @@ class ProhibitDefaultEffects extends SemanticRule("ProhibitDefaultEffects") {
99

1010
override def fix(implicit doc: SemanticDocument): Patch = {
1111
doc.tree.collect {
12-
case a: Decl.Def => check(a.decltpe)
13-
case a: Decl.Val => check(a.decltpe)
14-
case a: Decl.Var => check(a.decltpe)
15-
case a: Defn.Def => check(a.decltpe)
16-
case a: Defn.Val => check(a.decltpe)
17-
case a: Defn.Var => check(a.decltpe)
18-
case a: Term.Param => check(a.decltpe)
12+
13+
// case Defn.Def(_, name, _, _, None, body) => checkImplicit(name, body)
14+
// case Defn.Val(_, Pat.Var(name) :: Nil, None, body) => checkImplicit(name, body)
15+
// case Defn.Var(_, Pat.Var(name) :: Nil, None, Some(body)) => checkImplicit(name, body)
16+
17+
case a: Decl.Def => checkExplicit(a.decltpe)
18+
case a: Decl.Val => checkExplicit(a.decltpe)
19+
case a: Decl.Var => checkExplicit(a.decltpe)
20+
case a: Defn.Def => checkExplicit(a.decltpe)
21+
case a: Defn.Val => checkExplicit(a.decltpe)
22+
case a: Defn.Var => checkExplicit(a.decltpe)
23+
case a: Term.Param => checkExplicit(a.decltpe)
1924
}.asPatch
2025
}
2126

22-
private def check(o: Option[Type])(implicit doc: SemanticDocument): Patch =
23-
o.fold(Patch.empty)(check(_))
27+
// private def checkImplicit(name: Name, body: Term)(implicit doc: SemanticDocument): Patch = {
28+
// }
29+
30+
private def checkExplicit(o: Option[Type])(implicit doc: SemanticDocument): Patch =
31+
o.fold(Patch.empty)(checkExplicit(_))
2432

25-
private def check(t: Type)(implicit doc: SemanticDocument): Patch =
33+
private def checkExplicit(t: Type)(implicit doc: SemanticDocument): Patch =
2634
if (isDefaultEffect(t.symbol))
2735
Patch.lint(DefaultEffectDetected(t.pos))
2836
else

0 commit comments

Comments
 (0)