Skip to content

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.

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.

Examples

Before — flagged Do not copy a structured value across functions
src/queries.ts
function one() {
return "SELECT id, status, created_at FROM candidates";
}
function two() {
return "SELECT id, status, created_at FROM candidates";
}
After — preferred Share one structured value
src/queries.ts
const QUERY = "SELECT id, status, created_at FROM candidates";
function one() {
return QUERY;
}
function two() {
return QUERY;
}