-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add DiscardEff, DiscardMonixTask, DiscardScalaFuture
- Loading branch information
Showing
9 changed files
with
453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
rule = DiscardEff | ||
*/ | ||
package fix | ||
|
||
import org.atnos.eff.Eff | ||
import org.mockito.Mockito | ||
import org.mockito.Mockito.verify | ||
|
||
trait DiscardEffTest { | ||
def f0[R]: Eff[R, Int] | ||
|
||
def f1[R](n: Int): Eff[R, Int] | ||
|
||
def mock: DiscardEffTest | ||
|
||
def f2[R]: Eff[R, Int] = { | ||
f0[R] // assert: DiscardEff | ||
|
||
f1[R](2) // assert: DiscardEff | ||
|
||
f1[R](3).map(_ + 4) // assert: DiscardEff | ||
|
||
val x1 = f1[R](5) | ||
def x2: Eff[R, Int] = f1[R](5) | ||
|
||
Mockito.verify(mock).f1(3) | ||
Mockito.verify(mock).f1[R](3) | ||
Mockito.verify(mock, Mockito.times(2)).f1(9) | ||
Mockito.verify(mock, Mockito.times(2)).f1[R](9) | ||
Mockito.verify(mock, Mockito.never()).f1(-1) | ||
Mockito.verify(mock, Mockito.never()).f1[R](-1) | ||
|
||
verify(mock).f0[R] | ||
verify(mock).f1(4) | ||
verify(mock).f1[R](4) | ||
verify(mock, Mockito.times(2)).f1(5) | ||
verify(mock, Mockito.times(2)).f1[R](5) | ||
verify(mock, Mockito.never()).f1(8) | ||
verify(mock, Mockito.never()).f1[R](8) | ||
|
||
x1.flatMap(y => x1.map(_ + y)) // assert: DiscardEff | ||
|
||
x1 // assert: DiscardEff | ||
|
||
x1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
rule = DiscardMonixTask | ||
*/ | ||
package fix | ||
|
||
import monix.eval.Task | ||
import org.mockito.Mockito | ||
import org.mockito.Mockito.verify | ||
|
||
trait DiscardMonixTaskTest { | ||
def f0[R]: Task[Int] | ||
|
||
def f1[R](n: Int): Task[Int] | ||
|
||
def mock: DiscardMonixTaskTest | ||
|
||
def f2[R]: Task[Int] = { | ||
f0[R] // assert: DiscardMonixTask | ||
|
||
f1[R](2) // assert: DiscardMonixTask | ||
|
||
f1[R](3).map(_ + 4) // assert: DiscardMonixTask | ||
|
||
val x1 = f1[R](5) | ||
def x2: Task[Int] = f1[R](5) | ||
|
||
Mockito.verify(mock).f1(3) | ||
Mockito.verify(mock).f1[R](3) | ||
Mockito.verify(mock, Mockito.times(2)).f1(9) | ||
Mockito.verify(mock, Mockito.times(2)).f1[R](9) | ||
Mockito.verify(mock, Mockito.never()).f1(-1) | ||
Mockito.verify(mock, Mockito.never()).f1[R](-1) | ||
|
||
verify(mock).f0[R] | ||
verify(mock).f1(4) | ||
verify(mock).f1[R](4) | ||
verify(mock, Mockito.times(2)).f1(5) | ||
verify(mock, Mockito.times(2)).f1[R](5) | ||
verify(mock, Mockito.never()).f1(8) | ||
verify(mock, Mockito.never()).f1[R](8) | ||
|
||
x1.flatMap(y => x1.map(_ + y)) // assert: DiscardMonixTask | ||
|
||
x1 // assert: DiscardMonixTask | ||
|
||
x1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
rule = DiscardScalaFuture | ||
*/ | ||
package fix | ||
|
||
import scala.concurrent.Future | ||
import scala.concurrent.ExecutionContext | ||
import org.mockito.Mockito | ||
import org.mockito.Mockito.verify | ||
|
||
trait DiscardScalaFutureTest { | ||
def f0[R]: Future[Int] | ||
|
||
def f1[R](n: Int): Future[Int] | ||
|
||
def mock: DiscardScalaFutureTest | ||
|
||
def f2[R](implicit ec: ExecutionContext): Future[Int] = { | ||
f0[R] // assert: DiscardScalaFuture | ||
|
||
f1[R](2) // assert: DiscardScalaFuture | ||
|
||
f1[R](3).map(_ + 4) // assert: DiscardScalaFuture | ||
|
||
val x1 = f1[R](5) | ||
def x2: Future[Int] = f1[R](5) | ||
|
||
Mockito.verify(mock).f1(3) | ||
Mockito.verify(mock).f1[R](3) | ||
Mockito.verify(mock, Mockito.times(2)).f1(9) | ||
Mockito.verify(mock, Mockito.times(2)).f1[R](9) | ||
Mockito.verify(mock, Mockito.never()).f1(-1) | ||
Mockito.verify(mock, Mockito.never()).f1[R](-1) | ||
|
||
verify(mock).f0[R] | ||
verify(mock).f1(4) | ||
verify(mock).f1[R](4) | ||
verify(mock, Mockito.times(2)).f1(5) | ||
verify(mock, Mockito.times(2)).f1[R](5) | ||
verify(mock, Mockito.never()).f1(8) | ||
verify(mock, Mockito.never()).f1[R](8) | ||
|
||
x1.flatMap(y => x1.map(_ + y)) // assert: DiscardScalaFuture | ||
|
||
x1 // assert: DiscardScalaFuture | ||
|
||
x1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
rule = DiscardValue | ||
DiscardValue.types = [ | ||
"scala/Option#" | ||
] | ||
*/ | ||
package fix | ||
|
||
import org.mockito.Mockito | ||
import org.mockito.Mockito.verify | ||
|
||
trait DiscardValueTest { | ||
def f0[R]: Option[Int] | ||
|
||
def f1[R](n: Int): Option[Int] | ||
|
||
def mock: DiscardValueTest | ||
|
||
def f2[R]: Option[Int] = { | ||
f0[R] // assert: DiscardValue | ||
|
||
f1[R](2) // assert: DiscardValue | ||
|
||
f1[R](3).map(_ + 4) // assert: DiscardValue | ||
|
||
val x1 = f1[R](5) | ||
def x2: Option[Int] = f1[R](5) | ||
|
||
Mockito.verify(mock).f1(3) | ||
Mockito.verify(mock).f1[R](3) | ||
Mockito.verify(mock, Mockito.times(2)).f1(9) | ||
Mockito.verify(mock, Mockito.times(2)).f1[R](9) | ||
Mockito.verify(mock, Mockito.never()).f1(-1) | ||
Mockito.verify(mock, Mockito.never()).f1[R](-1) | ||
|
||
verify(mock).f0[R] | ||
verify(mock).f1(4) | ||
verify(mock).f1[R](4) | ||
verify(mock, Mockito.times(2)).f1(5) | ||
verify(mock, Mockito.times(2)).f1[R](5) | ||
verify(mock, Mockito.never()).f1(8) | ||
verify(mock, Mockito.never()).f1[R](8) | ||
|
||
x1.flatMap(y => x1.map(_ + y)) // assert: DiscardValue | ||
|
||
x1 // assert: DiscardValue | ||
|
||
x1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fix | ||
|
||
import scalafix.Patch | ||
import scalafix.v1.Configuration | ||
import scalafix.v1.Rule | ||
import scalafix.v1.SemanticDocument | ||
import scalafix.v1.SemanticRule | ||
import metaconfig.ConfDecoder | ||
import metaconfig.Configured | ||
import metaconfig.generic.Surface | ||
import scalafix.lint.LintSeverity | ||
|
||
case class DiscardEffConfig( | ||
severity: LintSeverity | ||
) | ||
|
||
object DiscardEffConfig { | ||
val default: DiscardEffConfig = DiscardEffConfig( | ||
severity = LintSeverity.Warning, | ||
) | ||
|
||
implicit val surface: Surface[DiscardEffConfig] = | ||
metaconfig.generic.deriveSurface[DiscardEffConfig] | ||
|
||
implicit val decoder: ConfDecoder[DiscardEffConfig] = { | ||
import DiscardValueConfig.lintSeverityDecoderInstance | ||
metaconfig.generic.deriveDecoder(default) | ||
} | ||
} | ||
|
||
class DiscardEff(config: DiscardEffConfig) extends SemanticRule("DiscardEff") { | ||
|
||
def this() = this(DiscardEffConfig.default) | ||
|
||
override def withConfiguration(config: Configuration): Configured[Rule] = { | ||
config.conf.getOrElse("DiscardEff")(this.config).map(newConfig => new DiscardEff(newConfig)) | ||
} | ||
|
||
override def fix(implicit doc: SemanticDocument): Patch = DiscardValue.typeRef( | ||
severity = config.severity, | ||
types = Set("org/atnos/eff/Eff#") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package fix | ||
|
||
import scalafix.Patch | ||
import scalafix.v1.Configuration | ||
import scalafix.v1.Rule | ||
import scalafix.v1.SemanticDocument | ||
import scalafix.v1.SemanticRule | ||
import metaconfig.ConfDecoder | ||
import metaconfig.Configured | ||
import metaconfig.generic.Surface | ||
import scalafix.lint.LintSeverity | ||
|
||
case class DiscardMonixTaskConfig( | ||
severity: LintSeverity | ||
) | ||
|
||
object DiscardMonixTaskConfig { | ||
val default: DiscardMonixTaskConfig = DiscardMonixTaskConfig( | ||
severity = LintSeverity.Warning, | ||
) | ||
|
||
implicit val surface: Surface[DiscardMonixTaskConfig] = | ||
metaconfig.generic.deriveSurface[DiscardMonixTaskConfig] | ||
|
||
implicit val decoder: ConfDecoder[DiscardMonixTaskConfig] = { | ||
import DiscardValueConfig.lintSeverityDecoderInstance | ||
metaconfig.generic.deriveDecoder(default) | ||
} | ||
} | ||
|
||
class DiscardMonixTask(config: DiscardMonixTaskConfig) extends SemanticRule("DiscardMonixTask") { | ||
|
||
def this() = this(DiscardMonixTaskConfig.default) | ||
override def withConfiguration(config: Configuration): Configured[Rule] = { | ||
config.conf.getOrElse("DiscardMonixTask")(this.config).map(newConfig => new DiscardMonixTask(newConfig)) | ||
} | ||
|
||
override def fix(implicit doc: SemanticDocument): Patch = DiscardValue.typeRef( | ||
severity = config.severity, | ||
types = Set("monix/eval/Task#") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fix | ||
|
||
import scalafix.Patch | ||
import scalafix.v1.Configuration | ||
import scalafix.v1.Rule | ||
import scalafix.v1.SemanticDocument | ||
import scalafix.v1.SemanticRule | ||
import metaconfig.ConfDecoder | ||
import metaconfig.Configured | ||
import metaconfig.generic.Surface | ||
import scalafix.lint.LintSeverity | ||
|
||
case class DiscardScalaFutureConfig( | ||
severity: LintSeverity | ||
) | ||
|
||
object DiscardScalaFutureConfig { | ||
val default: DiscardScalaFutureConfig = DiscardScalaFutureConfig( | ||
severity = LintSeverity.Warning, | ||
) | ||
|
||
implicit val surface: Surface[DiscardScalaFutureConfig] = | ||
metaconfig.generic.deriveSurface[DiscardScalaFutureConfig] | ||
|
||
implicit val decoder: ConfDecoder[DiscardScalaFutureConfig] = { | ||
import DiscardValueConfig.lintSeverityDecoderInstance | ||
metaconfig.generic.deriveDecoder(default) | ||
} | ||
} | ||
|
||
class DiscardScalaFuture(config: DiscardScalaFutureConfig) extends SemanticRule("DiscardScalaFuture") { | ||
|
||
def this() = this(DiscardScalaFutureConfig.default) | ||
|
||
override def withConfiguration(config: Configuration): Configured[Rule] = { | ||
config.conf.getOrElse("DiscardScalaFuture")(this.config).map(newConfig => new DiscardScalaFuture(newConfig)) | ||
} | ||
|
||
override def fix(implicit doc: SemanticDocument): Patch = DiscardValue.typeRef( | ||
severity = config.severity, | ||
types = Set("scala/concurrent/Future#") | ||
) | ||
} |
Oops, something went wrong.