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

take into account config file BEFORE checking if rules are syntactic #103

Merged
merged 1 commit into from
May 13, 2020
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
12 changes: 5 additions & 7 deletions src/main/scala/scalafix/sbt/ScalafixPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,14 @@ object ScalafixPlugin extends AutoPlugin {
if (shell0.rules.isEmpty && shell0.extra == List("--help")) {
scalafixHelp
} else {
val scalafixConf = scalafixConfig.value.map(_.toPath)
val (shell, mainArgs0) = scalafixArgsFromShell(
shell0,
scalafixDependencies.in(ThisBuild).value,
scalafixResolvers.in(ThisBuild).value
)
val mainArgs = mainArgs0
.withConfig(jutil.Optional.ofNullable(scalafixConf.orNull))
.withRules(shell.rules.asJava)
.safeWithArgs(shell.extra)
val rulesThatWillRun = mainArgs.safeRulesThatWillRun()
Expand All @@ -175,8 +177,7 @@ object ScalafixPlugin extends AutoPlugin {
runArgs(
filesToFix(shellArgs, config).value,
mainArgs,
streams.value.log,
scalafixConfig.value
streams.value.log
)
}

Expand All @@ -202,8 +203,7 @@ object ScalafixPlugin extends AutoPlugin {
runArgs(
files,
args,
streams.value.log,
scalafixConfig.value
streams.value.log
)
}
} else {
Expand All @@ -223,11 +223,9 @@ object ScalafixPlugin extends AutoPlugin {
private def runArgs(
paths: Seq[Path],
mainArgs: ScalafixArguments,
logger: Logger,
config: Option[File]
logger: Logger
): Unit = {
val finalArgs = mainArgs
.withConfig(jutil.Optional.ofNullable(config.map(_.toPath).orNull))
.withPaths(paths.asJava)

if (paths.nonEmpty) {
Expand Down
3 changes: 3 additions & 0 deletions src/sbt-test/sbt-scalafix/custom-config/.scalafixxx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rules = [
RemoveUnused
]
6 changes: 6 additions & 0 deletions src/sbt-test/sbt-scalafix/custom-config/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
val V = _root_.scalafix.sbt.BuildInfo

scalaVersion := V.scala212
addCompilerPlugin(scalafixSemanticdb)
scalacOptions ++= Seq("-Yrangepos", "-Ywarn-unused")
scalafixConfig := Some(file(".scalafixxx.conf"))
2 changes: 2 additions & 0 deletions src/sbt-test/sbt-scalafix/custom-config/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package example

import java.util.Map
import scala.concurrent.Future

object Example {
implicit val str = null.asInstanceOf[Map.Entry[Int, String]]
}
1 change: 1 addition & 0 deletions src/sbt-test/sbt-scalafix/custom-config/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> scalafix