Skip to content

Commit 7fb4e68

Browse files
committed
introduce WarningConfig DSL
1 parent 6dc6815 commit 7fb4e68

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.scalacoptions
18+
19+
sealed trait WarningAction
20+
21+
case object silent extends WarningAction
22+
case object error extends WarningAction
23+
24+
sealed trait WarningActionWithVerbosity extends WarningAction { action =>
25+
26+
def summary: WarningAction = new WarningAction {
27+
override def toString = s"$action-summary"
28+
}
29+
30+
def verbose: WarningAction = new WarningAction {
31+
override def toString = s"$action-verbose"
32+
}
33+
}
34+
35+
case object warning extends WarningActionWithVerbosity
36+
case object info extends WarningActionWithVerbosity
37+
38+
sealed class WarningFilter(val asString: String) {
39+
override def toString: String = asString
40+
41+
def &(that: WarningFilter): WarningFilter = new WarningFilter(
42+
Seq(this.asString, that.asString).mkString("&")
43+
)
44+
}
45+
46+
case object any extends WarningFilter("any")
47+
final case class cat(cat: String) extends WarningFilter(s"cat=$cat")
48+
final case class msg(regex: String) extends WarningFilter(s"msg=$regex")
49+
final case class src(regex: String) extends WarningFilter(s"src=$regex")
50+
51+
final case class origin(segments: String*)
52+
extends WarningFilter(s"origin=${segments.mkString(raw"\.")}")
53+
54+
final case class WarningConfig(rules: (WarningFilter, WarningAction)*) {
55+
56+
override def toString: String = {
57+
val conf = rules.toSeq
58+
.map { case (filter, action) => Seq(filter, action).mkString(":") }
59+
.mkString(",")
60+
s"-Wconf:$conf"
61+
}
62+
63+
def asScalacOption: ScalacOption =
64+
ScalacOption(
65+
option = this.toString,
66+
isSupported = {
67+
case ScalaVersion(2, 12, x) => x >= 13
68+
case ScalaVersion(2, 13, x) => x >= 2
69+
case _ => false
70+
}
71+
)
72+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2022 Typelevel
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.typelevel.scalacoptions
18+
19+
class WarningConfigSuite extends munit.ScalaCheckSuite {}

0 commit comments

Comments
 (0)