TrailingCommentNormalizer

com.colofabrix.scala.dixtra.normalize.TrailingCommentNormalizer

Trailing comments: the one-line comments at the end of a line of code.

A trailing comment never counts in the width of its line, so the code before it never breaks because of it. Two passes change where it goes:

  • moveAbove, with overflow.trailing-comment = move-above: a line that goes past the maximum width with its trailing comment gets the comment on a line of its own above, at the indent of the line. When the line above is a // comment, an empty // line keeps the two comments apart, so that the comment reflow does not join them.
  • align, with alignment.trailing-comments: the trailing comments of consecutive lines start on one column, one space after the longest code. A line that would go past the maximum width once aligned stays as it is, and the lines before and after it align separately.

Both passes are token-aware; if the text cannot be tokenised, it is returned unchanged (safety net).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def align(source: String, maxColumn: Int, enabled: Boolean): String

Align on one column the trailing comments of consecutive lines, when enabled, never past maxColumn.

Align on one column the trailing comments of consecutive lines, when enabled, never past maxColumn.

Attributes

def moveAbove(source: String, maxColumn: Int, policy: TrailingOverflow): String

Move above its line each trailing comment whose line goes past maxColumn, when policy is move-above.

Move above its line each trailing comment whose line goes past maxColumn, when policy is move-above.

Attributes