Skip to content

Commit

Permalink
cleanup: Enable most clang-tidy readability checks.
Browse files Browse the repository at this point in the history
Some exceptions that either potentially break Qt code or we don't like
(like variable names needing to be at least 3 characters).
  • Loading branch information
iphydf committed Jan 24, 2025
1 parent 0d274c0 commit 0439127
Show file tree
Hide file tree
Showing 62 changed files with 218 additions and 218 deletions.
1 change: 1 addition & 0 deletions .ci-scripts/build-qtox-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ ccache --show-stats

if [ ! -z "${TIDY+x}" ]; then
if [ ! -z "${TIDY_FIX+x}" ]; then
clang-tidy -list-checks
run-clang-tidy -quiet -fix -format -p "$BUILD_DIR" \
-exclude-header-filter '/usr/.*' \
audio/include/ \
Expand Down
22 changes: 15 additions & 7 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ Checks: "-*
, modernize-use-nullptr
, modernize-use-override
, performance-move-const-arg
, readability-container-*
, readability-else-after-return
, readability-implicit-bool-conversion
, readability-isolate-declaration
, readability-make-member-function-const
, readability-named-parameter
, readability-inconsistent-declaration-parameter-name
, readability-*
, -readability-avoid-return-with-void-value
, -readability-braces-around-statements
, -readability-convert-member-functions-to-static
, -readability-function-cognitive-complexity
, -readability-identifier-length
, -readability-magic-numbers
, -readability-math-missing-parentheses
, -readability-redundant-access-specifiers
, -readability-redundant-member-init
, -readability-simplify-boolean-expr
, -readability-suspicious-call-argument
"
WarningsAsErrors: "*"
HeaderFilterRegex: ".*"
CheckOptions:
- key: readability-uppercase-literal-suffix.NewSuffixes
value: f;d;u;L;Lu;LLu;uL;uLL
2 changes: 1 addition & 1 deletion audio/include/audio/iaudiosink.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class IAudioSink
CallEnd
};

