Skip to content

feat(base): flag null-returning JSX ternaries via no-restricted-syntax#32

Merged
stevensacks merged 1 commit into
mainfrom
feat/no-null-render
Jun 25, 2026
Merged

feat(base): flag null-returning JSX ternaries via no-restricted-syntax#32
stevensacks merged 1 commit into
mainfrom
feat/no-null-render

Conversation

@stevensacks

Copy link
Copy Markdown
Contributor

Adds two no-restricted-syntax selectors that flag rendering null from a JSX ternary:

  • cond ? <JSX/> : null
  • cond ? null : <JSX/>

Both point to the boolean-guarded && form (cond && <JSX/>, coercing a numeric/falsy guard with !!cond). The selectors are flag-only (no autofix) because a blind ? : null&& rewrite is unsafe: numeric-0 guards need !!, ??-fed values need : undefined, and ||-guards need per-operand coercion. A human applies the fix.

Both selectors only match a JSXElement/JSXFragment branch, so they are inert outside .tsx/.jsx. All no-restricted-syntax selectors are consolidated into one gaia/no-restricted-syntax config object, because ESLint flat config merges that rule key by replacement (last match wins), not concatenation — a second block would silently clobber the existing default-export-arrow selector.

Verified locally: pnpm typecheck, lint, build green; a 13-case ESLint Linter test confirms it flags both ternary forms and ignores legit ternaries, &&, ??, numeric/undefined/regex branches, and return null.

Minor bump per the repo's versioning policy ("New rules added → minor"); changeset included.

🤖 Generated with Claude Code

Add two `no-restricted-syntax` selectors that flag `cond ? <JSX/> : null`
and `cond ? null : <JSX/>`, pointing to the boolean-guarded `&&` form.
Flag-only (no autofix): the safe rewrite needs `!!` for numeric guards and
`: undefined` for `??`-fed values, so a human applies it. Consolidate all
no-restricted-syntax selectors into one `gaia/no-restricted-syntax` block
since ESLint merges that rule key by replacement, not concatenation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@stevensacks stevensacks merged commit 55bb692 into main Jun 25, 2026
1 check passed
@stevensacks stevensacks deleted the feat/no-null-render branch June 25, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant