-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dedis/1.1.4
1.1.4
- Loading branch information
Showing
29 changed files
with
712 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,12 @@ inThisBuild( | |
organizationName := "dedis", | ||
organizationHomepage := Some(url("https://dedis.epfl.ch")), | ||
homepage := Some(url("https://github.com/dedis/scapegoat-scalafix")), | ||
licenses := List("AGPL 3.0" -> url("https://www.gnu.org/licenses/agpl-3.0.en.html")), | ||
licenses := List("GPL 3.0" -> url("https://www.gnu.org/licenses/gpl-3.0.en.html")), | ||
developers := List(Developer("t1b00", "Thibault Czarniak", "[email protected]", url("https://www.linkedin.com/in/thcz/"))), | ||
semanticdbEnabled := true, | ||
semanticdbVersion := scalafixSemanticdb.revision, | ||
scmInfo := Some(ScmInfo(url("https://github.com/dedis/scapegoat-scalafix"), "scm:[email protected]:dedis/scapegoat-scalafix.git")), | ||
version := "1.1.3", | ||
version := "1.1.4", | ||
versionScheme := Some("pvp") | ||
) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
input/src/main/scala/fix/ExistsSimplifiableToContains.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
rule = ExistsSimplifiableToContains | ||
*/ | ||
package fix | ||
|
||
object ExistsSimplifiableToContains { | ||
val exists1 = List(1, 2, 3).exists(x => x == 2) // assert: ExistsSimplifiableToContains | ||
val exists12 = List(1, 2, 3).exists(x => 2 == x) // assert: ExistsSimplifiableToContains | ||
|
||
val list = List("sam", "spade") | ||
val exists2 = list.exists(_ == "spoof") // assert: ExistsSimplifiableToContains | ||
val exists22 = list.exists("spoof" == _) // assert: ExistsSimplifiableToContains | ||
|
||
val exists3 = (1 to 3).exists(_ == 2) // assert: ExistsSimplifiableToContains | ||
val exists32 = (1 to 3).exists(2 == _) // assert: ExistsSimplifiableToContains | ||
val exists33 = (1 until 3).exists(_ == 2) // assert: ExistsSimplifiableToContains | ||
val exists34 = (1 until 3).exists(2 == _) // assert: ExistsSimplifiableToContains | ||
|
||
def isItA(strings: String*): Boolean = { | ||
strings.exists { element => // assert: ExistsSimplifiableToContains | ||
element.toLowerCase == "a" | ||
} | ||
} | ||
|
||
val l: Iterable[String] = List[String]("a", "b", "c") | ||
print(l.exists(_ == "a")) // scalafix: ok; | ||
|
||
def atLeastOneIsAllLowercase(strings: String*): Boolean = { | ||
strings.exists { element => // scalafix: ok; | ||
element == element.toLowerCase | ||
} | ||
} | ||
|
||
def containsNoA(strings: String*): Boolean = { | ||
strings.exists { element => // scalafix: ok; | ||
element.replaceAll("a", "").size == element.size | ||
} | ||
} | ||
|
||
val map = Map("answer" -> "42") | ||
val isCorrect = map.exists(_._2 == "42") // scalafix: ok; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
rule = FilterDotHead | ||
*/ | ||
package fix | ||
|
||
object FilterDotHead { | ||
def test(): Unit = { | ||
List(1, 2, 3).filter(_ < 0).head // assert: FilterDotHead | ||
List(1, 2, 3).map(e => e).head // scalafix: ok; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
rule = FilterDotHeadOption | ||
*/ | ||
package fix | ||
|
||
object FilterDotHeadOption { | ||
def test(): Unit = { | ||
List(1, 2, 3).filter(_ < 0).headOption // assert: FilterDotHeadOption | ||
List(1, 2, 3).map(e => e).headOption // scalafix: ok; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
rule = FilterDotIsEmpty | ||
*/ | ||
package fix | ||
|
||
object FilterDotIsEmpty { | ||
def test(): Unit = { | ||
List(1, 2, 3).filter(_ < 0).isEmpty // assert: FilterDotIsEmpty | ||
List(1, 2, 3).map(e => e).isEmpty // scalafix: ok; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
rule = FilterDotSize | ||
*/ | ||
package fix | ||
|
||
object FilterDotSize { | ||
def test(): Unit = { | ||
List(1, 2, 3).filter(_ < 0).size // assert: FilterDotSize | ||
List(1, 2, 3).map(e => e).size // scalafix: ok; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
rule = FilterOptionAndGet | ||
*/ | ||
package fix | ||
|
||
object FilterOptionAndGet { | ||
def test(): Unit = { | ||
val a = List(None, Some("sam")).filter(_.isDefined).map(_.get) // assert: FilterOptionAndGet | ||
val b = List(None, Some("sam")).filter(_.isDefined).map(_.getOrElse("default")) // scalafix: ok; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
rule = FinalModifierOnCaseClass | ||
*/ | ||
package fix | ||
|
||
object FinalModifierOnCaseClass { | ||
case class Person(name: String) // assert: FinalModifierOnCaseClass | ||
abstract case class Person2(name: String) // scalafix: ok; | ||
final case class Person3(name: String) // scalafix: ok; | ||
|
||
// Comes from an issue on Scapegoat GitHub | ||
sealed abstract case class Nat(toInt: Int) // scalafix: ok; | ||
object Nat { | ||
def fromInt(n: Int): Option[Nat] = | ||
if (n >= 0) Some(new Nat(n) {}) else None | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
input/src/main/scala/fix/FindAndNotEqualsNoneReplaceWithExists.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
rule = FindAndNotEqualsNoneReplaceWithExists | ||
*/ | ||
package fix | ||
|
||
object FindAndNotEqualsNoneReplaceWithExists { | ||
def test(): Unit = { | ||
List(1, 2, 3).find(_ > 0) != None // assert: FindAndNotEqualsNoneReplaceWithExists | ||
List(1, 2, 3).find(_ > 0) == None // assert: FindAndNotEqualsNoneReplaceWithExists | ||
List(1, 2, 3).find(_ > 0) // scalafix: ok; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
rule = FindDotIsDefined | ||
*/ | ||
package fix | ||
|
||
object FindDotIsDefined { | ||
def test(): Unit = { | ||
val a = List(1, 2, 3).find(_ > 4).isDefined // assert: FindDotIsDefined | ||
val b = List(1, 2, 3).find(_ > 4) // scalafix: ok; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
rule = InvalidRegexTest | ||
*/ | ||
package fix | ||
|
||
object InvalidRegexTest { | ||
val regex = "?".r // assert: InvalidRegexTest | ||
val regex2 = "^[A-Z][A-Za-z0-9]*$".r // scalafix: ok; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
rule = IsInstanceOf | ||
*/ | ||
package fix | ||
|
||
object IsInstanceOf { | ||
def test(): Unit = { | ||
val s: Any = "sammy" | ||
println(s.isInstanceOf[String]) // assert: IsInstanceOf | ||
|
||
case class MappingCharFilter(name: String, mappings: (String, String)*) // scalafix: ok; | ||
|
||
val pf: PartialFunction[Any, Unit] = { | ||
case s: String => println(s) // scalafix: ok; | ||
case i: Int if i == 4 => println(i) // scalafix: ok; | ||
case _ => println("no match :(") // scalafix: ok; | ||
} | ||
|
||
@SuppressWarnings(Array("all")) | ||
def hello: Unit = { | ||
val s: Any = "sammy" | ||
println(s.isInstanceOf[String]) // scalafix: ok; | ||
} | ||
|
||
@SuppressWarnings(Array("IsInstanceOf")) | ||
def hello2: Unit = { | ||
val s: Any = "sammy" | ||
println(s.isInstanceOf[String]) // scalafix: ok; | ||
} | ||
|
||
sealed trait MyGADT[T] | ||
final case class VariantInt(value: Int) extends MyGADT[Int] | ||
final case class VariantString(value: String) extends MyGADT[String] | ||
|
||
def doStuff[T](gadt: MyGADT[T]): T = { // scalafix: ok; | ||
gadt match { | ||
case VariantInt(value) => value | ||
case VariantString(value) => value | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.