{"record":{"id":"e0df28b68270a957","repo":"oxc-project/oxc","slug":"unexpected-string-concatenation-of-literals","errorCode":null,"errorMessage":"Unexpected string concatenation of literals.","messagePattern":"Unexpected string concatenation of literals\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_useless_concat.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{BinaryExpression, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::{line_terminator::is_line_terminator, operator::BinaryOperator};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\n#[derive(Debug, Default, Clone)]\npub struct NoUselessConcat;\n\nfn no_useless_concat_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Unexpected string concatenation of literals.\")\n        .with_help(\"Rewrite into one string literal.\")\n        .with_label(span)\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow unnecessary concatenation of literals or template literals.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// It’s unnecessary to concatenate two strings together when they could\n    /// be combined into a single literal.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:\n    /// ```javascript","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_useless_concat.rs#L1-L34","documentation":"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.","triggerScenarios":"`\"a\" + \"b\"`, `` `a` + \"b\" ``, or a literal chain built across multiple lines such as `\"long start\" +\n\"long end\"`. Runs on BinaryExpression nodes with the concatenation operator and literal operands.","commonSituations":"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 `+`.","solutions":["Merge the two literals: `\"a\" + \"b\"` -> `\"ab\"`.","Use a single template literal with interpolation for mixed parts: `` `Hello ${name}` ``.","If the split was for line length, rely on your formatter to wrap the merged literal.","Use `oxlint --fix` where the rule provides an automatic join."],"exampleFix":"// before\nconst msg = \"Hello, \" + \"world\";\n\n// after\nconst msg = \"Hello, world\";","handlingStrategy":"validation","validationCode":"const hasLiteralConcat = /(['\"`])[^+]*\\1\\s*\\+\\s*(['\"`])/.test(sourceLine);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Author long strings as a single literal or one template literal.","Let the formatter handle line length instead of splitting strings with +.","Prefer interpolation `\\`Hello ${name}\\`` over concatenation."],"tags":["lint","eslint","oxlint","string","concatenation"],"backgroundTag":"no-useless-string-concat","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}