fix: conditional expressions are now checked by require-data-selectors - #305
Merged
cacieprins merged 3 commits intoMar 24, 2026
Merged
cacieprins merged 3 commits into
cacieprins merged 3 commits into
Conversation
Collaborator
|
Collaborator
|
This proposed change looks like it goes in the direction of Conditional Testing. Since I don't have experience in this area, I would defer to the Cypress.io team to judge whether the added functionality is endorsed and encouraged, or perhaps to be discouraged. |
Contributor
Author
|
The code does not necessarily have to be used in conditional testing. We have custom commands that use a parameter in a conditional to support different use cases. The test itself passes a static parameter. |
cacieprins
self-requested a review
March 17, 2026 14:20
cacieprins
approved these changes
Mar 20, 2026
Contributor
|
While this does appear to endorse conditional expressions, it's a small change and does address the undefined behavior here. A |
Collaborator
|
🎉 This PR is included in version 6.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
We had some places in our codebase where we passed a conditional as the selector in 'cy.get'. Both branches conformed to the rule, but it was still flagged. Obviously, tracking a value across complex if/else branches is potentially impossible, but some false positives can be reduced by checking conditional expressions. This PR adds support for that, by checking each branch recursively against the current rules. This supports nested conditionals, conditionals assigned to variables, variables used in conditionals, etc. Documentation and tests are extended.
The following code was flagged before and is not anymore:
Note
Low Risk
Low risk: small, localized change to an ESLint rule’s AST checking plus test/doc updates; main risk is unintended allow/deny behavior for some selector expressions.
Overview
Fixes
cypress/require-data-selectorsfalse positives whency.get()receives a ternary/conditional selector by recursively validating both branches (including nested conditionals and variables).Updates rule docs and expands test coverage with new valid/invalid cases for conditional expressions, including alias branches and conditionals assigned to variables.
Written by Cursor Bugbot for commit c52556d. This will update automatically on new commits. Configure here.