inline static QString getSound(Sound s)
static QString getSound(Sound s)
{
switch (s) {
case Sound::Test:
Expand Down
14 changes: 7 additions & 7 deletions audio/src/backend/openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void OpenAL::reinitInput(const QString& inDevDesc)
locker.unlock();
// this must happen outside `audioLock`, to avoid a deadlock when
// a slot on AlSource::invalidate tries to create a new source immediately.
for (auto& source : bakSources) {
for (const auto& source : bakSources) {
source->kill();
}
}
Expand All @@ -242,7 +242,7 @@ bool OpenAL::reinitOutput(const QString& outDevDesc)
locker.unlock();
// this must happen outside `audioLock`, to avoid a deadlock when
// a slot on AlSink::invalidate tries to create a new source immediately.
for (auto& sink : bakSinks) {
for (const auto& sink : bakSinks) {
sink->kill();
}

Expand All @@ -265,7 +265,7 @@ std::unique_ptr<IAudioSink> OpenAL::makeSink()
ALuint sid;
alGenSources(1, &sid);

const auto sink = new AlSink(*this, sid);
auto* const sink = new AlSink(*this, sid);
if (sink == nullptr) {
return {};
}
Expand Down Expand Up @@ -512,7 +512,7 @@ void OpenAL::cleanupSound()

auto sinkIt = soundSinks.begin();
while (sinkIt != soundSinks.end()) {
auto sink = *sinkIt;
auto* sink = *sinkIt;
const ALuint sourceId = sink->getSourceId();
ALint state = 0;

Expand All @@ -532,7 +532,7 @@ void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, un
assert(channels == 1 || channels == 2);
const QMutexLocker<QRecursiveMutex> locker(&audioLock);

if (!((alOutDev != nullptr) && outputInitialized))
if ((alOutDev == nullptr) || !outputInitialized)
return;

ALuint bufids[BUFFER_COUNT];
Expand Down Expand Up @@ -665,15 +665,15 @@ void OpenAL::doInput()
}

// NOTE(sudden6): this loop probably doesn't scale too well with many sources
for (auto source : sources) {
for (auto* source : sources) {
emit source->volumeAvailable(volume);
}
if (!isActive) {
return;
}

// NOTE(sudden6): this loop probably doesn't scale too well with many sources
for (auto source : sources) {
for (auto* source : sources) {
emit source->frameAvailable(inputBuffer, AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL,
inputChannels, AUDIO_SAMPLE_RATE);
}
Expand Down
2 changes: 1 addition & 1 deletion audio/src/backend/openal.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class OpenAL : public IAudioControl
virtual bool initInput(const QString& deviceName);
virtual bool initOutput(const QString& deviceName);

void cleanupBuffers(uint sourceId);
static void cleanupBuffers(uint sourceId);
void cleanupSound();

qreal getVolume();
Expand Down
24 changes: 12 additions & 12 deletions src/appmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ int AppManager::startGui(QCommandLineParser& parser)

// Windows platform plugins DLL hell fix
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());
qapp->addLibraryPath("platforms");
QApplication::addLibraryPath("platforms");

qDebug() << "Commit:" << VersionInfo::gitVersion();
qDebug() << "Process ID:" << QCoreApplication::applicationPid();
Expand Down Expand Up @@ -381,14 +381,14 @@ int AppManager::run()
});
PosixSignalNotifier::watchUsrSignals();

qapp->setApplicationName("qTox");
qapp->setDesktopFileName("io.github.qtox.qTox");
qapp->setApplicationVersion(QStringLiteral("%1, git commit %2 (%3)")
.arg(VersionInfo::gitDescribe())
.arg(VersionInfo::gitVersion())
.arg(UpdateCheck::isCurrentVersionStable()
? QStringLiteral("stable")
: QStringLiteral("unstable")));
QApplication::setApplicationName("qTox");
QApplication::setDesktopFileName("io.github.qtox.qTox");
QApplication::setApplicationVersion(QStringLiteral("%1, git commit %2 (%3)")
.arg(VersionInfo::gitDescribe())
.arg(VersionInfo::gitVersion())
.arg(UpdateCheck::isCurrentVersionStable()
? QStringLiteral("stable")
: QStringLiteral("unstable")));

// Install Unicode 6.1 supporting font
// Keep this as close to the beginning of `main()` as possible, otherwise
Expand Down Expand Up @@ -437,13 +437,13 @@ int AppManager::run()
updateCheck->checkForUpdate();
connect(updateCheck, &UpdateCheck::updateCheckFailed, qapp.get(), &QApplication::quit);
connect(updateCheck, &UpdateCheck::complete, this,
[this](QString currentVersion, QString latestVersion, const QUrl& link) {
[](QString currentVersion, QString latestVersion, const QUrl& link) {
const QString message =
QStringLiteral("Current version: %1\nLatest version: %2\n%3\n")
.arg(currentVersion, latestVersion, link.toString());
// Output to stdout.
QTextStream(stdout) << message;
qapp->quit();
QApplication::quit();
});
} else {
const int result = startGui(parser);
Expand All @@ -452,7 +452,7 @@ int AppManager::run()
}
}

return qapp->exec();
return QApplication::exec();
}

AppManager::~AppManager() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/appmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private slots:
void cleanup();

private:
void preConstructionInitialization();
static void preConstructionInitialization();
std::unique_ptr<QApplication> qapp;
std::unique_ptr<MessageBoxManager> messageBoxManager;
std::unique_ptr<Settings> settings;
Expand Down
10 changes: 5 additions & 5 deletions src/chatlog/chatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeName
// correlate ChatMessages created here, however a logic bug could turn into
// a crash due to this dangerous cast. The alternative would be to make
// ChatLine a QObject which I didn't think was worth it.
auto chatMessage = static_cast<ChatMessage*>(chatLine.get());
auto* chatMessage = static_cast<ChatMessage*>(chatLine.get());

