feat(base): flag null-returning JSX ternaries via no-restricted-syntax#32
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two
no-restricted-syntaxselectors that flag renderingnullfrom a JSX ternary:cond ? <JSX/> : nullcond ? 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-0guards need!!,??-fed values need: undefined, and||-guards need per-operand coercion. A human applies the fix.Both selectors only match a
JSXElement/JSXFragmentbranch, so they are inert outside.tsx/.jsx. Allno-restricted-syntaxselectors are consolidated into onegaia/no-restricted-syntaxconfig 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,buildgreen; a 13-case ESLintLintertest confirms it flags both ternary forms and ignores legit ternaries,&&,??, numeric/undefined/regex branches, andreturn null.Minor bump per the repo's versioning policy ("New rules added → minor"); changeset included.
🤖 Generated with Claude Code