Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ _refs contains ref if {

not terms[0].value in _shadowed_imports

# util.to_location_row inlined for some extra performance
row := to_number(regex.replace(terms[0].location, `^(\d+):.*`, "$1"))
ref := {
"name": name,
Expand Down Expand Up @@ -132,14 +131,17 @@ _to_location_object(loc, text, file) := {"location": {
"col": col,
"text": text,
"end": {
"row": end_row,
"row": row,
"col": end_col,
},
}} if {
[r, c, er, ec] := split(loc, ":")
vals := split(loc, ":")

row := to_number(r)
col := to_number(c)
end_row := to_number(er)
end_col := to_number(ec)
row := to_number(vals[0])
col := to_number(vals[1])

from_col := substring(text, col - 1, -1)
ref_text := substring(from_col, 0, indexof(from_col, " "))

end_col := to_number(vals[1]) + count(ref_text)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ test_fail_identifies_unresolved_reference if {
x := 1
`)
r := rule.aggregate_report with input as {"aggregate": (agg1 | agg2)}
expected := {with_location({

r == {with_location({
"file": "p1.rego",
"row": 4,
"col": 7,
"end": {
"row": 4,
"col": 10,
"col": 14,
},
"text": "\tx := bar.baz",
})}
r == expected
}

test_success_no_unresolved_reference if {
Expand Down Expand Up @@ -53,17 +53,17 @@ test_fail_identifies_unresolved_reference_with_alias if {
x := 1
`)
r := rule.aggregate_report with input as {"aggregate": (agg1 | agg2)}
expected := {with_location({

r == {with_location({
"file": "p1.rego",
"row": 4,
"col": 7,
"end": {
"row": 4,
"col": 10,
"col": 14,
},
"text": "\tx := baz.qux",
})}
r == expected
}

test_success_identifies_reference_with_alias if {
Expand All @@ -77,6 +77,7 @@ test_success_identifies_reference_with_alias if {
qux := 1
`)
r := rule.aggregate_report with input as {"aggregate": (agg1 | agg2)}

r == set()
}

Expand All @@ -90,17 +91,17 @@ test_fail_identifies_unresolved_full_path if {
x := 1
`)
r := rule.aggregate_report with input as {"aggregate": (agg1 | agg2)}
expected := {with_location({

r == {with_location({
"file": "p1.rego",
"row": 3,
"col": 7,
"end": {
"row": 3,
"col": 11,
"col": 19,
},
"text": "\tx := data.bar.baz",
})}
r == expected
}

test_success_identifies_full_path if {
Expand All @@ -113,6 +114,7 @@ test_success_identifies_full_path if {
baz := 1
`)
r := rule.aggregate_report with input as {"aggregate": (agg1 | agg2)}

r == set()
}

Expand All @@ -139,14 +141,14 @@ test_fail_everything_all_at_once if {
`)
r := rule.aggregate_report with input as {"aggregate": (((agg1 | agg2) | agg3) | agg4)}

expected := {
r == {
with_location({
"file": "p1.rego",
"row": 5,
"col": 7,
"end": {
"row": 5,
"col": 10,
"col": 18,
},
"text": "\tx := bar.unknown",
}),
Expand All @@ -156,7 +158,7 @@ test_fail_everything_all_at_once if {
"col": 7,
"end": {
"row": 6,
"col": 10,
"col": 18,
},
"text": "\ty := qux.unknown",
}),
Expand All @@ -166,12 +168,11 @@ test_fail_everything_all_at_once if {
"col": 7,
"end": {
"row": 7,
"col": 11,
"col": 23,
},
"text": "\tz := data.qux.unknown",
}),
}
r == expected
}

test_success_everything_all_at_once if {
Expand Down Expand Up @@ -261,7 +262,7 @@ test_fail_builtin_namespaces_are_not_ignored if {
"col": 14,
"end": {
"row": 4,
"col": 18,
"col": 26,
},
"text": "\tfun(foo) := time.now_nss",
})}
Expand Down