if (chatMessage != nullptr) {
if (chatLogMessage.state == MessageState::complete) {
Expand Down Expand Up @@ -850,7 +850,7 @@ void ChatWidget::handleSearchResult(SearchResult result, SearchDirection directi
auto msg = (*chatLineStorage)[searchPos.logIdx];
scrollToLine(msg);

auto text = qobject_cast<Text*>(msg->getContent(1));
auto* text = qobject_cast<Text*>(msg->getContent(1));
text->selectText(result.exp, std::make_pair(result.start, result.len));
};

Expand Down Expand Up @@ -1424,9 +1424,9 @@ void ChatWidget::renderFile(QString displayName, ToxFile file, bool isSelf, QDat
timestamp, documentCache, settings,
style, messageBoxManager);
} else {
auto proxy = static_cast<ChatLineContentProxy*>(chatMessage->getContent(1));
auto* proxy = static_cast<ChatLineContentProxy*>(chatMessage->getContent(1));
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);
auto ftWidget = static_cast<FileTransferWidget*>(proxy->getWidget());
auto* ftWidget = static_cast<FileTransferWidget*>(proxy->getWidget());
ftWidget->onFileTransferUpdate(file);
}
}
Expand Down Expand Up @@ -1474,7 +1474,7 @@ void ChatWidget::disableSearchText()
}

auto line = (*chatLineStorage)[searchPos.logIdx];
auto text = qobject_cast<Text*>(line->getContent(1));
auto* text = qobject_cast<Text*>(line->getContent(1));
text->deselectText();
}

Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/chatwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private slots:

private:
void retranslateUi();
bool isActiveFileTransfer(ChatLine::Ptr l);
static bool isActiveFileTransfer(ChatLine::Ptr l);
void handleMultiClickEvent();
void moveSelectionRectUpIfSelected(int offset);
void moveSelectionRectDownIfSelected(int offset);
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/content/filetransferwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private slots:
static bool tryRemoveFile(const QString& filepath);

void updateWidget(const ToxFile& file);
void updateBackgroundColor(const ToxFile::FileStatus status);
void updateBackgroundColor(ToxFile::FileStatus status);

private:
CoreFile& coreFile;
Expand Down
4 changes: 2 additions & 2 deletions src/conferencelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ QList<Conference*> ConferenceList::getAllConferences()
{
QList<Conference*> res;

for (auto it : conferenceList)
for (auto* it : conferenceList)
res.append(it);

return res;
}

