Same rule, different behaviour
Opened this issue · 0 comments
Bringing this over from scalacenter/scalafix#865
I have a code snippet in one of my tests (which is why I am allowing Option#get)
def databaseConfig(labels: NonEmptyString): DatabaseConfig =
DatabaseConfig(
NonEmptyString.from(postgresUrl).toOption.get,
NonEmptyString.from(postgresUser).toOption.get, // scalafix:ok Disable.get
Password(NonEmptyString.from(postgresPassword).toOption.get), // scalafix:ok Disable.get
Tables(labels)
)
It seems to only work with this set of scalafix annotations.
I would have expected each and every one of the .get
calls to need // scalafix:ok Disable.get
.
If I place it on the first one, I get
[warn] /home/nequi/dev/project/src/test/scala/Spec.scala:60:69: warning: [UnusedScalafixSuppression] Unused Scalafix suppression. This can be removed
[warn] NonEmptyString.from(postgresUrl).toOption.get, // scalafix:ok Disable.get
If I take them all away, I get
[error] /home/nequi/dev/project/src/test/scala/Spec.scala:61:50: error: [Disable.get] not a total function
[error] NonEmptyString.from(postgresUser).toOption.get,
[error] ^^^
[error] /home/nequi/dev/project/src/test/scala/Spec.scala:62:63: error: [Disable.get] not a total function
[error] Password(NonEmptyString.from(postgresPassword).toOption.get),
It seems rather confusing that the first call to .get
is not caught and hence behaves differently from subsequent ones.
Note that I have only ever seen this in calls to .apply
functions. If I were to apply the three values to vals
beforehand, I would get Scalafix warnings for all three.
I am using Scalafix 0.6.0-M16 here. (I know it's not stable, but this is how I can send you issue reports :D)