Repository navigation
Conversation
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.
Problem
prefer-optional-chainaccepts a value comparison as a new OR-chain guard when an unrelated operand precedes it:The comparison against
' 'is meaningful and cannot be replaced by an optional chain. The same two trailing operands are correctly left alone without the leadinginput.ctrl.Change
Apply
isInvalidOrChainStartingOperandwhen restarting an OR chain, matching the validation already used when starting a fresh chain. This prevents the restarted chain from treating a non-nullish value comparison as a nullish guard.Add regressions for a leading property, a separate boolean, and a reversed literal comparison. This is distinct from the trailing-comparison behavior in #1127: the invalid operand here starts a new chain after an unrelated operand.
Validation
8897346) before the change and pass afterward.go test ./internal/rules/prefer_optional_chainpasses, including the existing valid/invalid and fix snapshots.just readypasses: formatting, golangci-lint, build, E2E, and all Go tests.@typescript-eslint/prefer-optional-chain8.63.0.AI assistance: This contribution was prepared with OpenAI Codex.