MethodSpacingNormalizer

com.colofabrix.scala.dixtra.normalize.MethodSpacingNormalizer

Blank-line-between-methods normalisation.

Ensures a single blank line precedes every method definition that directly follows another statement, so adjacent defs are always visually separated. given definitions and extension groups are methods too and are separated exactly like defs.

A method's decorations — the annotations, scaladoc, and comments on the lines directly above its def (multi-line scaladoc included) — form one group with it, so the blank line goes before the whole group, never between a decoration and the def. The blank line is inserted only when the line before the group is non-blank and is not an opener: a line ending with { or : (Scala 3 braceless object A:) or with with (given A: B with), an extension (...) header, or a line ending with = or => that opens a braceless body (so a local given or def at the top of a method body is not pushed down). The blank lines at the top of a body follow blank-lines.body-edges instead (see EdgeBlankLines).

One-line definitions (val, lazy val, var, def, given, type, a one-line declaration without a body included) at the same indent whose keywords are both in an alignment group follow the groups instead: two adjacent one-liners of the same group are a block and are not separated; between two of different groups the blank line follows BlankLinesConfig.betweenAlignmentGroups (kept as written, always, or never). Comments and annotations above a one-liner do not change that, but a scaladoc does: the blank line before a definition with a scaladoc follows blank-lines.before-scaladoc (added with always, and with always-multiline for a multi-line scaladoc), and a one-line one also gets a blank line after it, before the next statement at its indent.

This is a line pass keyed off lines whose first token (after optional modifiers, including qualified private[x] / protected[x]) is def, given, or extension, which is robust for the rendered output where signatures start their own line. It is token-aware: a line that starts inside a multi-line string or comment is never a method start, and no line is ever inserted inside such a token. If the text cannot be tokenised, the input is returned unchanged (safety net).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def normalize(source: String, alignment: AlignmentConfig, betweenGroups: BlankLinePolicy, beforeScaladoc: ScaladocSpacing): String

Insert a blank line before each method (and its decorations) that follows adjacent content, with the given alignment groups and blank line between them, and the given blank line before a scaladoc.

Insert a blank line before each method (and its decorations) that follows adjacent content, with the given alignment groups and blank line between them, and the given blank line before a scaladoc.

Attributes