Created
January 20, 2025 09:52
-
-
Save xuwei-k/bc0ac85bfccad51be69d5c29b662ce95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fix | |
import scala.meta.Defn | |
import scala.meta.Term | |
import scala.meta.transversers.* | |
import scalafix.Patch | |
import scalafix.lint.Diagnostic | |
import scalafix.lint.LintSeverity | |
import scalafix.v1.SyntacticDocument | |
import scalafix.v1.SyntacticRule | |
import scalafix.v1.XtensionSeqPatch | |
class GivenAnonymous extends SyntacticRule("GivenAnonymous") { | |
override def fix(implicit doc: SyntacticDocument): Patch = { | |
doc.tree.collect { | |
case t: Term.Block => | |
t.stats.collect { | |
case g: Defn.GivenAlias | |
if !g.name.isAnonymous && t.collect { case Term.Name(n) if n == g.name.value => () }.sizeIs <= 1 => | |
Patch.lint( | |
Diagnostic( | |
id = "", | |
message = "明示的に名前で参照しないローカルなgivenは無名にしてください", | |
position = g.pos, | |
severity = LintSeverity.Error | |
) | |
) | |
}.asPatch | |
}.asPatch | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment