-
Notifications
You must be signed in to change notification settings - Fork 315
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
feat(queries): implementation of regal for linting rego files #7295
Open
ArturRibeiro-CX
wants to merge
87
commits into
master
Choose a base branch
from
add_regal_linter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR integrates the Regal linter for Rego files in KICS to support query maintanance, reusability and best practices. As KICS uses Rego extensively to build queries, adding a linter helps ensuring consistency and quality across our codebase.
Thanks to the contributors who initiated the discussions and provided input for this addition. 🥳 🙌
Closes #6774
Reason for Proposed Changes
Proposed Changes
Fixed Lint Problems:
opa fmt
, which removes unnecessary whitespace, replaces spaces with tabs, and ensures consistent formatting across the codebase. This command helps maintain a clean and readable structure.opa fmt -w <path_to_rego_file>
/openapi.rego
/cloudFormation/aws_bom/dynamo/query.rego
/openAPI/2.0/non_body_parameter_with_schema/query.rego
/openAPI/general/example_not_compliant_with_schema_type/query.rego
/openAPI/general/path_parameter_not_required/query.rego
/terraform/aws_bom/dynamo/query.rego
/openAPI/2.0/body_parameter_with_wrong_property/query.rego
/openAPI/2.0/body_parameter_without_schema/query.rego
/openAPI/2.0/multi_body_parameters_same_operation/query.rego
/openAPI/2.0/multi_collectionformat_not_valid_in_parameter/query.rego
/openAPI/2.0/object_without_required_property/query.rego
/openAPI/2.0/operation_object_parameters_with_body_and_formatdata/query.rego
/openAPI/2.0/parameter_file_type_not_in_formdata/query.rego
/openAPI/3.0/property_allow_empty_value_ignored/query.rego
/openAPI/3.0/property_allow_reserved_improperly_defined/query.rego
/openAPI/general/parameter_objects_headers_dup_name/query.rego
/openAPI/general/parameters_name_in_not_unique/query.rego
/openAPI/general/path_parameter_with_no_corresponding_template_path/query.rego
/openAPI/general/property_allow_empty_value_improperly_defined/query.rego
/openAPI/general/template_path_parameter_with_no_corresponding_path_parameter/query.rego
opa fmt --diff <path_to_rego_file>
andopa fmt --check-result <path_to_rego_file>
, the output remained the same, leaving me confused about the specific formatting issues in these files. All other files were successfully fixed by these commands/analysis, so it’s unclear why these particular files remain problematic.""
(double quotes) to´´
(backticks). This reduces redundant escaping within the regular expressions and significantly improves readability and maintainability of the patterns.in
operator. This change clarifies the intent of the code and reduces the chance of errors, especially in cases where we are checking if something is not part of a collection. For example, changingx != []
tox not in []
makes the check more explicit and readable.prefer-some-in-iteration
rule, which encourages using thesome
function in iterations for better performance and clarity. While I made substantial progress, there are still many more files that could benefit from this change. Given that reviewing 1000+ file changes is already a significant task, I decided to stop for now. The full implementation of this rule across all 2531 KICS queries (approximately 1700 files plus libraries) would be a massive effort. However, it’s worth noting that this change significantly improves code readability and maintainability, even if it’s not a critical priority for Rego linting.in
operator andobject.keys
method, ensuring better performance and adherence to Rego best practices.Documentation Links:
I submit this contribution under the Apache-2.0 license.