Skip to content
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

Rule: suggest importing commonly used data ref #452

Open
johanfylling opened this issue Nov 9, 2023 · 1 comment
Open

Rule: suggest importing commonly used data ref #452

johanfylling opened this issue Nov 9, 2023 · 1 comment

Comments

@johanfylling
Copy link
Member

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.

@srenatus
Copy link
Member

srenatus commented Nov 9, 2023

💭 Rule of three, maybe? I mean propose it if there are at least three references that share a prefix (which is not a plain data, of course) Or maybe that's a desirable configurable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Planned
Development

No branches or pull requests

3 participants