Skip to content

Commit

Permalink
filter Var and Assign
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 13, 2024
1 parent e207795 commit 490abea
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions input/src/main/scala-2/fix/DiscardCatsEffectIOTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ trait DiscardCatsEffectIOTest {

x1 // assert: DiscardCatsEffectIO

var mutableValue: IO[Int] = x1

mutableValue = x1

x1
}
}
4 changes: 4 additions & 0 deletions input/src/main/scala-2/fix/DiscardEffTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ trait DiscardEffTest {

x1.flatMap(y => x1.map(_ + y)) // assert: DiscardEff

var mutableValue: Eff[R, Int] = null

mutableValue = x1

x1 // assert: DiscardEff

x1
Expand Down
4 changes: 4 additions & 0 deletions input/src/main/scala-2/fix/DiscardMonixTaskTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ trait DiscardMonixTaskTest {

x1 // assert: DiscardMonixTask

var mutableValue: Task[Int] = null

mutableValue = x1

x1
}
}
4 changes: 4 additions & 0 deletions input/src/main/scala-2/fix/DiscardScalaFutureTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ trait DiscardScalaFutureTest {

x1 // assert: DiscardScalaFuture

var mutableValue: Future[Int] = null

mutableValue = x1

x1
}
}
4 changes: 1 addition & 3 deletions rules/src/main/scala/fix/DiscardValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ object DiscardValue {
)(implicit doc: SemanticDocument): Patch = {
doc.tree.collect { case Term.Block(values :+ _) => // ignore last
values.filter {
case _: Defn.Val =>
false
case _: Defn.Def =>
case _: Defn.Val | _: Defn.Def | _: Term.Assign | _: Defn.Var =>
false
case x =>
x.collectFirst {
Expand Down

0 comments on commit 490abea

Please sign in to comment.