-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Initial support for Scala 3 (#858)
* split source into scala 2 and 3 * First Scala 3 inspection * Rewire plugin and feedback flow * Bootstrap compiler differently to allow to extract the raw feedback * Clean up OptionGet and set up for more re-use * Set up cross ci and fix readme test * Apply suggestions from code review Co-authored-by: Bendix Sältz <[email protected]> * Fix scalafix and configure Scala 3 compiler options * sbt fix * Build dotty feedback per compile run, not compilation unit * Improve test coverage * Add coverage on plugin control flows * Add coverage on feedback reporting flow --------- Co-authored-by: Bendix Sältz <[email protected]>
- Loading branch information
Showing
301 changed files
with
991 additions
and
257 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
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,4 +1,5 @@ | ||
*.class | ||
*.tasty | ||
*.log | ||
|
||
# sbt specific | ||
|
@@ -22,4 +23,4 @@ target | |
.metals | ||
metals.sbt | ||
|
||
.bsp | ||
.bsp |
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,23 @@ | ||
rules = [ | ||
DisableSyntax, | ||
LeakingImplicitClassVal, | ||
NoAutoTupling, | ||
NoValInForComprehension, | ||
ProcedureSyntax, | ||
RemoveUnused | ||
] | ||
|
||
DisableSyntax.noVars = false | ||
DisableSyntax.noThrows = false | ||
DisableSyntax.noNulls = false | ||
DisableSyntax.noReturns = true | ||
DisableSyntax.noWhileLoops = true | ||
DisableSyntax.noFinalize = true | ||
DisableSyntax.noValPatterns = true | ||
DisableSyntax.noUniversalEquality = false | ||
DisableSyntax.noUniversalEqualityMessage = "== and != are unsafe since they allow comparing two unrelated types" | ||
SortImports.blocks = [ | ||
"java.", | ||
"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
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
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 @@ | ||
pluginClass=com.sksamuel.scapegoat.ScapegoatPlugin |
22 changes: 22 additions & 0 deletions
22
src/main/scala-2/com/sksamuel/scapegoat/FeedbackScala2.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,22 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
import scala.tools.nsc.reporters.Reporter | ||
import scala.reflect.internal.util.Position | ||
|
||
class FeedbackScala2( | ||
reporter: Reporter, | ||
configuration: Configuration | ||
) extends Feedback[Position](configuration) { | ||
|
||
protected def toSourcePath(pos: Position): String = pos.source.file.path | ||
protected def toSourceLine(pos: Position): Int = pos.line | ||
|
||
override protected def report(pos: Position, level: Level, message: String): Unit = { | ||
level match { | ||
case Levels.Error => reporter.error(pos, message) | ||
case Levels.Warning => reporter.warning(pos, message) | ||
case Levels.Info => reporter.echo(pos, message) | ||
case Levels.Ignore => () | ||
} | ||
} | ||
} |
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,18 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
/** | ||
* @author | ||
* Stephen Samuel | ||
*/ | ||
abstract class Inspection( | ||
override val text: String, | ||
override val defaultLevel: Level, | ||
override val description: String, | ||
override val explanation: String | ||
) extends InspectionBase { | ||
|
||
val self: Inspection = this | ||
|
||
def inspector(ctx: InspectionContext): Inspector | ||
|
||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
22 changes: 22 additions & 0 deletions
22
src/main/scala-3/com/sksamuel/scapegoat/FeedbackDotty.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,22 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.core.Decorators.toMessage | ||
import dotty.tools.dotc.reporting.Diagnostic | ||
import dotty.tools.dotc.util.SourcePosition | ||
|
||
class FeedbackDotty(configuration: Configuration)(using ctx: Context) | ||
extends Feedback[SourcePosition](configuration) { | ||
|
||
protected def toSourcePath(pos: SourcePosition): String = pos.source().path() | ||
protected def toSourceLine(pos: SourcePosition): Int = pos.line | ||
protected def report(pos: SourcePosition, level: Level, message: String): Unit = { | ||
level match { | ||
case Levels.Error => ctx.reporter.report(Diagnostic.Error(message, pos)) | ||
case Levels.Warning => ctx.reporter.report(Diagnostic.Warning(message.toMessage, pos)) | ||
case Levels.Info => ctx.reporter.report(Diagnostic.Info(message, pos)) | ||
case Levels.Ignore => () | ||
} | ||
} | ||
|
||
} |
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,18 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
import dotty.tools.dotc.ast.tpd | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.util.SourcePosition | ||
|
||
abstract class Inspection( | ||
val text: String, | ||
val defaultLevel: Level, | ||
val description: String, | ||
val explanation: String | ||
) extends InspectionBase { | ||
|
||
val self: Inspection = this | ||
|
||
def inspect(feedback: Feedback[SourcePosition], tree: tpd.Tree)(using Context): Unit | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/scala-3/com/sksamuel/scapegoat/InspectionTraverser.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,14 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
import dotty.tools.dotc.ast.tpd.* | ||
import dotty.tools.dotc.core.Contexts.Context | ||
import dotty.tools.dotc.util.NoSource | ||
|
||
abstract class InspectionTraverser extends TreeTraverser { | ||
|
||
extension (tree: Tree)(using Context) | ||
def asSnippet: Option[String] = tree.source match | ||
case NoSource => None | ||
case _ => Some(tree.source.content().slice(tree.sourcePos.start, tree.sourcePos.end).mkString) | ||
|
||
} |
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,11 @@ | ||
package com.sksamuel.scapegoat | ||
|
||
import com.sksamuel.scapegoat.inspections.option._ | ||
|
||
object Inspections { | ||
|
||
final val inspections: List[Inspection] = List( | ||
new OptionGet | ||
) | ||
|
||
} |
Oops, something went wrong.