Skip to content

Commit efa85ee

Browse files
authored
Merge pull request #809 from olafurpg/apis
Second steps towards scalafix.v1
2 parents 1d9d610 + 87c3276 commit efa85ee

File tree

124 files changed

+2011
-1846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+2011
-1846
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ lazy val core = project
3838
libraryDependencies ++= List(
3939
scalameta,
4040
symtab,
41+
metap,
4142
googleDiff,
4243
"com.geirsson" %% "metaconfig-typesafe-config" % metaconfigV,
4344
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided

docs/rule-authors/setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ scalafix-testkit features include:
5656

5757
- Assert that a linter error is expected at a particular line by suffixing the
5858
line with the comment `// assert: <LintCategory>`. For an example, see the
59-
NoInfer test suite:
59+
Disable test suite:
6060

6161
```scala
62-
val x = List(1, "")// assert: NoInfer.any
62+
val x = List(1, "")// assert: Disable.Any
6363
```
6464

6565
It's also possible to assert the offset position and the message contents with a

docs/rules/DisableUnless.md

Lines changed: 0 additions & 49 deletions
This file was deleted.

docs/rules/ExplicitUnit.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/rules/NoFinalize.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/rules/NoInfer.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/rules/RemoveXmlLiterals.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/users/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ foo(null)
174174
```
175175

176176
```scala
177-
List(1, "") // scalafix:ok NoInfer.any
177+
List(1, "") // scalafix:ok Disable.Any
178178
```
179179

180180
Optionally, you can include an arbitrary description at the end of any

project/Dependencies.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import sbt._
22
/* scalafmt: { maxColumn = 120 }*/
33

44
object Dependencies {
5-
val scalametaV = "4.0.0-M8"
5+
val scalametaV = "4.0.0-M10"
66
val metaconfigV = "0.8.3"
77
def dotty = "0.9.0-RC1"
88
def scala210 = "2.10.6"
@@ -25,13 +25,14 @@ object Dependencies {
2525
def semanticdbPluginLibrary = "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full
2626
def scalameta = "org.scalameta" %% "contrib" % scalametaV
2727
def symtab = "org.scalameta" %% "symtab" % scalametaV
28+
def metap = "org.scalameta" %% "metap" % scalametaV
2829
def scalatest = "org.scalatest" %% "scalatest" % "3.2.0-SNAP10"
2930
def scalacheck = "org.scalacheck" %% "scalacheck" % "1.14.0"
3031

3132
def testsDeps = List(
3233
// integration property tests
3334
"com.geirsson" %% "coursier-small" % "1.0.0-M4",
34-
"org.renucci" %% "scala-xml-quote" % "0.1.4",
35+
"org.scala-lang.modules" %% "scala-xml" % "1.1.0",
3536
"org.typelevel" %% "catalysts-platform" % "0.0.5",
3637
"org.typelevel" %% "cats-core" % "0.9.0",
3738
"com.typesafe.slick" %% "slick" % "3.2.0-M2",

project/ScalafixBuild.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
6161
)
6262

6363
lazy val testsInputOutputSetting = Seq(
64-
// TODO: Remove once scala-xml-quote is merged into scala-xml
65-
resolvers += Resolver.bintrayRepo("allanrenucci", "maven"),
6664
libraryDependencies ++= testsDeps
6765
)
6866

scalafix-cli/src/main/scala/scalafix/internal/interfaces/MainCallbackImpl.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import scalafix.interfaces.ScalafixDiagnostic
55
import scalafix.interfaces.ScalafixMainCallback
66
import scalafix.internal.config
77
import scalafix.internal.config.ScalafixReporter
8-
import scalafix.internal.util.LintSyntax
9-
import scalafix.lint.LintDiagnostic
8+
import scalafix.lint.Diagnostic
9+
import scalafix.lint.RuleDiagnostic
1010
import scalafix.lint.LintID
1111
import scalafix.lint.LintSeverity
12+
import scalafix.rule.RuleName
1213

1314
object MainCallbackImpl {
1415

@@ -31,13 +32,16 @@ object MainCallbackImpl {
3132

3233
def fromJava(underlying: ScalafixMainCallback): ScalafixReporter =
3334
new ScalafixReporter {
34-
override def lint(d: LintDiagnostic): Unit = {
35-
val diagnostic = ScalafixDiagnosticImpl.fromScala(d)
35+
override def lint(ruleDiagnostic: RuleDiagnostic): Unit = {
36+
val diagnostic = ScalafixDiagnosticImpl.fromScala(ruleDiagnostic)
3637
underlying.reportDiagnostic(diagnostic)
3738
}
3839
def report(msg: String, pos: Position, sev: LintSeverity): Unit = {
3940
val diagnostic = ScalafixDiagnosticImpl.fromScala(
40-
new LintSyntax.EagerLintDiagnostic(msg, pos, sev, "", LintID.empty)
41+
RuleDiagnostic(
42+
Diagnostic(id = "", msg, pos, "", sev),
43+
RuleName.empty,
44+
None)
4145
)
4246
underlying.reportDiagnostic(diagnostic)
4347
}
Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,46 @@
11
package scalafix.internal.interfaces
22
import java.util.Optional
3-
import scala.meta.inputs.Input
4-
import scala.meta.inputs.Position
53
import scalafix.interfaces.ScalafixDiagnostic
64
import scalafix.interfaces.ScalafixLintID
75
import scalafix.interfaces.ScalafixPosition
86
import scalafix.interfaces.ScalafixSeverity
9-
import scalafix.lint.LintDiagnostic
107
import scalafix.lint.LintID
118
import scalafix.lint.LintSeverity
9+
import scalafix.lint.RuleDiagnostic
1210

1311
object ScalafixDiagnosticImpl {
14-
def fromScala(diagnostic: LintDiagnostic): ScalafixDiagnostic =
15-
new ScalafixDiagnostic {
16-
override def severity(): ScalafixSeverity = diagnostic.severity match {
17-
case LintSeverity.Info => ScalafixSeverity.INFO
18-
case LintSeverity.Warning => ScalafixSeverity.WARNING
19-
case LintSeverity.Error => ScalafixSeverity.ERROR
20-
}
21-
override def message(): String = diagnostic.message
22-
override def explanation(): String = diagnostic.explanation
23-
override def position(): Optional[ScalafixPosition] =
24-
PositionImpl.optionalFromScala(diagnostic.position)
25-
override def lintID(): Optional[ScalafixLintID] =
26-
if (diagnostic.id == LintID.empty) {
27-
Optional.empty()
28-
} else {
29-
Optional.of(new ScalafixLintID {
30-
override def ruleName(): String = diagnostic.id.rule
31-
override def categoryID(): String = diagnostic.id.categoryID
32-
})
33-
}
12+
def fromScala(diagnostic: RuleDiagnostic): ScalafixDiagnostic =
13+
DelegateJavaDiagnostic(diagnostic)
14+
15+
def fromJava(scalafixDiagnostic: ScalafixDiagnostic): RuleDiagnostic = {
16+
scalafixDiagnostic match {
17+
case DelegateJavaDiagnostic(underlying) =>
18+
underlying
19+
case _ =>
20+
throw new IllegalArgumentException(
21+
"Unexpected diagnostic: " + scalafixDiagnostic.toString)
3422
}
23+
}
24+
}
3525

36-
def fromJava(diagnostic: ScalafixDiagnostic): LintDiagnostic =
37-
new LintDiagnostic {
38-
override def message: String = diagnostic.message()
39-
override def position: Position = {
40-
if (diagnostic.position().isPresent) {
41-
val spos = diagnostic.position().get
42-
val input = Input.VirtualFile(
43-
spos.input().filename(),
44-
spos.input().text().toString
45-
)
46-
Position.Range(input, spos.startOffset(), spos.endOffset())
47-
} else {
48-
Position.None
49-
}
50-
}
51-
override def severity: LintSeverity = diagnostic.severity() match {
52-
case ScalafixSeverity.INFO => LintSeverity.Info
53-
case ScalafixSeverity.WARNING => LintSeverity.Warning
54-
case ScalafixSeverity.ERROR => LintSeverity.Error
55-
}
56-
override def explanation: String = diagnostic.explanation()
57-
override def id: LintID = {
58-
if (diagnostic.lintID().isPresent) {
59-
val lintID = diagnostic.lintID().get
60-
LintID(lintID.ruleName(), lintID.categoryID())
61-
} else {
62-
LintID.empty
63-
}
64-
}
26+
case class DelegateJavaDiagnostic(diagnostic: RuleDiagnostic)
27+
extends ScalafixDiagnostic {
28+
override def severity(): ScalafixSeverity = diagnostic.severity match {
29+
case LintSeverity.Info => ScalafixSeverity.INFO
30+
case LintSeverity.Warning => ScalafixSeverity.WARNING
31+
case LintSeverity.Error => ScalafixSeverity.ERROR
32+
}
33+
override def message(): String = diagnostic.message
34+
override def explanation(): String = diagnostic.explanation
35+
override def position(): Optional[ScalafixPosition] =
36+
PositionImpl.optionalFromScala(diagnostic.position)
37+
override def lintID(): Optional[ScalafixLintID] =
38+
if (diagnostic.id == LintID.empty) {
39+
Optional.empty()
40+
} else {
41+
Optional.of(new ScalafixLintID {
42+
override def ruleName(): String = diagnostic.id.rule
43+
override def categoryID(): String = diagnostic.id.category
44+
})
6545
}
6646
}

scalafix-cli/src/main/scala/scalafix/internal/v1/CompletionsOps.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import metaconfig.generic.Setting
44
import metaconfig.generic.Settings
55
import metaconfig.internal.Case
66
import org.apache.commons.text.StringEscapeUtils
7-
import scalafix.rule.ScalafixRules
87

98
object CompletionsOps {
109
private def option(kebab: String): String =
@@ -47,7 +46,7 @@ object CompletionsOps {
4746
}
4847

4948
private def zshNames: String =
50-
ScalafixRules.allNamesDescriptions
49+
Rules.allNamesDescriptions
5150
.map {
5251
case (name, description) =>
5352
s""""$name[${StringEscapeUtils.escapeXSI(description)}]""""
@@ -62,7 +61,7 @@ _scalafix()
6261
COMPREPLY=()
6362
cur="$${COMP_WORDS[COMP_CWORD]}"
6463
prev="$${COMP_WORDS[COMP_CWORD-1]}"
65-
rules="${ScalafixRules.allNames.mkString(" ")}"
64+
rules="${Rules.allNames.mkString(" ")}"
6665
opts="$bashArgs"
6766

6867
case "$${prev}" in

0 commit comments

Comments
 (0)