Skip to content

Commit

Permalink
Merge pull request scalacenter#497 from olafurpg/disable-signatures
Browse files Browse the repository at this point in the history
Fix scalacenter#493, handle synthetics and symbol signatures in Disable.
  • Loading branch information
olafurpg authored Dec 12, 2017
2 parents b48d7f0 + a992b02 commit a422860
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,33 @@ final case class Disable(index: SemanticdbIndex, config: DisableConfig)
.getOrElse("disable", "Disable")(DisableConfig.default)
.map(Disable(index, _))

override def check(ctx: RuleCtx): Seq[LintMessage] =
ctx.index.names.collect {
case ResolvedName(
pos,
disabledSymbol(symbol @ Symbol.Global(_, signature)),
false) => {

val message =
config
.customMessage(symbol)
.getOrElse(s"${signature.name} is disabled")

errorCategory
.copy(id = signature.name)
.at(message, pos)
override def check(ctx: RuleCtx): Seq[LintMessage] = {
for {
document <- ctx.index.documents.view
ResolvedName(
pos,
disabledSymbol(symbol @ Symbol.Global(_, signature)),
false
) <- {
document.names.view ++
document.synthetics.view.flatMap(_.names)
}
} yield {
val (details, caret) = pos.input match {
case synthetic @ Input.Synthetic(_, input, start, end) =>
// For synthetics the caret should point to the original position
// but display the inferred code.
s" and it got inferred as `${synthetic.text}`" ->
Position.Range(input, start, end)
case _ =>
"" -> pos
}
val message = config
.customMessage(symbol)
.getOrElse(s"${signature.name} is disabled$details")
errorCategory
.copy(id = signature.name)
.at(message, caret)
}
}
}
11 changes: 10 additions & 1 deletion scalafix-tests/input/src/main/scala/test/Disable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ Disable.symbols = [
|...
|// scalafix:on Option.get"""
}
"scala.collection.mutable.ListBuffer"
"scala.Predef.any2stringadd"
]
*/
package test

import scala.collection.mutable.ListBuffer

case object Disable {

case class B()
Expand Down Expand Up @@ -52,4 +56,9 @@ If you must Option.get, wrap the code block with
...
// scalafix:on Option.get
*/
}
val l: ListBuffer[Int] = scala.collection.mutable.ListBuffer.empty[Int] // assert: Disable.ListBuffer
List(1) + "any2stringadd" /* assert: Disable.any2stringadd
^
any2stringadd is disabled and it got inferred as `scala.Predef.any2stringadd[List[Int]](*)`
*/
}

0 comments on commit a422860

Please sign in to comment.