-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RE-2): split into three subprojects
* feat(RE-2): split into two artifacts * chore: readme fix * chore: consistency on docs formatting * feat: trying to publish * feat(RE-2): split into three projects and refactoring plugin internals * feat(RE-2): make it work with nested case classes too * feat(RE-2): refactoring * feat(RE-2): refactoring * feat(RE-2): adjustments in readme * feat(RE-2): use TreeOps implicts methods * feat(RE-2): further refinements & test * feat(RE-2): bump sbt version * feat(RE-2): minor fixes
- Loading branch information
Showing
20 changed files
with
421 additions
and
282 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
metals.sbt | ||
project/project/* | ||
project/target/* | ||
target/* | ||
target/* | ||
**/target/* |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,83 @@ | ||
ThisBuild / version := "0.2.0-SNAPSHOT" | ||
ThisBuild / version := "0.3.0-SNAPSHOT" | ||
ThisBuild / scalaVersion := "3.1.3" | ||
|
||
ThisBuild / publishMavenStyle := true | ||
ThisBuild / crossPaths := false | ||
ThisBuild / versionScheme := Some("early-semver") | ||
ThisBuild / publishTo := Some("GitHub Package Registry" at "https://maven.pkg.github.com/polentino/redacted") | ||
ThisBuild / credentials += Credentials( | ||
"GitHub Package Registry", | ||
"maven.pkg.github.com", | ||
"polentino", | ||
sys.env.getOrElse("GITHUB_TOKEN", "???")) | ||
|
||
inThisBuild( | ||
List( | ||
organization := "io.github.polentino", | ||
homepage := Some(url("https://github.com/polentino/redacted")), | ||
licenses := List( | ||
"WTFPL" -> url("http://www.wtfpl.net/") | ||
), | ||
developers := List( | ||
Developer( | ||
"polentino", | ||
"Diego Casella", | ||
"polentino911@gmail.com", | ||
url("https://be.linkedin.com/in/diegocasella") | ||
) | ||
) | ||
) | ||
) | ||
|
||
Global / onChangedBuildSource := ReloadOnSourceChanges | ||
|
||
lazy val root = (project in file(".")) | ||
.settings( | ||
name := "redacted", | ||
libraryDependencies ++= Seq( | ||
"org.scala-lang" %% "scala3-compiler" % scalaVersion.value % "provided", | ||
"org.scalatest" %% "scalatest" % "3.2.17" % "test" | ||
), | ||
scalafixDependencies += "com.liancheng" %% "organize-imports" % "0.6.0", | ||
semanticdbEnabled := true, | ||
semanticdbVersion := scalafixSemanticdb.revision, | ||
Test / scalacOptions ++= { | ||
val jar = (Compile / packageBin).value | ||
Seq(s"-Xplugin:${jar.getAbsolutePath}", s"-Jdummy=${jar.lastModified}") // ensures recompile | ||
name := "redacted-root", | ||
publish / skip := true | ||
) | ||
.aggregate(redactedLibrary, redactedCompilerPlugin, redactedTests) | ||
|
||
val scalafixSettings = Seq( | ||
scalafixDependencies += "com.liancheng" %% "organize-imports" % "0.6.0", | ||
semanticdbEnabled := true, | ||
semanticdbVersion := scalafixSemanticdb.revision | ||
) | ||
|
||
lazy val redactedLibrary = (project in file("library")) | ||
.settings(name := "redacted") | ||
.settings( | ||
scalafixSettings, | ||
Test / skip := true | ||
) | ||
|
||
lazy val redactedCompilerPlugin = (project in file("plugin")) | ||
.dependsOn(redactedLibrary) | ||
.settings(name := "redacted-plugin") | ||
.settings(scalafixSettings) | ||
.settings( | ||
Test / skip := true, | ||
assembly / assemblyJarName := { | ||
val assemblyJarFile = (Compile / Keys.`package`).value | ||
assemblyJarFile.getName | ||
}, | ||
libraryDependencies += "org.scala-lang" %% "scala3-compiler" % scalaVersion.value | ||
) | ||
|
||
lazy val redactedTests = (project in file("tests")) | ||
.dependsOn(redactedLibrary) | ||
.settings(name := "redacted-tests") | ||
.settings(scalafixSettings) | ||
.settings( | ||
publish / skip := true, | ||
libraryDependencies ++= Seq("org.scalatest" %% "scalatest" % "3.2.17" % Test), | ||
scalacOptions ++= { | ||
val jar = (redactedCompilerPlugin / assembly).value | ||
val addPlugin = "-Xplugin:" + jar.getAbsolutePath | ||
val dummy = "-Jdummy=" + jar.lastModified | ||
Seq(addPlugin, dummy) | ||
} | ||
) | ||
|
||
addCommandAlias("fmt", "all scalafmtSbt scalafmtAll test:scalafmtAll; scalafixAll") | ||
addCommandAlias("fmt", "; scalafmtAll ; scalafmtSbt") // todo scalafix ? | ||
addCommandAlias("fmtCheck", "; scalafmtCheckAll ; scalafmtSbtCheck") |
File renamed without changes.
File renamed without changes.
This file contains 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
34 changes: 34 additions & 0 deletions
34
plugin/src/main/scala/io/github/polentino/redacted/helpers/AstOps.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.polentino.redacted.helpers | ||
|
||
import dotty.tools.dotc.* | ||
import dotty.tools.dotc.ast.tpd | ||
import dotty.tools.dotc.core.Constants.Constant | ||
import dotty.tools.dotc.core.Contexts.* | ||
import dotty.tools.dotc.core.Symbols.* | ||
import dotty.tools.dotc.core.{Flags, Symbols} | ||
|
||
import io.github.polentino.redacted.redacted | ||
|
||
object AstOps { | ||
private val REDACTED_CLASS: String = classOf[redacted].getCanonicalName | ||
|
||
def redactedSymbol(using Context): ClassSymbol = Symbols.requiredClass(REDACTED_CLASS) | ||
|
||
extension (s: String)(using Context) { | ||
def toConstantLiteral: tpd.Tree = tpd.Literal(Constant(s)) | ||
} | ||
|
||
extension (symbol: Symbol)(using Context) { | ||
|
||
def redactedFields: List[String] = { | ||
val redactedType = redactedSymbol | ||
symbol.primaryConstructor.paramSymss.flatten.collect { | ||
case s if s.annotations.exists(_.matches(redactedType)) => s.name.toString | ||
} | ||
} | ||
} | ||
|
||
extension (tree: tpd.TypeDef)(using Context) { | ||
def isCaseClass: Boolean = tree.symbol.is(Flags.CaseClass) | ||
} | ||
} |
Oops, something went wrong.