-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add id for CustomMessage (fix #495) #500
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package scalafix | ||
package config | ||
|
||
import metaconfig.{Conf, ConfError, ConfDecoder, Configured, Metaconfig} | ||
import org.langmeta._ | ||
import scalafix.internal.config.MetaconfigPendingUpstream.XtensionConfScalafix | ||
|
||
import scala.language.implicitConversions | ||
|
||
class CustomMessage[T]( | ||
val value: T, | ||
val message: Option[String], | ||
val id: Option[String]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You only read from the CustomMessage, I don't think this is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I agree. |
||
|
||
object CustomMessage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ibid. you only read from the conf. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, nevermind! |
||
def decoder[T](field: String)( | ||
implicit ev: ConfDecoder[T]): ConfDecoder[CustomMessage[T]] = | ||
ConfDecoder.instance[CustomMessage[T]] { | ||
case obj: Conf.Obj => { | ||
(obj.get[T](field) |@| | ||
obj.getOption[String]("message") |@| | ||
obj.getOption[String]("id")).map { | ||
case ((value, message0), id) => | ||
val message = | ||
message0.map(msg => | ||
if (msg.isMultiline) { | ||
"\n" + msg.stripMargin | ||
} else { | ||
msg | ||
}) | ||
|
||
new CustomMessage(value, message, id) | ||
} | ||
} | ||
case els => | ||
ev.read(els).map(value => new CustomMessage(value, None, None)) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package scalafix.internal.config | ||
package scalafix | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I generally avoid this pattern since it can easily introduce cycles in your codebase. |
||
package internal.config | ||
|
||
import metaconfig.ConfDecoder | ||
import MetaconfigPendingUpstream.XtensionConfScalafix | ||
|
@@ -8,14 +9,13 @@ import scalafix.internal.util.SymbolOps | |
case class DisableConfig(symbols: List[CustomMessage[Symbol.Global]] = Nil) { | ||
def allSymbols = symbols.map(_.value) | ||
|
||
private val messageBySymbol: Map[String, String] = | ||
private val messageBySymbol: Map[String, CustomMessage[Symbol.Global]] = | ||
symbols | ||
.flatMap(custom => | ||
custom.message.map(message => | ||
(SymbolOps.normalize(custom.value).syntax, message))) | ||
.map(custom => (SymbolOps.normalize(custom.value).syntax, custom)) | ||
.toMap | ||
|
||
def customMessage(symbol: Symbol.Global): Option[String] = | ||
def customMessage( | ||
symbol: Symbol.Global): Option[CustomMessage[Symbol.Global]] = | ||
messageBySymbol.get(SymbolOps.normalize(symbol).syntax) | ||
|
||
implicit val customMessageReader: ConfDecoder[CustomMessage[Symbol.Global]] = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ DisableSyntax.noSemicolons = true | |
DisableSyntax.noXml = true | ||
DisableSyntax.regex = [ | ||
{ | ||
id = offensive | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot use pimp here because the assert would trigger the regex again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, I wonder if we can avoid this in general by making sure the offensive part does not follow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "offensive" is better anyways. |
||
pattern = "[P|p]imp" | ||
message = "Please consider a less offensive word such as Extension" | ||
} | ||
|
@@ -39,7 +40,7 @@ case object DisableSyntax { | |
<a>xml</a> // assert: DisableSyntax.noXml | ||
// assert: DisableSyntax.noTabs | ||
|
||
implicit class StringPimp(value: String) { // assert: DisableSyntax.[P|p]imp | ||
implicit class StringPimp(value: String) { // assert: DisableSyntax.offensive | ||
def -(other: String): String = s"$value - $other" | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that this is in our public API, can we add
in the scalafix package object? Rule authors should only need to
import scalafix._; import scala.meta._
to get started.