Skip to content
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

scalafix-rules_3 (GSoC 2022) #1643

Merged
merged 5 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,19 @@ lazy val rules = projectMatrix
moduleName := "scalafix-rules",
description := "Built-in Scalafix rules",
buildInfoSettingsForRules,
libraryDependencies ++= List(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
semanticdbScalacCore,
collectionCompat
)
libraryDependencies ++= {
if (!isScala3.value)
List(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
semanticdbScalacCore,
collectionCompat
)
else Nil
}
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(buildScalaVersions)
.jvmPlatform(buildScalaVersions :+ scala3, Seq(), p => p)
.dependsOn(core)
.enablePlugins(BuildInfoPlugin)

Expand Down
1 change: 1 addition & 0 deletions project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
commands += Command.command("ci-3") { s =>
"unit2_12Target3/test" ::
"core3/compile" ::
"rules3/compile" ::
s
},
commands += Command.command("ci-213") { s =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package scalafix.internal.rule

import java.util.regex.Pattern

import metaconfig.pprint._
import scalafix.config.CustomMessage
import scalafix.config.Regex

class TPrintImplicits {
implicit val tprintPattern
: TPrint[List[CustomMessage[Either[Regex, Pattern]]]] =
new TPrint[List[CustomMessage[Either[Regex, Pattern]]]] {
def render(implicit tpc: TPrintColors): fansi.Str =
fansi.Str("List[Regex]")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,19 @@ final class DisableSyntax(config: DisableSyntaxConfig)
Seq(noFinalVal.at(mod.pos))
case NoValPatterns(v) if config.noValPatterns =>
Seq(noValPatternCategory.at(v.pos))
case t @ mod"+" if config.noCovariantTypes =>
case t @ Mod.Covariant() if config.noCovariantTypes =>
Seq(
Diagnostic(
"covariant",
"Covariant types could lead to error-prone situations.",
"Covariant types could lead to error-prone situations",
t.pos
)
)
case t @ mod"-" if config.noContravariantTypes =>
case t @ Mod.Contravariant() if config.noContravariantTypes =>
Seq(
Diagnostic(
"contravariant",
"Contravariant types could lead to error-prone situations.",
"Contravariant types could lead to error-prone situations",
t.pos
)
)
Expand Down Expand Up @@ -297,7 +297,7 @@ object DisableSyntax {
|overriding finalize incurs a performance penalty""".stripMargin

def FinalizeMatcher(id: String): PartialFunction[Tree, List[Diagnostic]] = {
case Defn.Def(_, name @ q"finalize", _, Nil | Nil :: Nil, _, _) =>
case Defn.Def(_, name @ Term.Name("finalize"), _, Nil | Nil :: Nil, _, _) =>
Diagnostic(
id,
"finalize should not be used",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class LeakingImplicitClassVal extends SyntacticRule("LeakingImplicitClassVal") {
_,
_,
Ctor.Primary(_, _, (Term.Param(pMods, _, _, _) :: Nil) :: Nil),
Template(_, init"AnyVal" :: Nil, _, _)
Template(_, Init(Type.Name("AnyVal"), _, _) :: Nil, _, _)
) if cMods.exists(_.is[Mod.Implicit]) =>
val optPatch = for {
anchorMod <- pMods.find(!_.is[Mod.Annot])
Expand Down