Credence.Pattern.PreferHeredocForMultiLineDoc
(credence v0.8.0)
Copy Markdown
Detects @doc, @moduledoc, and @typedoc strings that contain
escaped newlines (\n) and should use heredoc syntax instead.
LLMs generate documentation as single-line strings with \n escapes
because that's how Python docstrings work. In Elixir, multi-line
documentation should use the heredoc (""") syntax for readability.
Bad
@doc "Finds the second largest number in a list.\nThe list must have at least two distinct values.\n"Good
@doc """
Finds the second largest number in a list.
The list must have at least two distinct values.
"""Auto-fix
Converts single-line @doc/@moduledoc/@typedoc strings containing
\n escapes into heredoc format. The fixer preserves indentation and
strips unnecessary trailing \n (since heredocs naturally end with a
newline). Strings containing \"\"\" are left unchanged.
Scope
Only \n-escaped strings (the form LLMs emit) are converted, via a
per-node patch over just the doc attribute. A doc string that already
spans multiple source lines (a real-newline regular string) is left
untouched: its multi-line range trips a Sourceror.patch_string edge that
swallows the following newline, and the only safe alternative — rendering
the whole file — would reformat unrelated, not-yet-formatted code.