Skip to content

Remove dead code path in print_suggestion() #486

Description

@shenxianpeng

Summary

The print_suggestion() function in commit_check/util.py has a dead else branch that is never reached in practice.

Current Code

def print_suggestion(suggest: str | None) -> None:
    """Print suggestion to user
    :param suggest: what message to print out
    """
    if suggest:
        print(
            f"Suggest: {GREEN}{suggest}{RESET_COLOR} ",
            end="",
        )
    else:
        print(f"commit-check does not support {suggest} yet.")
        raise SystemExit(1)
    print("\n")

The Problem

  1. The function is only ever called when suggest is truthy — see callers in _print_failure() (line 36) and print_errors() (line 293), both of which guard the call with `if check.get("suggest"):
  2. If the else branch were somehow triggered, it would print "commit-check does not support None yet." — ugly and misleading.
  3. The dead code is confusing to readers and will show up in code coverage reports as uncovered.

Suggested Fix

Remove the unreachable else branch and simplify the function to handle only the happy path. Since the callers already guard against None/empty, the function signature can also be changed from str | None to str.

Files to Change

  • commit_check/util.py — the print_suggestion() function
  • Optionally, update the docstring and type hint accordingly.

References

  • Reported during codebase review of #485
  • See also util.py lines 307-316

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions