From 93699e59314fca24ad49ab31da5d6d0d3f331944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Wed, 10 May 2017 18:47:00 +0200 Subject: [PATCH] Add support for configuring the plugin to only emit warnings instead of errors --- build.sbt | 2 +- readme.md | 9 +++++++++ src/main/scala/acyclic/plugin/Plugin.scala | 7 ++++++- src/main/scala/acyclic/plugin/PluginPhase.scala | 11 +++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/build.sbt b/build.sbt index 3fd0f8e..db0bdc6 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,7 @@ organization := "com.lihaoyi" name := "acyclic" -version := "0.1.7" +version := "0.1.8" scalaVersion := "2.11.8" diff --git a/readme.md b/readme.md index b7f29e8..5b28ab2 100644 --- a/readme.md +++ b/readme.md @@ -219,6 +219,15 @@ import acyclic.skipped to tell the acyclic plugin to ignore them. +Warnings instead of errors +========================== + +If you want the plugin to only emit warnings instead of errors, add `warn` to the plugin's flags. + +```scala +scalacOptions += "-P:acyclic:warn" +``` + Limitations =========== diff --git a/src/main/scala/acyclic/plugin/Plugin.scala b/src/main/scala/acyclic/plugin/Plugin.scala index 257894c..61d6e02 100644 --- a/src/main/scala/acyclic/plugin/Plugin.scala +++ b/src/main/scala/acyclic/plugin/Plugin.scala @@ -11,16 +11,21 @@ class TestPlugin(val global: Global, val name = "acyclic" var force = false + var fatal = true + // Yeah processOptions is deprecated but keep using it anyway for 2.10.x compatibility override def processOptions(options: List[String], error: String => Unit): Unit = { if (options.contains("force")) { force = true } + if (options.contains("warn")) { + fatal = false + } } val description = "Allows the developer to prohibit inter-file dependencies" val components = List[tools.nsc.plugins.PluginComponent]( - new PluginPhase(this.global, cycleReporter, force) + new PluginPhase(this.global, cycleReporter, force, fatal) ) } diff --git a/src/main/scala/acyclic/plugin/PluginPhase.scala b/src/main/scala/acyclic/plugin/PluginPhase.scala index eaee91a..f364a8e 100644 --- a/src/main/scala/acyclic/plugin/PluginPhase.scala +++ b/src/main/scala/acyclic/plugin/PluginPhase.scala @@ -16,7 +16,8 @@ import tools.nsc.plugins.PluginComponent */ class PluginPhase(val global: Global, cycleReporter: Seq[(Value, SortedSet[Int])] => Unit, - force: => Boolean) + force: => Boolean, + fatal: => Boolean) extends PluginComponent with GraphAnalysis { t => @@ -145,7 +146,13 @@ class PluginPhase(val global: Global, cycleInfo.map{ case (a, b) => a -> b.map(_.pos.line).to[SortedSet]} ) - global.error("Unwanted cyclic dependency") + val msg = "Unwanted cyclic dependency" + if (fatal) { + global.error(msg) + } else { + global.warning(msg) + } + for (Seq((value, locs), (nextValue, _)) <- (cycleInfo :+ cycleInfo.head).sliding(2)){ global.inform("") value match{