Skip to content

check-readme-links.py: dead if not normalized branch in check_relative_file_links #60

Description

@GuaRuan

Bug

In scripts/check-readme-links.py, check_relative_file_links has an unreachable guard:

# scripts/check-readme-links.py:223-227
for target in iter_links(path):
    normalized, anchor = split_link_target(target)
    if not normalized.startswith(("./", "../")):
        continue
    if not normalized:
        continue

The second if not normalized: continue can never fire. The line immediately above already continues for every value of normalized that does not start with "./" or "../". Any string that survives to line 227 therefore begins with "./" or "../", which makes it non-empty by construction, so not normalized is always False.

Reproduction

Purely by reading: there is no input for which line 227's continue is taken. The branch is dead code.

It looks like the intent may have been to skip empty targets before the prefix check (a link like [x]() produces an empty target). As written, an empty target hits line 225 ("".startswith(("./", "../")) is False) and is skipped there, so the emptiness check is both misordered and redundant.

Suggested Fix

Either drop the redundant guard entirely, or — if the goal was to defend against empty/odd targets generally — move it above the prefix check so it actually does something:

normalized, anchor = split_link_target(target)
if not normalized:
    continue
if not normalized.startswith(("./", "../")):
    continue

Low impact (CI helper, no behavior change today), but it's a small readability snag that suggests the validation order isn't quite what was intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions