scala-steward
scala-steward copied to clipboard
Support custom heuristics
WDYT about support of custom heuristics ?
Example repo config:
...
...
updates.customHeuristics = [
{
groupId = "org.platform"
termsToReplace = ["platform"]
// artifactName = "some" // optional artifact name
}
]
So it would be possible to update such dependencies with scala steward:
"org.platform" %% "libA" % platformVersion
"org.platform" %% "libB" % platformVersion % Test,
@fthomas WDYT ? I prepared a draft. Let me know if you ready to accept this contribution and I will fix all failed tests ASAP :)
I do not yet understand why the custom heuristic is needed. I think the groupId
heuristic would be able to update platformVersion
above.
Oh, you right, I made a mistake in the example above 🤦
Right example is:
"com.organization" % "libA" % platformVersion
"com.organization" % "libB" % platformVersion
It's not the best way to organize artifact but this is what we have.
Ok, so the issue is that the val
used for the version does not contain a word of the groupId or artifactId so Scala Steward can't associate platformVersion
with the version of "com.organization" % "libA"
or "com.organization" % "libB"
. I think that Scala Steward could automatically (without manual help) find and use platformVersion
as search term for the version number. We could add a new heuristic between moduleId
and strict
that first looks for strings like "com.organization" % "libA" % X
in all files and then uses X
as sole search term if it is not the version number.
I think this strategy could also fix #1184.
WDYT @payurgin, would this work in your case?
I think it will work for my case. I'm not sure if it possible to write regexp for matching variable name. It's relatively simple for:
"com.organization" % "libA" % platformVersion
"com.organization" % "libB" % platformVersion
But what to do with:
lazy val deps = Seq("foo" % "bar" % `platform version`, "foo" % "bar" % `to be, or nø† †o ∫e`, "bar" % "foo" % "0.01")
Maybe we can start from simple cases when version variable name is relatively simple ? Then it would be relatively simple and I can add this to my pr.
I would also focus on the simple cases and ignore the esoteric ones. I could imagine that the naive approach works for 95% or more of the cases where a variable used for the version.