Replace `+`-based string concatenation with template literals (backticks) in JavaScript/TypeScript code where semantics are preserved, aligning with ESLint `prefer-template` best practices and improving readability/maintainability.
Replace +-based string concatenation with template literals (backticks) in JavaScript/TypeScript code where semantics are preserved, aligning with ESLint prefer-template best practices and improving readability/maintainability.
Installation
bash
# Install from registry
npx codemod@latest javascript-prefer-template-literals
# Or run locally
npx codemod@latest workflow run -w .
Usage
This codemod rewrites left-associative + string-concatenation chains into template literals across:
.js, .mjs, .cjs, .ts via the TypeScript parser
.jsx, .tsx via the TSX parser
It transforms chains only when string intent is explicit and evaluation order is preserved.
It is intentionally conservative about chains whose first explicit string appears later in the expression.