Skip to content

Commit 156f47e

Browse files
No type traits, actually stream clang-tidy output locally, easy fixes
1 parent 12572fd commit 156f47e

8 files changed

Lines changed: 30 additions & 23 deletions

File tree

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Checks: >
99
-bugprone-easily-swappable-parameters,
1010
-modernize-use-trailing-return-type,
1111
-modernize-avoid-c-arrays,
12+
-modernize-type-traits,
1213
-modernize-use-auto,
1314
-modernize-use-nodiscard,
1415
-modernize-return-braced-init-list,

src/data_stream.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::string generateRandomId(std::size_t bytes = 16) {
3838
out.reserve(bytes * 2);
3939
const char *hex = "0123456789abcdef";
4040
for (std::size_t i = 0; i < bytes; ++i) {
41-
int v = dist(rng);
41+
const int v = dist(rng);
4242
out.push_back(hex[(v >> 4) & 0xF]);
4343
out.push_back(hex[v & 0xF]);
4444
}
@@ -314,7 +314,7 @@ void TextStreamWriter::write(const std::string &text) {
314314

315315
for (const auto &chunk_str : splitUtf8(text, kStreamChunkSize)) {
316316
const auto *p = reinterpret_cast<const std::uint8_t *>(chunk_str.data());
317-
std::vector<std::uint8_t> bytes(p, p + chunk_str.size());
317+
const std::vector<std::uint8_t> bytes(p, p + chunk_str.size());
318318
LK_LOG_DEBUG("sending chunk");
319319
sendChunk(bytes);
320320
}
@@ -348,7 +348,7 @@ void ByteStreamWriter::write(const std::vector<std::uint8_t> &data) {
348348
const std::size_t n =
349349
std::min<std::size_t>(kStreamChunkSize, data.size() - offset);
350350
auto it = data.begin() + static_cast<std::ptrdiff_t>(offset);
351-
std::vector<std::uint8_t> chunk(it, it + static_cast<std::ptrdiff_t>(n));
351+
const std::vector<std::uint8_t> chunk(it, it + static_cast<std::ptrdiff_t>(n));
352352
sendChunk(chunk);
353353
offset += n;
354354
}

src/ffi_client.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ bool FfiClient::isInitialized() const noexcept {
173173
FfiClient::ListenerId
174174
FfiClient::AddListener(const FfiClient::Listener &listener) {
175175
const std::scoped_lock<std::mutex> guard(lock_);
176-
FfiClient::ListenerId id = next_listener_id++;
176+
const FfiClient::ListenerId id = next_listener_id++;
177177
listeners_[id] = listener;
178178
return id;
179179
}
@@ -191,7 +191,7 @@ FfiClient::sendRequest(const proto::FfiRequest &request) const {
191191
}
192192
const uint8_t *resp_ptr = nullptr;
193193
size_t resp_len = 0;
194-
FfiHandleId handle =
194+
const FfiHandleId handle =
195195
livekit_ffi_request(reinterpret_cast<const uint8_t *>(bytes.data()),
196196
bytes.size(), &resp_ptr, &resp_len);
197197
if (handle == INVALID_HANDLE) {
@@ -455,7 +455,7 @@ FfiClient::getTrackStatsAsync(uintptr_t track_handle) {
455455
get_stats_req->set_request_async_id(async_id);
456456

457457
try {
458-
proto::FfiResponse resp = sendRequest(req);
458+
const proto::FfiResponse resp = sendRequest(req);
459459
if (!resp.has_get_stats()) {
460460
logAndThrow("FfiResponse missing get_stats");
461461
}
@@ -502,7 +502,7 @@ FfiClient::publishTrackAsync(std::uint64_t local_participant_handle,
502502
}
503503

504504
const proto::OwnedTrackPublication &pub = cb.publication();
505-
pr.set_value(std::move(pub));
505+
pr.set_value(pub);
506506
});
507507

508508
// Build and send the request
@@ -701,7 +701,7 @@ FfiClient::subscribeDataTrack(std::uint64_t track_handle,
701701
}
702702

703703
try {
704-
proto::FfiResponse resp = sendRequest(req);
704+
const proto::FfiResponse resp = sendRequest(req);
705705
if (!resp.has_subscribe_data_track()) {
706706
return Result<proto::OwnedDataTrackStream,
707707
SubscribeDataTrackError>::failure(SubscribeDataTrackError{

src/local_participant.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void LocalParticipant::publishDtmf(int code, const std::string &digit) {
9999
}
100100

101101
// TODO, should we take destination as inputs?
102-
std::vector<std::string> destination_identities;
102+
const std::vector<std::string> destination_identities;
103103
auto fut = FfiClient::instance().publishSipDtmfAsync(
104104
static_cast<std::uint64_t>(handle_id), static_cast<std::uint32_t>(code),
105105
digit, destination_identities);
@@ -212,7 +212,7 @@ void LocalParticipant::publishTrack(const std::shared_ptr<Track> &track,
212212
static_cast<std::uint64_t>(track_handle), options);
213213

214214
// Will throw if the async op fails (error in callback).
215-
proto::OwnedTrackPublication owned_pub = fut.get();
215+
const proto::OwnedTrackPublication owned_pub = fut.get();
216216

217217
// Construct a LocalTrackPublication from the proto publication.
218218
auto publication = std::make_shared<LocalTrackPublication>(owned_pub);
@@ -436,12 +436,12 @@ void LocalParticipant::handleRpcMethodInvocation(
436436
state->cv.notify_all();
437437
}
438438
}
439-
} guard{state};
439+
} const guard{state};
440440

441441
std::optional<RpcError> response_error;
442442
std::optional<std::string> response_payload;
443-
RpcInvocationData params{request_id, caller_identity, payload,
444-
response_timeout_sec};
443+
const RpcInvocationData params{request_id, caller_identity, payload,
444+
response_timeout_sec};
445445
auto it = rpc_handlers_.find(method);
446446
if (it == rpc_handlers_.end()) {
447447
// No handler registered → built-in UNSUPPORTED_METHOD

src/room.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ void Room::OnEvent(const FfiEvent &event) {
918918
identity);
919919
break;
920920
}
921-
std::string old_metadata = participant->metadata();
921+
const std::string old_metadata = participant->metadata();
922922
participant->set_metadata(pm.metadata());
923923
ev.participant = participant;
924924
ev.old_metadata = old_metadata;
@@ -950,7 +950,7 @@ void Room::OnEvent(const FfiEvent &event) {
950950
identity);
951951
break;
952952
}
953-
std::string old_name = participant->name();
953+
const std::string old_name = participant->name();
954954
participant->set_name(pn.name());
955955
ev.participant = participant;
956956
ev.old_name = old_name;
@@ -1292,7 +1292,7 @@ void Room::OnEvent(const FfiEvent &event) {
12921292
} else if (byte_reader) {
12931293
// Convert string bytes -> vector<uint8_t>
12941294
const std::string &s = chunk.content();
1295-
std::vector<std::uint8_t> bytes(s.begin(), s.end());
1295+
const std::vector<std::uint8_t> bytes(s.begin(), s.end());
12961296
byte_reader->onChunkUpdate(bytes);
12971297
}
12981298
break;

src/subscription_thread_dispatcher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void SubscriptionThreadDispatcher::setOnVideoFrameCallback(
118118
VideoFrameCallback callback, const VideoStream::Options &opts) {
119119
const CallbackKey key{participant_identity, TrackSource::SOURCE_UNKNOWN,
120120
track_name};
121-
const std::lock_guard<std::mutex> lock(lock_);
121+
const std::scoped_lock<std::mutex> lock(lock_);
122122
const bool replacing = video_callbacks_.find(key) != video_callbacks_.end();
123123
video_callbacks_[key] = RegisteredVideoCallback{
124124
std::move(callback),
@@ -651,8 +651,8 @@ std::thread SubscriptionThreadDispatcher::startDataReaderLocked(
651651
const DataFrameCallback &cb) {
652652
auto old_thread = extractDataReaderThreadLocked(id);
653653

654-
int total_active = static_cast<int>(active_readers_.size()) +
655-
static_cast<int>(active_data_readers_.size());
654+
const int total_active = static_cast<int>(active_readers_.size()) +
655+
static_cast<int>(active_data_readers_.size());
656656
if (total_active >= kMaxActiveReaders) {
657657
LK_LOG_ERROR("Cannot start data reader for {} track={}: active reader "
658658
"limit ({}) reached",

src/trace/event_tracer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct TraceEventData {
9292
// Escape a string for JSON
9393
std::string JsonEscape(const std::string &s) {
9494
std::ostringstream oss;
95-
for (char c : s) {
95+
for (const char c : s) {
9696
switch (c) {
9797
case '"':
9898
oss << "\\\"";
@@ -294,15 +294,15 @@ const unsigned char *EventTracer::GetCategoryEnabled(const char *name) {
294294
}
295295

296296
// Check if this specific category is enabled
297-
std::string category_name(name);
297+
const std::string category_name(name);
298298
if (g_enabled_categories.count(category_name) > 0) {
299299
return &g_enabled_byte;
300300
}
301301

302302
// Check for wildcard matches (e.g., "livekit.*" matches "livekit.connect")
303303
for (const auto &pattern : g_enabled_categories) {
304304
if (pattern.back() == '*') {
305-
std::string prefix = pattern.substr(0, pattern.size() - 1);
305+
const std::string prefix = pattern.substr(0, pattern.size() - 1);
306306
if (category_name.compare(0, prefix.size(), prefix) == 0) {
307307
return &g_enabled_byte;
308308
}

tidy.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,13 @@ write_step_summary() {
280280
log="tidy.log"
281281

282282
set +e
283-
run-clang-tidy \
283+
# run-clang-tidy is a Python script that doesn't flush stdout in its per-file
284+
# loop; it only flushes once at exit. When its stdout is a pipe (the `| tee`
285+
# below), Python's stdio defaults to block-buffered mode, so diagnostics
286+
# accumulate in an ~8 KB buffer and the user sees nothing until the run is
287+
# essentially over. PYTHONUNBUFFERED=1 forces line/unbuffered writes so each
288+
# file's findings appear as soon as that file's clang-tidy finishes.
289+
PYTHONUNBUFFERED=1 run-clang-tidy \
284290
-p "${BUILD_DIR}" \
285291
-quiet \
286292
-j "${jobs}" \

0 commit comments

Comments
 (0)