noctcore-code-quality/no-template-trim-empty-ternary
Extract the inline
`…`.trim() === '' ? fallback : `…`.trim()pattern to a named util. Niche — not inrecommended.
Recommended preset: not included · Autofix: no · Suggestions: no · Type information: not needed
The inline shape `${a} ${b}`.trim() === '' ? fallback : `${a} ${b}`.trim() builds the same
template-plus-trim() expression twice and buries a small piece of display logic where it can’t be
unit-tested on its own. Extracting it to a named helper (e.g. buildDisplayName(...)) builds the
expression once and gives it one testable home.
This is a very specific pattern, so the rule is excluded from the recommended preset. Enable it
explicitly if the shape recurs in your codebase.
Enabling it
Section titled “Enabling it”Not part of recommended. Turn it on directly:
'noctcore-code-quality/no-template-trim-empty-ternary': 'error'What it flags
Section titled “What it flags”A ConditionalExpression whose test is a === / !== comparison between an empty-string literal
and a .trim() call on a template literal, in either order.
const name = `${first} ${last}`.trim() === '' ? email : `${first} ${last}`.trim();const label = '' !== `${a}`.trim() ? `${a}`.trim() : fallback;const name = buildDisplayName({ first, last, fallback: email });const trimmed = value.trim() === '' ? fallback : value; // not a template literalWhat it does not flag
Section titled “What it does not flag”- A
.trim()empty check on anything that is not a template literal (value.trim() === ''). - A trimmed template outside a ternary test (
const label = `${first} ${last}`.trim();).
When not to use it
Section titled “When not to use it”If this pattern doesn’t appear in your codebase, there’s nothing to gain from enabling it.