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

Add support for configuring the plugin to only emit warnings #24

Merged
merged 2 commits into from
Jan 13, 2022
Merged
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
7 changes: 6 additions & 1 deletion acyclic/src/acyclic/plugin/Plugin.scala
Original file line number Diff line number Diff line change
@@ -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
@@ -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 =>

@@ -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{
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
===========