fix(rules): fix HasParent check and utilify it #1468
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.
#906 should've been closed by previous PRs, but a user recently reported some issues with it not being completely fixed.
I think they bumped into an edge case where if the resource type wasn't annotated with
google.api.resource
, the logic that checked if the resource was a child resource by looking for exactly one resource ID segment produced a false positive. It should've been checking for> 1
and accounting for the fact that if there are nopattern
s (or if it is unannotated), it is also not a child resource/has no parent.I've centralized an updated implementation in
rules/internal/utils
and inverted the logic as per the naminghasNoParent
->HasParent
.Also cleans up some variable names/comments in copy-pasted code.
Updates #906