Skip to content

fix(groq-lint): avoid false positive for discriminated unions in array filters#28

Open
kmelve wants to merge 1 commit intomainfrom
fix/invalid-type-filter-discriminated-unions
Open

fix(groq-lint): avoid false positive for discriminated unions in array filters#28
kmelve wants to merge 1 commit intomainfrom
fix/invalid-type-filter-discriminated-unions

Conversation

@kmelve
Copy link
Collaborator

@kmelve kmelve commented Jan 19, 2026

Summary

Fixes #27 - The invalid-type-filter rule was incorrectly flagging _type filters on array items as invalid document types.

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:

*[_type == "post"] { "images": content[_type == "imageBlock"] }

Changes

  • Added isInTopLevelDocumentFilter() helper function that walks up the parent chain to check if the nearest Filter ancestor has Everything as its base
  • Updated check() to use the walker context and skip validation for nested array filters
  • Added 8 new test cases covering discriminated unions in various scenarios

Test plan

🤖 Generated with Claude Code

…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]>
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.

groq-invalid-type-filter false positive for discriminated union object types in arrays

1 participant