Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove some code made redundant by roast #1013

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions bundle/regal/lsp/completion/providers/snippet/snippet.rego
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ items contains item if {
some label, snippet in _snippets

strings.any_prefix_match(snippet.prefix, word.text)

# regal ignore:todo-comment
# TODO: use https://github.com/open-policy-agent/opa/pull/6841 when
# released.
count(regex.find_n(snippet.prefix[0], line, 2)) < 2
strings.count(line, snippet.prefix[0]) < 2

not endswith(trim_space(line), "=")

Expand Down
26 changes: 8 additions & 18 deletions bundle/regal/result.rego
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ _fail_annotated(metadata, details) := violation if {
})

without_custom_and_scope := object.remove(with_category, ["custom", "scope", "schemas"])
related_resources := resource_urls(without_custom_and_scope.related_resources, category)
related_resources := _resource_urls(without_custom_and_scope.related_resources, category)

violation := json.patch(
without_custom_and_scope,
Expand All @@ -171,7 +171,7 @@ _fail_annotated_custom(metadata, details) := violation if {
violation := object.remove(with_category, ["custom", "scope", "schemas"])
}

resource_urls(related_resources, category) := [r |
_resource_urls(related_resources, category) := [r |
some item in related_resources
r := object.union(object.remove(item, ["ref"]), {"ref": config.docs.resolve_url(item.ref, category)})
]
Expand All @@ -185,26 +185,16 @@ _with_text(loc_obj) := loc if {
loc_obj.row
} else := {"location": loc_obj}

# METADATA
# description: |
# returns a "normalized" location object from the location value found in the AST.
# new code should most often use one of the ranged_ location functions instea, as
# that will also include an `"end"` location attribute
# scope: document
location(x) := _with_text(util.to_location_object(x.location))

location(x) := _with_text(util.to_location_object(x[0].location)) if is_array(x)

# Special case for rule refs, where location is currently only assigned to the value
# In this case, we'll just assume that the column is 1, as that's the most likely place
# See: https://github.com/open-policy-agent/opa/issues/5790
location(x) := _with_text(loc_obj) if {
not x.location
count(x.ref) == 1
x.ref[0].type == "var"
loc_obj := object.union(util.to_location_object(x.value.location), {"col": 1})
}

location(x) := {} if {
not x.location
not x.Location
count(x.ref) != 1
}

# METADATA
# description: |
# similar to `location` but includes an `end` attribute where `end.row` is the same
Expand Down