Skip to content

Conversation

@racoelhosilva
Copy link

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.

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.

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.

This work was developed as part of the Infragov Project.

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.

1 participant