fix(groq-lint): avoid false positive for discriminated unions in array filters#28
Open
fix(groq-lint): avoid false positive for discriminated unions in array filters#28
Conversation
…y filters The `invalid-type-filter` rule was incorrectly flagging `_type` filters on array items as invalid document types. This fixes issue #27. The fix uses the walker's context to detect if a `_type` comparison is in a top-level document filter (`*[...]`) vs a nested array filter (`field[...]`). Only top-level filters are validated against document types, while nested array filters are skipped since they're used for discriminated union object types. Example that was incorrectly flagged: ```groq *[_type == "post"] { "images": content[_type == "imageBlock"] } ``` Closes #27 Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.
Summary
Fixes #27 - The
invalid-type-filterrule was incorrectly flagging_typefilters on array items as invalid document types.The fix uses the walker's context to detect if a
_typecomparison is in a top-level document filter (*[...]) vs a nested array filter (field[...]). Only top-level filters are validated against document types, while nested array filters are skipped since they're used for discriminated union object types.Example that was incorrectly flagged:
Changes
isInTopLevelDocumentFilter()helper function that walks up the parent chain to check if the nearestFilterancestor hasEverythingas its basecheck()to use the walker context and skip validation for nested array filtersTest plan
groq-invalid-type-filterfalse positive for discriminated union object types in arrays #27🤖 Generated with Claude Code