oxc-project/oxc · warning · OxcDiagnostic

Unexpected string concatenation of literals.

Error message

Unexpected string concatenation of literals.

What it means

Diagnostic from the `no-useless-concat` rule. Two literals (string literals or template literals) are joined with `+`, but since both parts are statically known they can be merged into a single literal. Oxc flags binary `+` expressions (via BinaryOperator checks and line-terminator awareness) whose operands are both literals.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_useless_concat.rs:16

use oxc_ast::{
    AstKind,
    ast::{BinaryExpression, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_syntax::{line_terminator::is_line_terminator, operator::BinaryOperator};

use crate::{AstNode, context::LintContext, rule::Rule};

#[derive(Debug, Default, Clone)]
pub struct NoUselessConcat;

fn no_useless_concat_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected string concatenation of literals.")
        .with_help("Rewrite into one string literal.")
        .with_label(span)
}

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow unnecessary concatenation of literals or template literals.
    ///
    /// ### Why is this bad?
    ///
    /// It’s unnecessary to concatenate two strings together when they could
    /// be combined into a single literal.
    ///
    /// ### Examples
    ///
    /// Examples of **incorrect** code for this rule:
    /// ```javascript

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Merge the two literals: `"a" + "b"` -> `"ab"`.
  2. Use a single template literal with interpolation for mixed parts: `` `Hello ${name}` ``.
  3. If the split was for line length, rely on your formatter to wrap the merged literal.
  4. Use `oxlint --fix` where the rule provides an automatic join.

Example fix

// before
const msg = "Hello, " + "world";

// after
const msg = "Hello, world";
Defensive patterns

Strategy: validation

Validate before calling

const hasLiteralConcat = /(['"`])[^+]*\1\s*\+\s*(['"`])/.test(sourceLine);

Prevention

When it happens

Trigger: `"a" + "b"`, `` `a` + "b" ``, or a literal chain built across multiple lines such as `"long start" + "long end"`. Runs on BinaryExpression nodes with the concatenation operator and literal operands.

Common situations: Line-wrapping long messages before template literals were available; generated code from old bundlers/minifiers that split string constants; refactors that inlined a variable but left the `+`.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/e0df28b68270a957. Report an issue: GitHub.