void ConferenceList::clear()
{
for (auto conferenceptr : conferenceList)
for (auto* conferenceptr : conferenceList)
delete conferenceptr;
conferenceList.clear();
}
4 changes: 2 additions & 2 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void Core::onConferenceMessage(Tox* tox, uint32_t conferenceId, uint32_t peerId,
void Core::onConferencePeerListChange(Tox* tox, uint32_t conferenceId, void* vCore)
{
std::ignore = tox;
const auto core = static_cast<Core*>(vCore);
auto* const core = static_cast<Core*>(vCore);
qDebug("Conference %u peerlist changed", conferenceId);
// no saveRequest, this callback is called on every connection to conference peer, not just on brand new peers
emit core->conferencePeerlistChanged(conferenceId);
Expand Down Expand Up @@ -1316,7 +1316,7 @@ QString Core::getFriendUsername(uint32_t friendNumber) const
return ToxString(nameBuf.data(), nameSize).getQString();
}

uint64_t Core::getMaxMessageSize() const
uint64_t Core::getMaxMessageSize()
{
/*
* TODO: Remove this hack; the reported max message length we receive from c-toxcore
Expand Down
4 changes: 2 additions & 2 deletions src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Core : public QObject,
~Core() override;

static const QString TOX_EXT;
uint64_t getMaxMessageSize() const;
static uint64_t getMaxMessageSize();
QString getPeerName(const ToxPk& id) const;
QVector<uint32_t> getFriendList() const;
ConferenceId getConferencePersistentId(uint32_t conferenceNumber) const override;
Expand Down Expand Up @@ -161,7 +161,7 @@ public slots:
void friendRemoved(uint32_t friendId);
void friendLastSeenChanged(uint32_t friendId, const QDateTime& dateTime);

void emptyConferenceCreated(uint32_t conferencenumber, const ConferenceId conferenceId,
void emptyConferenceCreated(uint32_t conferencenumber, ConferenceId conferenceId,
const QString& title = QString());
void conferenceInviteReceived(const ConferenceInvite& inviteInfo);
void conferenceMessageReceived(uint32_t conferencenumber, uint32_t peernumber,
Expand Down
2 changes: 1 addition & 1 deletion src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ void CoreAV::videoFrameCallback(ToxAV* toxAV, uint32_t friendNum, uint16_t w, ui
int32_t yStride, int32_t uStride, int32_t vStride, void* vSelf)
{
std::ignore = toxAV;
auto self = static_cast<CoreAV*>(vSelf);
auto* self = static_cast<CoreAV*>(vSelf);
// This callback should come from the CoreAV thread
assert(QThread::currentThread() == self->coreAvThread.get());
const QReadLocker locker{&self->callsLock};
Expand Down
2 changes: 1 addition & 1 deletion src/friendlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void FriendList::removeFriend(const ToxPk& friendPk, Settings& settings, bool fa

void FriendList::clear()
{
for (auto friendPtr : friendList)
for (auto* friendPtr : friendList)
delete friendPtr;
friendList.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const char* getCurUsername()

QString getIpcKey()
{
auto* user = getCurUsername();
const auto* user = getCurUsername();
if (user == nullptr) {
qWarning() << "Failed to get current username. Will use a global IPC.";
user = "";
Expand Down
2 changes: 1 addition & 1 deletion src/model/about/aboutfriend.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AboutFriend : public QObject, public IAboutFriend
Q_OBJECT

public:
AboutFriend(const Friend* f_, IFriendSettings* const settings, Profile& profile);
AboutFriend(const Friend* f_, IFriendSettings* settings, Profile& profile);

QString getName() const override;
QString getStatusMessage() const override;
Expand Down
4 changes: 2 additions & 2 deletions src/model/chathistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void ChatHistory::onFileTransferBrokenUnbroken(const ToxPk& sender, const ToxFil
void ChatHistory::onMessageReceived(const ToxPk& sender, const Message& message)
{
if (canUseHistory()) {
auto& chatId = chat.getPersistentId();
const auto& chatId = chat.getPersistentId();
auto displayName = chat.getDisplayedName(sender);
auto content = message.content;
if (message.isAction) {
Expand All @@ -272,7 +272,7 @@ void ChatHistory::onMessageSent(DispatchedMessageId id, const Message& message)
{
if (canUseHistory()) {
auto selfPk = coreIdHandler.getSelfPublicKey();
auto& chatId = chat.getPersistentId();
const auto& chatId = chat.getPersistentId();

auto content = message.content;
if (message.isAction) {
Expand Down
6 changes: 3 additions & 3 deletions src/model/chatroom/conferenceroom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ void ConferenceRoom::inviteFriend(const ToxPk& pk)
bool ConferenceRoom::possibleToOpenInNewWindow() const
{
const auto conferenceId = conference->getPersistentId();
const auto dialogs = dialogsManager->getConferenceDialogs(conferenceId);
auto* const dialogs = dialogsManager->getConferenceDialogs(conferenceId);
return (dialogs == nullptr) || dialogs->chatroomCount() > 1;
}

bool ConferenceRoom::canBeRemovedFromWindow() const
{
const auto conferenceId = conference->getPersistentId();
const auto dialogs = dialogsManager->getConferenceDialogs(conferenceId);
auto* const dialogs = dialogsManager->getConferenceDialogs(conferenceId);
return (dialogs != nullptr) && dialogs->hasChat(conferenceId);
}

void ConferenceRoom::removeConferenceFromDialogs()
{
const auto conferenceId = conference->getPersistentId();
auto dialogs = dialogsManager->getConferenceDialogs(conferenceId);
auto* dialogs = dialogsManager->getConferenceDialogs(conferenceId);
dialogs->removeConference(conferenceId);
}
Loading

0 comments on commit 0439127

Please sign in to comment.