Scalafix

Scalafix

  • User guide
  • Developer guide
  • Browse sources
  • GitHub

›Rules

Usage

  • Installation
  • Configuration
  • Suppressing rules

Rules

  • Built-in rules
  • DisableSyntax
  • ExplicitResultTypes
  • LeakingImplicitClassVal
  • NoAutoTupling
  • NoValInForComprehension
  • ProcedureSyntax
  • RedundantSyntax
  • RemoveUnused
  • Using external rules
  • Community rules

Misc

  • Related projects
Edit

LeakingImplicitClassVal

Non-private val fields of implicit classes leak as publicly accessible extension methods. This rule adds the private access modifier on the field of implicit value classes in order to prevent direct access.

// before
implicit class XtensionVal(val str: String) extends AnyVal {
  def doubled: String = str + str
}
"message".str // compiles

// after
implicit class XtensionValFixed(private val str: String) extends AnyVal {
  def doubled: String = str + str
}
"message".str // does not compile

This rule only triggers for val fields, it ignores other modifiers such as var.

← ExplicitResultTypesNoAutoTupling →
Scalafix
Docs
Get startedRulesExtend Scalafix
Community
Chat on DiscordDiscuss on Scala Users
More
GitHub
Copyright © 2023 Scala Center