Skip to content

tersesystems/disable-case-class-to-string

Repository files navigation

Scalafix rules for DisableCaseClassToString

This is a Scalafix rule that disables the toString method on case classes, preventing leaks of sensitive information.

Both explicit toString and string interpolation are disabled:

def explicitToString = {
  val foo = Foo("name")
  foo.toString // assert DisableCaseClassToString
}

asserts, as does:

def explicitToString = {
  val foo = Foo("name")
  s"$foo" // assert DisableCaseClassToString
}

Also any2stringadd and string synthetic addition should prevent an implicit toString on a case class:

def lit2Add: String = {
  val foo = Foo("name")
  "" + foo  // assert: DisableCaseClassToString
}

def method2Add: String = {
  val foo = Foo("name")
  stringMethod + foo // assert: DisableCaseClassToString
}

def stillString: String = {
  val foo = Foo("name")
  // any2stringadd(foo)
  foo + stringMethod // assert: DisableCaseClassToString
}

Configuration

rules = [
  DisableCaseClassToString
]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages