← Lesson library

Reject usage and error diagnostics in linter output

Before accepting exit code 1 as expected lint findings, scan all combined stdout and stderr for usage or bare Error: diagnostics. Accept the undocumented-exit exception only when no such operational diagnostic appears anywhere in the output.

Compare the published fixtures

fixtures/bad/lint.py

def has_findings(exit_code, output):
    return exit_code == 1

fixtures/good/lint.py

import re

DIAGNOSTIC = re.compile(r"^(usage:|Error:)", re.M)


def has_findings(exit_code, output):
    return exit_code == 1 and not DIAGNOSTIC.search(output)