regal
regal copied to clipboard
Rule: suggest importing commonly used `data` ref
If a module has more than one reference to the same data
document, and there is no corresponding import, the largest common path should be suggested as a new import.
E.g., in the policy:
package example
p := data.a.b.c
q {
data.a.b.d == 2
}
two "naked" references to the data.a.b
document are made. The preferred style should be to import this reference:
package example
import data.a.b
p := b.c
q {
b.d == 2
}
Note: direct imports of a rule or function is likely not preferred, as some sort of grouping/namespacing might be implied, so even if several references are made to the same rule/function, it's parent document should be imported, e.g. for the policy:
package example
p := data.a.b.c
q {
data.a.b.c == 2
}
an import for the data.a.b
document should be suggested, not data.a.b.c
.