#!/usr/bin/env python3
import re
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from harness import LintWarning, file_check

INCLUDE_RE = re.compile(r'#\s*include\s*[<"]stdbool\.h[>"]')


def check(path, text):
    if "stdbool.h" not in text:
        return
    for match in INCLUDE_RE.finditer(text):
        yield LintWarning(
            path,
            "stdbool.h is redundant: bool, true and false are built in "
            "under C23",
            line=text.count("\n", 0, match.start()) + 1,
        )


file_check(check)
