feat(tidy): add fairmq-readability-transfer-code

- Replace -1, -2 and -3 in == and != comparisons with the result of
  Send() or Receive() by static_cast<int64_t>(fair::mq::TransferCode::X).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-09 23:14:01 +00:00
parent e9afe76155
commit b113f0a7d8
6 changed files with 141 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ The `fairmq-*` checks are a clang-tidy module ([Module.cxx](/source/fairmq/tidy/
| `fairmq-modernize-parts-api` | Calls of `Parts::AtRef()` and of `Parts::AddPart(Message*)` | `At()` with `->` or `*`, and `MessagePtr(p)` |
| `fairmq-modernize-progoptions-accessors` | Calls of the deprecated accessors `ProgOptions::GetValue()`, `GetStringValue()` and `SetValue()` | `GetProperty()`, `GetPropertyAsString()` and `SetProperty()` |
| `fairmq-modernize-run-device` | A `getDevice()` for `<runFairMQDevice.h>` that returns a raw pointer | `<fairmq/runDevice.h>`, `std::unique_ptr` and `std::make_unique` |
| `fairmq-readability-transfer-code` | Comparisons of the result of `Send()` or `Receive()` with `-1`, `-2` or `-3` | `static_cast<int64_t>(fair::mq::TransferCode::...)` |
The checks report a name in a macro, but they do not fix it. Like all clang-tidy checks, they show findings in headers only if the header matches `--header-filter=<regex>`.
@@ -167,6 +168,16 @@ The check follows the control flow of the function, like the upstream check `bug
The check looks only at a `Send()` whose result the code does not use. If the code checks the result, the send can have failed, and a use of the message can be correct.
### fairmq-readability-transfer-code
| Code | Fix |
| --- | --- |
| `Receive(msg, "data") == -2` | `Receive(msg, "data") == static_cast<int64_t>(fair::mq::TransferCode::timeout)` |
| `Send(msg, "data") != -1` | `Send(msg, "data") != static_cast<int64_t>(fair::mq::TransferCode::error)` |
| `-3 == ch.Send(msg)` | `static_cast<int64_t>(fair::mq::TransferCode::interrupted) == ch.Send(msg)` |
The check looks only at `==` and `!=`. See [Transfer codes](/reference/transfer-codes/).
## Build fairmq-tidy
Set the CMake option `BUILD_TIDY_TOOL` (default `OFF`) when you configure FairMQ: