feat: add warning for mixed operators without parentheses#2786
feat: add warning for mixed operators without parentheses#2786ivanauth wants to merge 10 commits intoauthzed:mainfrom
Conversation
aa2be07 to
6a03a3d
Compare
Codecov Report❌ Patch coverage is ❌ Your project check has failed because the head coverage (74.52%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2786 +/- ##
==========================================
+ Coverage 74.40% 74.52% +0.12%
==========================================
Files 484 484
Lines 57406 57852 +446
==========================================
+ Hits 42707 43106 +399
- Misses 11709 11735 +26
- Partials 2990 3011 +21 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@ivanauth this won't actually work in all cases, because expressions can cross multiple lines. Instead, this should likely be done by marking the expression during compilation with a piece of metadata, and having the warnings generator read that metadata |
|
Switched from source-scanning to compile-time metadata detection per review feedback. Added |
88ff553 to
6952dbd
Compare
Satisfies panic check linter which allows panics in Must* functions. Also regenerates proto files after import order fix.
Add TestMixedOperatorsMetadata to pkg/namespace/metadata_test.go covering all code paths in HasMixedOperatorsWithoutParens, GetMixedOperatorsPosition, and SetMixedOperatorsWithoutParens (nil metadata, empty metadata, non-permission relation, permission with/without flag, set/clear operations, creation of new metadata entries). Add additional warning test cases to pkg/development/warnings_test.go for mixed intersection+exclusion, intersection+union operator combinations, same-operators-repeated (no warning), and relation-referencing-parent for a non-permission relation.
e292e69 to
5c2b616
Compare
Update the expected AST output for the self_test to reflect the new NodeTypeParenthesizedExpression wrapper that is now emitted when parsing parenthesized expressions. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When writing permission expressions like
viewer - blocked & editor, it's easy to assume arithmetic-style precedence. But SpiceDB's actual precedence (exclusion binds loosest, then intersection, then union) can lead to unexpected behavior.This adds a lint warning that flags mixed operators at the same scope, nudging users to add parentheses and make their intent explicit.
Example:
The warning can be suppressed with:
Fixes authzed/zed#598