This rewrite inserts type annotations for inferred public members. Only compatible with 2.11.12, 2.12.13, 2.12.14, 2.12.15, 2.13.4, 2.13.5, 2.13.6
- def myComplexMethod = 1.to(10).map(i => i -> i.toString).toMap + def myComplexMethod: Map[Int, String] = 1.to(10).map(i => i -> i.toString).toMap
By default, only rewrite adds type annotations for public members that have non-trivial bodies.
|Enable/disable this rule for defs, vals or vars.|
|Enable/disable this rule for private/protected members.|
|If false, insert explicit result types even for simple definitions like `val x = 2`|
|If true, report and fail unexpected errors. If false, silently ignore errors to produce an explicit result type.|
|If false, disables rewriting of inferred structural types to named subclasses. Beware that this option may produce code that no longer compiles if it previously used `scala.language.reflectiveCalls` to access methods on structural types.|
ExplicitResultTypes.memberKind = [ Def, Val, Var ] ExplicitResultTypes.memberVisibility = [ Public, Protected ] ExplicitResultTypes.skipSimpleDefinitions = ['Term.Ref', 'Lit', 'Term.New'] ExplicitResultTypes.fatalWarnings = false ExplicitResultTypes.rewriteStructuralTypesToNamedSubclass = true
ExplicitResultTypes.memberKind = [Def, Val, Var] ExplicitResultTypes.memberVisibility = [Public, Protected] ExplicitResultTypes.skipSimpleDefinitions = ['Lit', 'Term.New']
This rule has several known limitations, which are most likely fixable with some effort. At the time of this writing, there are no short-term plans to address these issues however.
The rewrite inserts imports at the bottom of the global import list. Users are expected to organize the imports according to the conventions of their codebase.
For example, the rewrite may produce the following diff.
import java.io.File import scala.collection.mutable + import java.util.UUID
- use https://github.com/NeQuissimus/sort-imports
- use https://github.com/liancheng/scalafix-organize-imports
- run "organize imports" refactoring in IntelliJ