module

Noir::CallFold

Folds a call or subscript left open at a line end onto the line that opens it, so a per-line accessor regex also sees a wrapped read (params.fetch( / :q / )) as params.fetch(:q).

For the #-comment, "/'-string languages (Ruby, Crystal, Elixir). Python has its own triple-quote-aware fold in PythonEngine.

Constants

MAX_CONTINUATION_LINES = 10

A wrapped accessor read spans a handful of lines. A ( still open after this many is a long call (or a mis-scan, like a ( in a regex literal) and is left unfolded rather than glued onto far-away code.

TRAILING_COMMA_RE = /,\s*([)\]])/

Instance methods

drop_trailing_commas(joined : String) : String

x["q",] → x["q"]: formatters (crystal tool format, black, prettier) add a trailing comma to a wrapped argument list, which the accessor regexes would read as part of the name.

Source
fold(lines : Array(String), & : String -> String) : Array(String)

lines, same size, each cut by the block (the language's comment stripper) and rstripped. A line that leaves a ( or [ open is followed by its (stripped) continuation lines, which also come back as themselves, so a per-line scan over the result finds everything it found on the comment-cut lines plus the wrapped reads.

Source