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

feat(general): Allow skipping multiple checks in a single line #6512

Closed
2 changes: 1 addition & 1 deletion checkov/common/comment/enum.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import re

COMMENT_REGEX = re.compile(r'(checkov:skip=|bridgecrew:skip=) *([A-Za-z_\d]+)(:[^\n]+)?')
COMMENT_REGEX = re.compile(r'(checkov:skip=|bridgecrew:skip=) ([A-Za-z_\d]+(?:,[A-Za-z_\d]+))*(:[^\n]+)?')
15 changes: 9 additions & 6 deletions checkov/terraform/context_parsers/base_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ def _collect_skip_comments(self, definition_blocks: List[Dict[str, Any]]) -> Dic
if "start_line" in entity_context and "end_line" in entity_context \
and entity_context["start_line"] < skip_check_line_num < entity_context["end_line"]:
# No matter which ID was used to skip, save the pair of IDs in the appropriate fields
if bc_id_mapping and skip_check["id"] in bc_id_mapping:
skip_check["bc_id"] = skip_check["id"]
skip_check["id"] = bc_id_mapping[skip_check["id"]]
elif metadata_integration.check_metadata:
skip_check["bc_id"] = metadata_integration.get_bc_id(skip_check["id"])
skipped_checks.append(skip_check)
skip_check_ids = skip_check["id"].split(',')
for skip_check_id in skip_check_ids:
single_skip_check = {"id": skip_check_id.strip(), "suppress_comment": skip_check["suppress_comment"]}
if bc_id_mapping and single_skip_check["id"] in bc_id_mapping:
single_skip_check["bc_id"] = single_skip_check["id"]
single_skip_check["id"] = bc_id_mapping[single_skip_check["id"]]
elif metadata_integration.check_metadata:
single_skip_check["bc_id"] = metadata_integration.get_bc_id(skip_check["id"])
skipped_checks.append(single_skip_check)
dpath.new(self.context, entity_context_path + ["skipped_checks"], skipped_checks)
return self.context

Expand Down
Loading