-
Notifications
You must be signed in to change notification settings - Fork 353
Member collisions policies: id, value, const name #2456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,10 +89,82 @@ deny contains attr_registry_violation(description, group.id, "") if { | |
| description := sprintf("Semconv group '%s' does not contain stability field. All semconv definitions must include stability level.", [group.id]) | ||
| } | ||
|
|
||
|
|
||
| # check that attribute is not defined or referenced more than once within the same group | ||
| deny contains attr_registry_violation(description, group.id, name) if { | ||
| group := input.groups[_] | ||
| attr := group.attributes[_] | ||
| name := attr.name | ||
|
|
||
| collisions := [n | n := group.attributes[_].name; n == name ] | ||
| count(collisions) > 1 | ||
|
|
||
| description := sprintf("Attribute '%s' is already defined in the group '%s'. Attributes must be unique.", [name, group.id]) | ||
| } | ||
|
|
||
| # check that member ids do not collide within the same attribute | ||
| deny contains attr_registry_violation(description, group.id, attr.id) if { | ||
| group := input.groups[_] | ||
| startswith(group.id, "registry.") | ||
|
|
||
| attr := group.attributes[_] | ||
| member := attr.type.members[_] | ||
|
|
||
| collisions := [n | n := attr.type.members[_].id; n == member.id ] | ||
| count(collisions) > 1 | ||
|
|
||
| description := sprintf("Member with id '%s' is already defined on the attribute '%s' in the group '%s'. Member id must be unique.", [member.id, attr.id, group.id]) | ||
| } | ||
|
|
||
| # check that member values do not collide within the same attribute | ||
| deny contains attr_registry_violation(description, group.id, attr.id) if { | ||
| group := input.groups[_] | ||
| startswith(group.id, "registry.") | ||
| attr := group.attributes[_] | ||
| member := attr.type.members[_] | ||
| not is_property_set(member, "deprecated") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can never understand the difference between |
||
|
|
||
| collisions := [m | ||
| | m := attr.type.members[_] | ||
| not is_property_set(m, "deprecated") | ||
| m.value == member.value | ||
| ] | ||
| count(collisions) > 1 | ||
|
|
||
| description := sprintf("Member with value '%s' (id '%s') is already defined on the attribute '%s' in the group '%s'. Member value must be unique.", [member.value, member.id, attr.id, group.id]) | ||
| } | ||
|
|
||
| # check that member const names do not collide within the same attribute | ||
| deny contains attr_registry_violation(description, group.id, attr.id) if { | ||
| group := input.groups[_] | ||
| startswith(group.id, "registry.") | ||
| attr := group.attributes[_] | ||
| member := attr.type.members[_] | ||
| not member.annotations["code_generation"]["exclude"] | ||
|
|
||
| const_name := to_const_name(member.id) | ||
|
|
||
| collisions := [m | ||
| | m := attr.type.members[_] | ||
| to_const_name(m.id) == const_name | ||
| not m.annotations["code_generation"]["exclude"] | ||
| ] | ||
| count(collisions) > 1 | ||
|
|
||
| description := sprintf("Member with const name '%s' (id '%s'), is already defined on the attribute '%s' in the group '%s'. Member const names must be unique.", [const_name, member.id, attr.id, group.id]) | ||
| } | ||
|
|
||
| get_attribute_name(attr, group) := name if { | ||
| full_name := concat(".", [group.prefix, attr.id]) | ||
|
|
||
| # if there was no prefix, we have a leading dot | ||
| name := trim(full_name, ".") | ||
| } | ||
|
|
||
| to_const_name(name) = const_name if { | ||
| const_name := replace(name, ".", "_") | ||
| } | ||
|
|
||
| is_property_set(obj, property) = true if { | ||
| obj[property] != null | ||
| } else = false | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attribute-duplicate rule applies to every group. To match other member-collision rules, add a filter like
startswith(group.id, "registry.")so non-registry groups aren’t inadvertently flagged.