Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scalafix] tagChunkSize migration fix #238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scalafix/input/src/main/scala/fix/Fs2Pgp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object Fs2Pgp {
|-----END PGP PUBLIC KEY BLOCK-----""".stripMargin
val wrappedKey = PGPKeyAlg[IO].readPublicKey(key).unsafeRunSync()
val pos = PosInt(100)
val chunkSize = tagChunkSize(pos)

(for {
crypto <- Stream.resource(CryptoAlg[IO])
Expand Down
1 change: 1 addition & 0 deletions scalafix/output/src/main/scala/fix/Fs2Pgp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object Fs2Pgp {
|-----END PGP PUBLIC KEY BLOCK-----""".stripMargin
val wrappedKey = PGPKeyAlg[IO].readPublicKey(key).unsafeRunSync()
val pos = PosInt(100)
val chunkSize = ChunkSize(pos)

(for {
crypto <- Stream.resource(CryptoAlg.resource[IO])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ class V04to05 extends SemanticRule("com.dwolla.security.crypto.V04to05") {
migrateEncrypt(t, fun, additionalArguments, Some(keyName), offset = 1)
case Term.Apply.After_4_6_0(Term.Select(Term.Name(_), fun@Term.Name("encrypt")), t@Term.ArgClause(arguments, None)) =>
migrateEncrypt(t, fun, arguments, None, offset = 0)
// case t@Term.Apply.After_4_6_0(Term.Name("tagChunkSize"), _) =>
// Patch.replaceToken(t.tokens.head, "ChunkSizeFromFix")
case t@Term.Apply.After_4_6_0(Term.Name("tagChunkSize"), _) if !isEncryptAParent(t) =>
Patch.replaceToken(t.tokens.head, "ChunkSize")
}.asPatch


private def isEncryptAParent(t: Tree): Boolean = {
val res = for {
firstParent <- t.parent
secondParent <- firstParent.parent
res = secondParent match {
case Term.Apply.After_4_6_0(Term.Select(_, Term.Name("encrypt")), _) => true
case _ => false
}
} yield res
res match {
case None => false
case Some(v) => v
}
}

private def migrateEncrypt(t: Term.ArgClause,
fun: Term.Name,
Expand Down