scalafix
scalafix copied to clipboard
scalafixTest should support custom error message on failure
In scalafmt, the onTestFailure: String setting can be customized to print out a message on --test failure. See http://scalameta.org/scalafmt/#Other
It would be nice if scalafix did the same, so that contributors get actionable instructions on how to fix failures from scalafix --test.
I'll go ahead and give this one a go 👍
Quick question on this @olafurpg. So in scalafmt this works well in that one message can easily guide the user to how to solve their problem. I started to take the same approach on this, but then soon realized it may be sort of an issue depending on the rule that is being broken.
For example for some of the semantic rules that we can do a refactoring on, just having a message like Please run <custom command you may have configured> to fix this issue. However, for some of the syntactic checks it's a bit trickier as they will need to be manually changed.
What are you thoughts on this differentiation and how to enure the message is relevant to either a semantic or syntactic rule? For example I could see offering a .message for each rule? So you could do like DisableSyntax.failMessage = do something, RemovedUnused.failMessage = .... Or is that a bit to much to offer? This would maybe be similar to how the noUniversalEqualityMessage is done.
Maybe another approach could be having both a onTestFailure.message = string and a onTestFailureMembers = [ DisableSyntax, RemoveUnused ] or something to list the rules you want it to apply to?
Or is this not as large of an issue as I'm thinking it is?
Good question. I think we can restrict this message only to be printed for errors that can be automatically fixed. The exit code from Scalafix can tell us whether there was a lint error (which we can't autofix) or a "test error" (which we can autofix). See https://github.com/scalacenter/scalafix/blob/abf6e0963b9c203cd3d96b0d34fa5ac8f01a41bd/scalafix-cli/src/main/scala/scalafix/cli/ExitStatus.scala#L33
Does that make sense?
I think it's the role of the Scalafix linter rules to include "To fix this problem ..." in the default linter message so I don't think we need to worry about that.
Gotcha, that makes sense 👍