Skip to content

TypeScript · maintainability

no-repeated-string-literal

eslint:no-repeated-string-literal

Disallow a long structured string literal repeated across functions; the copies drift when one is edited. Extract a module-level constant.

Default
error
Fix
none
Languages
typescript

Why

Independent copies of a query, route template, or identifier can diverge and silently change behavior.

Fix

Extract the repeated value to one module-level constant and reference it from each function.

Before / after

Executed by this rule’s unit tests.

Before

Do not copy a structured value across functions

src/queries.ts · focus
function one() { return 'SELECT id, status, created_at FROM candidates'; }
function two() { return 'SELECT id, status, created_at FROM candidates'; }

After

Share one structured value

src/queries.ts · focus
const QUERY = 'SELECT id, status, created_at FROM candidates';
function one() { return QUERY; }
function two() { return QUERY; }

Limits

  • Test files, short strings, prose, substitutions, module sources, JSX attributes, and repetition within one function are excluded.

Message IDs

noRepeatedStringLiteral