-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathDisableSimple.scala
72 lines (65 loc) · 1.98 KB
/
DisableSimple.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
rules = Disable
Disable.symbols = [
"scala.Any.asInstanceOf"
"test.DisableSimple.D.disabledFunction"
{
symbol = "scala.Option.get"
id = "Option.get"
message =
"""|Option.get is the root of all evils
|
|If you must Option.get, wrap the code block with
|// scalafix:off Option.get
|...
|// scalafix:on Option.get"""
}
"scala.collection.mutable"
"scala.collection.immutable.List.drop"
"scala.collection.LinearSeqOptimized.length"
]
Disable.ifSynthetic = [
"scala.Predef.any2stringadd"
]
*/
package test
case object DisableSimple {
import scala.collection.mutable.ListBuffer // ok
import scala.collection.mutable.BitSet // ok
case class B()
val y = B().asInstanceOf[String] // assert: Disable.asInstanceOf
val z = 1.asInstanceOf[String] // assert: Disable.asInstanceOf
val x = "2".asInstanceOf[Int] // assert: Disable.asInstanceOf
val w = List(1, 2, 3).asInstanceOf[Seq[String]] // assert: Disable.asInstanceOf
case class D() {
def disabledFunction: Boolean = true // assert: Disable.disabledFunction
}
val zz = D().disabledFunction // assert: Disable.disabledFunction
case class C() {
def asInstanceOf: String = "test"
}
val xx = C().asInstanceOf // OK, no errors
trait A {
type O
}
object AA extends A {
type O = String
def asInstanceOf: O = "test"
}
val yy = AA.asInstanceOf // OK, no errors
Option(1).get /* assert: Disable.Option.get
^^^
Option.get is the root of all evils
If you must Option.get, wrap the code block with
// scalafix:off Option.get
...
// scalafix:on Option.get
*/
val l: ListBuffer[Int] = scala.collection.mutable.ListBuffer.empty[Int] // assert: Disable.mutable
List(1) + "any2stringadd" /* assert: Disable.any2stringadd
^^^^^^^
any2stringadd is disabled and it got inferred as `Predef.any2stringadd[List[Int]](*)`
*/
@SuppressWarnings(Array("Disable.drop", "Disable.length"))
val _ = List(1, 2 ,3).drop(2).filter(_ > 3).reverse.length
}