jatcwang / scalafix-named-params   0.2.5

GitHub

A scalafix rule to apply named parameters

Scala versions: 2.13 2.12

Scalafix rule for Named Parameters

This is a scalafix rule to add named parameters for your constructor and method calls.

The rule should fix any valid Scala code, including:

  • Curried calls and var args
  • Special characters in field names
  • Java classes and methods (by not doing anything :))

For example given this source code:

func(1,2,3)

myObj.someMethod(4,5,"6")

It will inspect the signature of the function methods and add named parameters:

func(first = 1, second = 2, third = 3)

myObj.someMethod(param1 = 4, param2 = 5, strParam =  "6")

Usage

Ensure your project has scalafix enabled and has the scalac option -P:semanticdb:synthetics:on.

Run in SBT:

scalafixEnable

yourmodulename/scalafix dependency:[email protected]:scalafix-named-params:<LATEST_VERSION>

# Or run the rule in test files
yourmodulename/test:scalafix dependency:[email protected]:scalafix-named-params:<LATEST_VERSION>

Replace <LATEST_VERSION> with the latest version of the rule.

Release

Configuration

By default, the rule will apply named parameter to function calls with 3 or more parameters.

You can configure this in .scalafix.conf

UseNamedParameters.minParams = 2

You can skip parameters with a single letter, such as x, y, or names that are only followed by a number, such as a1, a2, and so on.

UseNamedParameters.skipSingleAlphabet = true