Skip to content

Implementation of Design Queries in Rego#68

Merged
Nfsaavedra merged 12 commits intosr-lab:interactive_repairfrom
infragov-project:rego_integration
Jan 29, 2026
Merged

Implementation of Design Queries in Rego#68
Nfsaavedra merged 12 commits intosr-lab:interactive_repairfrom
infragov-project:rego_integration

Conversation

@racoelhosilva
Copy link
Copy Markdown
Contributor

@racoelhosilva racoelhosilva commented Jan 15, 2026

Implementation of Design Queries in Rego

Description

This pull request contains the implementation of some Design analysis into the new Rego engine. The overall structure is similar to the one previously developed here for security smells.
Additionally, a memory free operation was now enforced upon generating Rego results. The OPA package was also updated to the latest version and there was a new Rego Python release.

Implemented Queries

The following queries and errors were adapted based on the existing Python logic:

  • Avoid Comments: design_avoid_comments
  • Imperative Abstraction: design_imperative_abstraction
  • Long Resource: design_long_resource
  • Misplaced Attribute: design_misplaced_attribute
  • Multifaceted Abstraction: design_multifaceted_abstraction
  • Too Many Variables: implementation_too_many_variables

Missing Queries

Currently, not all of the existing Design queries were converted due to the following reasons:

  • The queries require access to the original file contents, which is not contained in the current export of the intermediate representation. This is the case for design_duplicate_block, implementation_improper_alignment and implementation_long_statement.
  • The query logic requires some rework and other considerations. This is the case for implementation_unguarded_variable and design_unnecessary_abstraction.

Rego Wrapper Changes

The Go package for OPA was also bumped from version 0.70.0 to 1.12.3 and the corresponding release was created. With this, some investigation was done into converting the queries to Rego v1 syntax. This is still open for discussion but, for now, the queries still use Rego v0. Finally, another change was also added to this PR, to enforce freeing the memory created for the Rego output.

Testing

All tests related to these changes are passing and working as expected.

Notes

  • The file imperative_abstraction.py should not be necessary anymore since the query was converted to Rego. However, since there are not specific tests for this query, it was kept and a comment was added. A file similar to the IR was manually created and used during development for testing purposes.
  • To facilitate the implementation of Too Many Variables, a slight change was made to the Intermediate Representation export. In particular, an extra field was added to UnitBlocks that contains the number of lines in the respective file.
  • Some investigation was done into converting all the queries into Rego v1, which would require using opa fmt --rego-v1 and doing some small changes to the wrapper. This subject should be discussed soon.

This work was developed as part of the Infragov Project.


import data.glitch_lib

# Some changes were made to the data config to make the tests pass
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this

}
checker(node) {
attr := node.attributes[_]
regex.match("(&&|;|\\|)", attr.value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to check the value of an attribute, you would need something like attr.value.value.

@Nfsaavedra Nfsaavedra merged commit 0deaaa0 into sr-lab:interactive_repair Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants