ForgeCredoChecks.MultilineStringConcat (forge_credo_checks v0.8.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of normal and works with any version of Elixir.

Explanation

Replace multi-line string-literal <> concatenation with a heredoc.

Why

Assembling a wrapped string literal with "..." <> "..." <> "..." spread across source lines is unidiomatic noise. Elixir heredocs (""" ... """) are the clean form for multi-line string literals; the <>-per-line pattern is a reviewer nit that signals an author reached for concatenation instead of the language's built-in multi-line string syntax.

This check fires only when every operand of the <> chain is a plain string literal and the chain spans more than one source line. A <> that mixes in a variable or expression is legitimate interpolation avoidance or dynamic assembly and is not flagged; a single-line <> of literals is rare but harmless and is not flagged either.

How to fix

# BEFORE
"first line " <>
"second line " <>
"third line"

# AFTER
"""
first line second line third line
"""

When the concatenation is used to keep a single-line result under the line length limit, use a heredoc with a trailing-backslash line continuation:

"""
first line second line third line\
"""

What NOT to do

Do not disable this check for a <> chain that mixes a literal with a variable ("prefix " <> some_var). That form is intentionally out of scope: it is not a static string literal and may be avoiding interpolation for performance or readability reasons.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.