Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 939 Bytes

readme.md

File metadata and controls

39 lines (28 loc) · 939 Bytes

Scalafix Rules WIP!!!

Linters

UnsafeIterableOps

List(1).head /* assert: UnsafeIterableOps
^^^^^^^^^^^^
  .head is unsafe, consider .headOption */

List(1).tail /* assert: UnsafeIterableOps
^^^^^^^^^^^^
  .tail is unsafe, consider .drop(1) */

List(1).minBy(identity) /* assert: UnsafeIterableOps
^^^^^^^^^^^^^
  .minBy is unsafe, consider .minByOption */

Rewrites

OptionBool

val x: Option[Boolean] = ???

- x.fold(true)(f)
+ a x.forall(f)

- x.fold(false)(f)
+ x.exists(f)

Backlog

  • name boolean arguments, except in standard functions such as Option#getOrElse
  • name arguments in applications with more than X arguments (and sort them alphabetically optionally)
  • rewrite trivial cases of UnsafeIterableOps such as if (xs.empty) None else Some(xs.minBy(f)), if (xs.size == 1) None else Some(xs.min)
  • suspicious sort before fold where the associativity of the operator isn't obvious