diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3d264352b5..a5bf61aa9f3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html ### Fixed - Empty yaml files do not crash +- Autofix printout is grouped with its own finding rather than the one below it (#3046) - Do not assign constant values to assigned variables (#2805) + ### Changed - .git/ directories are ignored when scanning - External Python API (`semgrep_main.invoke_semgrep`) now takes an diff --git a/semgrep/semgrep/output.py b/semgrep/semgrep/output.py index fd4a93cc0fc1..427aad95523d 100644 --- a/semgrep/semgrep/output.py +++ b/semgrep/semgrep/output.py @@ -256,6 +256,13 @@ def build_normal_output( if rule_index != len(sorted_rule_matches) - 1 else None ) + + if fix: + yield f"{BLUE_COLOR}autofix:{RESET_COLOR} {fix}" + elif rule_match.fix_regex: + fix_regex = rule_match.fix_regex + yield f"{BLUE_COLOR}autofix:{RESET_COLOR} s/{fix_regex.get('regex')}/{fix_regex.get('replacement')}/{fix_regex.get('count', 'g')}" + is_same_file = ( next_rule_match.path == rule_match.path if next_rule_match else False ) @@ -266,12 +273,6 @@ def build_normal_output( per_line_max_chars_limit, is_same_file, ) - - if fix: - yield f"{BLUE_COLOR}autofix:{RESET_COLOR} {fix}" - elif rule_match.fix_regex: - fix_regex = rule_match.fix_regex - yield f"{BLUE_COLOR}autofix:{RESET_COLOR} s/{fix_regex.get('regex')}/{fix_regex.get('replacement')}/{fix_regex.get('count', 'g')}" if show_times: yield from build_timing_summary( filtered_rules, all_targets, profiling_data, color_output