Flag direct Qt `.toDouble()` / `->toDouble()` calls outside SerialStudio.h. SerialStudio::toDouble() is the project-wide numeric parse: fast_float-backed, string-payload aware, and total (never fails).
(
raw_lines: list[str], path: Path, fence_mask: list[bool]
)
| 1646 | |
| 1647 | |
| 1648 | def find_todouble_violations( |
| 1649 | raw_lines: list[str], path: Path, fence_mask: list[bool] |
| 1650 | ) -> list[Violation]: |
| 1651 | """Flag direct Qt `.toDouble()` / `->toDouble()` calls outside |
| 1652 | SerialStudio.h. SerialStudio::toDouble() is the project-wide numeric |
| 1653 | parse: fast_float-backed, string-payload aware, and total (never fails).""" |
| 1654 | if path.name == _TODOUBLE_ALLOWED or path.suffix not in _TODOUBLE_SUFFIXES: |
| 1655 | return [] |
| 1656 | |
| 1657 | violations: list[Violation] = [] |
| 1658 | for i, line in enumerate(raw_lines): |
| 1659 | if i < len(fence_mask) and fence_mask[i]: |
| 1660 | continue |
| 1661 | if _TODOUBLE_RE.search(line): |
| 1662 | violations.append( |
| 1663 | Violation( |
| 1664 | path, |
| 1665 | i + 1, |
| 1666 | "qt-todouble-direct", |
| 1667 | "direct Qt .toDouble() call -- use the SerialStudio::toDouble() " |
| 1668 | "overload set (QStringView / QByteArrayView / QVariant / " |
| 1669 | "QJsonValue; fast_float-backed, parses string payloads, never " |
| 1670 | "fails). Deliberate locale-aware parsing belongs behind a " |
| 1671 | "`// code-verify off` fence.", |
| 1672 | ) |
| 1673 | ) |
| 1674 | return violations |
| 1675 | |
| 1676 | |
| 1677 | def process_file(path: Path, fix: bool) -> tuple[list[Violation], str | None]: |
no test coverage detected