Duplication is the primary enemy of a well-designed system. β Robert C. Martin
Disallow repetition when building strings with ternaries (optimize-string-ternary
) β
πΌ This rule is enabled in the following configs: π all
, β
recommended
.
π§ This rule is automatically fixable by the --fix
CLI option.
π Rule details β
This rule disallows repetition when building strings with ternaries.
π‘ Examples β
js
// β Incorrect
const CauseOrCampaign = !isNotCause ? 'Cause' : 'Campaign'
// β
Correct
const CauseOrCampaign = 'Ca' + (!isNotCause ? 'use' : 'mpaign')
π§ Config β
js
{ rules: { 'ninja/optimize-string-ternary': 2 } }