Skip to content

add-constant

Suggest named constants for repeated literals.

Updated View as Markdown

Default severity: note

Reports a string literal when it appears for the third time in one file. A named constant keeps repeated protocol values, states, and keys consistent.

Bad

if state == "ready" { start() }
if next == "ready" { queue() }
if previous == "ready" { resume() }

Good

const stateReady = "ready"
if state == stateReady { start() }
Navigation

Type to search…

↑↓ navigate↵ selectEsc close