Skip to content

Commit

Permalink
Merge pull request #24 from oyvindberg/warnings-instead-of-errors
Browse files Browse the repository at this point in the history
Add support for configuring the plugin to only emit warnings
  • Loading branch information
lefou authored Jan 13, 2022
2 parents 1195635 + bc6596e commit 4b70a2e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion acyclic/src/acyclic/plugin/Plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
11 changes: 9 additions & 2 deletions acyclic/src/acyclic/plugin/PluginPhase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 =>

Expand Down Expand Up @@ -148,7 +149,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{
Expand Down
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,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
===========

Expand Down

0 comments on commit 4b70a2e

Please sign in to comment.